syslog-ng 不会启动,因为错误绑定套接字且权限被拒绝

syslog-ng 不会启动,因为错误绑定套接字且权限被拒绝

我最近在很长一段时间后重新启动了我的一台机器,现在我在配置更改方面遇到了很多问题。

syslog-ng 服务不再工作,journactl 出现以下错误:

-- Unit syslog-ng.service has begun starting up.
Oct 01 17:13:48 SIEM-ConnLinuxLR systemd[1]: syslog-ng.service: Got notification message from PID 18672, but reception only permitted for main PID 18670
Oct 01 17:13:48 SIEM-ConnLinuxLR syslog-ng[18670]: [2018-10-01T17:13:48.128987] WARNING: window sizing for tcp sources were changed in syslog-ng 3.3, the configuration value was divided by the value of max-con
Oct 01 17:13:48 SIEM-ConnLinuxLR syslog-ng[18670]: [2018-10-01T17:13:48.129414] Error binding socket; addr='AF_INET(0.0.0.0:515)', error='Permission denied (13)'
Oct 01 17:13:48 SIEM-ConnLinuxLR syslog-ng[18670]: [2018-10-01T17:13:48.129438] Error initializing message pipeline;
Oct 01 17:13:48 SIEM-ConnLinuxLR systemd[1]: syslog-ng.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Oct 01 17:13:48 SIEM-ConnLinuxLR systemd[1]: Failed to start System Logger Daemon.
-- Subject: Unit syslog-ng.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit syslog-ng.service has failed.
--
-- The result is failed.

这是服务配置:

Description=System Logger Daemon
Documentation=man:syslog-ng(8)
After=network.target

[Service]
Type=notify
User=root
Group=root
ExecStart=/usr/sbin/syslog-ng -p /var/run/syslogd.pid
ExecReload=/bin/kill -HUP $MAINPID
EnvironmentFile=-/etc/syslog-ng
EnvironmentFile=-/etc/default/syslog-ng
EnvironmentFile=-/etc/sysconfig/syslog-ng
StandardOutput=journal
StandardError=journal
Restart=on-failure

[Install]
WantedBy=multi-user.target

因此,正如您所看到的,它应该以 root 身份运行,但它仍然返回一个error='Permission denied (13)'.有趣的是,如果我尝试从控制台运行该命令/usr/sbin/syslog-ng -p /var/run/syslogd.pid,那么它可以完美运行,不会出现任何错误。

编辑1:

端口 515 中没有运行其他进程,正如我所说,当我尝试手动运行命令时,它运行良好。

我正在添加系统日志配置:

@version:3.7
@include "scl.conf"

# syslog-ng configuration file.
#
# This should behave pretty much like the original syslog on RedHat. But
# it could be configured a lot smarter.
#
# See syslog-ng(8) and syslog-ng.conf(5) for more information.
#
# Note: it also sources additional configuration files (*.conf)
#       located in /etc/syslog-ng/conf.d/

options {
    flush_lines (0);
    time_reopen (10);
    log_fifo_size (1000);
    chain_hostnames (off);
    use_dns (no);
    use_fqdn (no);
    create_dirs (no);
    keep_hostname (yes);
};

source s_sys {
    system();
    internal();
    # udp(ip(0.0.0.0) port(514));
};

destination d_cons { file("/dev/console"); };
destination d_mesg { file("/var/log/messages"); };
destination d_auth { file("/var/log/secure"); };
destination d_mail { file("/var/log/maillog" flush_lines(10)); };
destination d_spol { file("/var/log/spooler"); };
destination d_boot { file("/var/log/boot.log"); };
destination d_cron { file("/var/log/cron"); };
destination d_kern { file("/var/log/kern"); };
destination d_mlal { usertty("*"); };

filter f_kernel     { facility(kern); };
filter f_default    { level(info..emerg) and
                        not (facility(mail)
                        or facility(authpriv)
                        or facility(cron)); };
filter f_auth       { facility(authpriv); };
filter f_mail       { facility(mail); };
filter f_emergency  { level(emerg); };
filter f_news       { facility(uucp) or
                        (facility(news)
                        and level(crit..emerg)); };
filter f_boot   { facility(local7); };
filter f_cron   { facility(cron); };

#log { source(s_sys); filter(f_kernel); destination(d_cons); };
log { source(s_sys); filter(f_kernel); destination(d_kern); };
log { source(s_sys); filter(f_default); destination(d_mesg); };
log { source(s_sys); filter(f_auth); destination(d_auth); };
log { source(s_sys); filter(f_mail); destination(d_mail); };
log { source(s_sys); filter(f_emergency); destination(d_mlal); };
log { source(s_sys); filter(f_news); destination(d_spol); };
log { source(s_sys); filter(f_boot); destination(d_boot); };
log { source(s_sys); filter(f_cron); destination(d_cron); };


# Source additional configuration files (.conf extension only)
@include "/etc/syslog-ng/conf.d/*.conf"

来自 apache.conf 的配置

source s_net_t515 {
     network(
         transport("tcp")
         port(515)
         log-msg-size(2097152)
         max-connections(100)
     );
};

destination d_apachea { file("/opt/arcsight/logs/Apache/${HOST}.log"); };

destination d_apachee {
        file("/opt/arcsight/logs/Apache/error/${HOST}-error.log");
};

destination d_a {
        file("/opt/arcsight/logs/Apache/test.log");
};

filter f_apachea { (netmask(***.***.***.5/32) or netmask(***.***.***.6/32)) and not message('error]') and  message('.*\d+\s\d+\s\".*') ; };
filter f_apachee { (netmask(***.***.***.5/32) or netmask(***.***.***.6/32)) and message('error]'); };

log {
        source(s_net_t515);
        filter(f_apachea);
        destination(d_apachea);
};

log {
        source(s_net_t515);
        filter(f_apachee);
        destination(d_apachee);
};

答案1

我猜测问题出在端口号 515,被 SELinux 阻止了。默认系统日志端口为 514。

# semanage port -l 
...
syslogd_port_t                 tcp      601, 20514
syslogd_port_t                 udp      514, 601, 20514
...
printer_port_t                 tcp      515

如果要在不同端口上运行 syslog-ng,则必须更改端口标签。 (semanage port --help会帮助你)

答案2

解决了!

正如 @Alexander 指出的,问题是 SELinux 阻止了端口,但我收到了 515 中的日志,所以我无法更改它。

解决方案是将 SELinux从enforcing设为。此外,我更改了配置文件以在重新启动后通过更改行来应用此配置permissivesetenforce 0SELINUX=permissive

相关内容