如何在docker容器中启动filebeat?

时间:2017-03-02 15:16:39

标签: docker filebeat

我尝试在dockercontainer中启动filebeat。

在开始时我尝试从这个Dockerfile开始

FROM tomcat:8.5
RUN rm -Rf /usr/local/tomcat/webapps/ROOT/*
RUN mkdir /usr/local/tomcat/webapps-my

COPY filebeat/ /opt/filebeat/
RUN chmod +x /opt/filebeat/filebeat

COPY db-creator.jar /opt/db-creator/

COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
ENTRYPOINT ["/opt/filebeat/filebeat", "-e", "-c", "/opt/filebeat/filebeat.yml"]
COPY server.xml /usr/local/tomcat/conf
COPY my.war /usr/local/tomcat/webapps-my/ROOT.war

CMD ["catalina.sh", "run"]

在这种情况下,filebeat正在启动,但它在控制台中工作,并且tomcat无法启动。 现在我尝试将filebeat作为服务启动

FROM tomcat:8.5
RUN curl -L -O https://artifacts.elastic.co/downloads/beats/fileb...
RUN dpkg -i filebeat-5.2.2-amd64.deb
COPY filebeat.yml /etc/filebeat
RUN update-rc.d filebeat defaults 95 10

COPY db-creator.jar /opt/db-creator/
COPY ./docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]

RUN rm -Rf /usr/local/tomcat/webapps/ROOT/*
COPY server.xml /usr/local/tomcat/conf
RUN mkdir /usr/local/tomcat/webapps-my
COPY my.war /usr/local/tomcat/webapps-iqp/ROOT.war

CMD ["catalina.sh", "run"]

但它根本没有开始。 在这些varint之后,我有一些其他的变形,但它们也不起作用。 比如像这样的东西

CMD [“/ etc / init.d / filebeat”,“start”]

如何启动filebeat?

1 个答案:

答案 0 :(得分:10)

你的方法有点不对劲。 想想微服务架构。每个容器需要一个微服务。

尝试以下方法:

这里需要2个独立的容器。一个用于tomcat,另一个用于filebeat。然后,您将在tomcat容器中的适当位置安装卷,以便在那里获取日志文件。

然后,您将同时在filebeat上同时挂载相同的日志卷,并开始使用filebeat发送日志。

通过这种方式,您将荣获微服务架构和码头工作者理念。

更新:如果您将tomcat配置为登录到stdout和stderr,您将能够使用available的各种日志驱动程序,并且更新时的列表如下

Driver  Description
none    No logs are available for the container and docker logs does not return any output.
json-file   The logs are formatted as JSON. The default logging driver for Docker.
local   Writes logs messages to local filesystem in binary files using Protobuf.
syslog  Writes logging messages to the syslog facility. The syslog daemon must be running on the host machine.
journald    Writes log messages to journald. The journald daemon must be running on the host machine.
gelf    Writes log messages to a Graylog Extended Log Format (GELF) endpoint such as Graylog or Logstash.
fluentd     Writes log messages to fluentd (forward input). The fluentd daemon must be running on the host machine.
awslogs     Writes log messages to Amazon CloudWatch Logs.
splunk  Writes log messages to splunk using the HTTP Event Collector.
etwlogs     Writes log messages as Event Tracing for Windows (ETW) events. Only available on Windows platforms.
gcplogs     Writes log messages to Google Cloud Platform (GCP) Logging.
logentries  Writes log messages to Rapid7 Logentries.