【问题标题】:rsyslog inside docker containers => "rsyslogd is not running ... failed"docker 容器中的 rsyslog =>“rsyslogd 未运行...失败”
【发布时间】:2016-06-13 10:43:00
【问题描述】:

我在 docker 容器中运行 rsyslog 以将 UDP 消息发送到 logstash。

当我登录 docker 容器时,输入:

service rsyslog status

显示:

rsyslogd is not running ... failed! 

但是,当我在容器中时,如果我输入:

service rsyslog start 

它完美启动,没有错误,也没有真正的迹象表明它一开始就失败了

我不知道为什么会失败!!!!

*rsyslog 配置文件没有被修改,除了模块允许 imfile。 rsyslog.conf如下:

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#                       For more information see
#                       /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#################
#### MODULES ####
#################
module(load="imfile" PollingInterval="10")
module(load="imuxsock" )  # provides support for local system logging
module(load="immark")  #provides --MARK-- message capability

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0644
$DirCreateMode 0755
$Umask 0022

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf


###############
#### RULES ####
###############

#
# First some standard log files.  Log by facility.
#
auth,authpriv.*                 /var/log/auth.log
*.*;auth,authpriv.none          -/var/log/syslog
#cron.*                         /var/log/cron.log
daemon.*                        -/var/log/daemon.log
kern.*                          -/var/log/kern.log
lpr.*                           -/var/log/lpr.log
mail.*                          -/var/log/mail.log
user.*                          -/var/log/user.log

#
# Logging for the mail system.  Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info                       -/var/log/mail.info
mail.warn                       -/var/log/mail.warn
mail.err                        /var/log/mail.err

#
# Logging for INN news system.
#
news.crit                       /var/log/news/news.crit
news.err                        /var/log/news/news.err
news.notice                     -/var/log/news/news.notice

#
# Some "catch-all" log files.
#
*.=debug;\
        auth,authpriv.none;\
        news.none;mail.none     -/var/log/debug
*.=info;*.=notice;*.=warn;\
        auth,authpriv.none;\
        cron,daemon.none;\
        mail,news.none          -/var/log/messages

#
# Emergencies are sent to everybody logged in.
#
*.emerg                         :omusrmsg:*

#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
#       news.=crit;news.=err;news.=notice;\
#       *.=debug;*.=info;\
#       *.=notice;*.=warn       /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,
# you must invoke `xconsole' with the `-file' option:
#
#    $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
#      busy site..
#
daemon.*;mail.*;\
        news.err;\
        *.=debug;*.=info;\
        *.=notice;*.=warn       |/dev/xconsole

*我有一个启动 rsyslog 的脚本文件

if [[ -z "$(pgrep rsyslog)" ]]; then
  echo "starting rsyslog"
  service rsyslog start
fi

我的conf文件如下:

##Get Nginx Error Logs
$InputFileName /var/log/nginx/error.log
$InputFileTag http-error
$InputFileStateFile stat-nginx-error
$InputFileSeverity error
$InputFileFacility local7
$InputRunFileMonitor

#GRAB PHP-FPM ACCESS LOGS
$InputFileName /var/log/php-fpm/access_log
$InputFileTag php-fpm-access
$InputFileStateFile stat-php-fpm-access
$InputFileSeverity info
$InputFileFacility local7
$InputRunFileMonitor

#GRAB PHP-FPM ERROR LOGS
$InputFileName /var/log/php-fpm/error_log
$InputFileTag php-fpm-error
$InputFileStateFile stat-php-fpm-error
$InputFileSeverity error
$InputFileFacility local7
$InputRunFileMonitor

#Json Template

template(name="json_temp" type="list")
  { constant(value="{")
    constant(value="\"@timestamp\":\"")         property(name="timegenerated" dateFormat="rfc3339")
    constant(value="\",\"message\":\"")         property(name="msg")
    constant(value="\",\"severity_label\":\"")  property(name="syslogseverity-text")
    constant(value="\",\"severity\":\"")        property(name="syslogseverity")
    constant(value="\",\"facility_label\":\"")  property(name="syslogfacility-text")
    constant(value="\",\"facility\":\"")        property(name="syslogfacility")
    constant(value="\",\"program\":\"")         property(name="programname")
    constant(value="\",\"pid\":\"")             property(name="procid")
    constant(value="\",\"rawmsg\":\"")          property(name="rawmsg")
    constant(value="\",\"syslogtag\":\"")       property(name="syslogtag")
    constant(value="\"}\n")
  }

if $programname == 'http-error' then @ip.address:port;json_temp
if $programname == 'http-error' then stop
if $programname == 'php-fpm-access' then @ip.address:port;json_temp
if $programname == 'php-fpm-access' then stop
if $programname == 'php-fpm-error' then @ip.address:port;json_temp
if $programname == 'php-fpm-error' then stop


*.* @ip.address:port;json_temp

任何帮助都会很棒,因为我不明白为什么它没有启动。

干杯

【问题讨论】:

  • 我刚遇到同样的问题。你找到解决办法了吗?
  • 我做到了,但这有点小题大做。因为我只对 php 和 nginx 日志感兴趣,所以我将我的 conf 文件放入 rsyslog.conf 并删除了我不直接使用的代码。类似于我发现的here。如果这不起作用,则可能是您的 ngninx 和 php 日志文件的组权限问题。

标签: docker rsyslog


【解决方案1】:

我们在 CentOS 7.3.1611 上创建的 Docker 17.03.2-ce 映像上遇到了同样的问题。解决方案是根据this 文档验证/etc/rsyslog.conf。基本上,在/etc/rsyslog.conf:

  • 删除 $ModLoad imjournal
  • 将 $OmitLocalLogging 设置为关闭
  • 确保 $ModLoad imuxsock 存在
  • 注释掉:$IMJournalStateFile imjournal.state

最后,请注意,运行rsyslogd 或其他任何内容是容器内正在运行的程序的责任。它不会自动启动。

【讨论】:

    【解决方案2】:

    这是我在 docker 容器(centos7)中的 rsyslog.conf:

    $> cat /etc/rsyslog.conf |grep -vE '^$|^#'
    $ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
    $WorkDirectory /var/lib/rsyslog
    $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
    $IncludeConfig /etc/rsyslog.d/*.conf
    $OmitLocalLogging off
    *.info;mail.none;authpriv.none;cron.none                /var/log/messages
    authpriv.*                                              /var/log/secure
    mail.*                                                  -/var/log/maillog
    cron.*                                                  /var/log/cron
    *.emerg                                                 :omusrmsg:*
    uucp,news.crit                                          /var/log/spooler
    local7.*                                                /var/log/boot.log
    

    我也更改了 /etc/rsyslog.d/listen.conf

    #$SystemLogSocketName /run/systemd/journal/syslog
    

    然后

    $> rsyslogd -n 
    

    感谢@elinax

    更多信息https://www.projectatomic.io/blog/2014/09/running-syslog-within-a-docker-container/

    【讨论】:

      猜你喜欢
      • 2019-01-02
      • 1970-01-01
      • 2015-06-18
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多