简体   繁体   English

Docker容器应用程序记录到ELK堆栈而没有文件拍子

[英]Docker container Application logs to ELK stack without filebeat

I'm using the Elasti Cloud as it appears to be the most suitable for quickly setting up application logging. 我正在使用Elasti Cloud,因为它似乎最适合快速设置应用程序日志。 I have 24 docker container running in different nodes, and some containers have no of replicas also. 我有24个在不同节点上运行的docker容器,有些容器也没有副本。 i want to export inside docker container logs to elk stack.. I don't want to install Filebeat on each of my containers because that seems like it goes directly against Docker's separation of duties mantra. 我想将Docker容器中的日志导出到麋鹿堆栈中。我不想在每个容器上安装Filebeat,因为这似乎直接违背了Docker的职责分离原则。

.... how do I get logs from my application containers to log stash server ....如何从应用程序容器中获取日志到日志存储服务器

You can send your syslog to Logstash by configuring rsyslogd like this 您可以通过这样配置rsyslogd将syslog发送到Logstash

# /etc/rsyslog.d/99-ship-syslog.conf
*.*;syslog;auth,authpriv.none action(
  type="omfwd"
  Target="myremote.elk-server.net"
  Port="5001"
  Protocol="udp"
)

If you don't have rsyslog running yet, you can add it like so (alpine linux example): 如果尚未运行rsyslog ,则可以这样添加它(高山linux示例):

# Dockerfile
FROM alpine:3.7

RUN  apk update \
  && apk add rsyslog

COPY rsyslog.conf /etc/rsyslog.conf

EXPOSE 514 514/udp

VOLUME [ "/var/log", "/etc/rsyslog.d" ]
ENTRYPOINT [ "rsyslogd", "-n" ]

-- -

# rsyslogd.conf
#
# if you experience problems, check:
# http://www.rsyslog.com/troubleshoot

#### MODULES ####

module(load="imuxsock")    # local system logging support (e.g. via logger command)
#module(load="imklog")     # kernel logging support (previously done by rklogd)
module(load="immark")      # --MARK-- message support
module(load="imudp")       # UDP listener support


input(type="imudp" port="514")

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 action(type="omfile" file="/dev/console")

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                action(type="omfile" file="/var/log/messages")

# The authpriv file has restricted access.
authpriv.*                                              action(type="omfile" file="/var/log/secure")

# Log all the mail messages in one place.
mail.*                                                  action(type="omfile" file="/var/log/maillog")

# Log cron stuff
cron.*                                                  action(type="omfile" file="/var/log/cron")

# Everybody gets emergency messages
*.emerg                                                 action(type="omusrmsg" users="*")

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          action(type="omfile" file="/var/log/spooler")

# Save boot messages also to boot.log
local7.*                                                action(type="omfile" file="/var/log/boot.log")

# log every host in its own directory
if $fromhost-ip then /var/log/$fromhost-ip/messages

# Include all .conf files in /etc/rsyslog.d
$IncludeConfig /etc/rsyslog.d/*.conf
$template GRAYLOGRFC5424,"<%PRI%>%PROTOCOL-VERSION% %TIMESTAMP:::date-rfc3339% %HOSTNAME% %APP-NAME% %PROCID% %MSGID% %STRUCTURED-DATA% %msg%\n"
*.info;mail.none;authpriv.none;cron.none;*.* @@graylog:514;GRAYLOGRFC5424 # forward everything to remote server

As you're running within a java-application, you can even send you logs directly to syslog. 当您在Java应用程序中运行时,甚至可以将日志直接发送到syslog。 Here's a small configuration example with log4j 这是一个使用log4j的小配置示例

log4j.rootLogger=INFO, SYSLOG

log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost=myremote.elk-server.net
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.conversionPattern=%d{ISO8601} %-5p [%t] %c{2} %x - %m%n
log4j.appender.SYSLOG.Facility=LOCAL1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM