如何在Docker容器中启动Filebeat?

3

我尝试在docker容器内启动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"]

但它仍然根本就没有启动。 在这些变量之间,我有一些其他的变量,但它们也不起作用。 例如:

CMD ["/etc/init.d/filebeat", "start"]

我该如何启动filebeat?

1个回答

20

你的方法有点错误。考虑微服务架构。每个容器需要一个微服务。

尝试以下方法:

在这里,你需要2个单独的容器。一个是tomcat,另一个是filebeat。然后,在适当的位置挂载tomcat容器上的卷,以便在那里获取日志文件。

然后,同时将相同的日志卷以只读方式挂载到filebeat上,并使用filebeat开始发送日志。

这样,你就能够遵守微服务架构和Docker哲学。

更新:如果配置tomcat将日志记录到stdout和stderr,则可以使用可用的各种日志驱动程序,更新时列表如下。

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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接