Tag: haproxy

haproxy 打印 log 的问题

haproxy 可以把 log 打印到 syslog 去,但是,如果单纯地在 haproxy 的配置上写了这句:

log 127.0.0.1   local0

是不够的,即使你在 syslog 的配置里也写上了这句:

local0.*    /var/log/haproxy/local0.log

也还是不够的,haproxy 也不会把log 打印到相应的文件里。

需要修改 /etc/default/syslogd ,把

SYSLOGD=”"   修改为   SYSLOGD=”-r”

然后重启一下 syslogd

/etc/init.d/sysklogd restart

我的系统是 debian ,centos 没去测试,syslog 的配置上印象中有点不同的。

原因可以参考这两段东西:

man 8 syslogd :

-r     This  option will enable the facility to receive message from the network using an internet domain socket with the syslog service (see ser-
vices(5)).  The default is to not receive any messages from the network.

———————————–

less configuration.txt:

log <address> <facility> [max level [min level]]

<address> can be one of:

- An IPv4 address optionally followed by a colon and a UDP port. If
no port is specified, 514 is used by default (the standard syslog
port).

- A filesystem path to a UNIX domain socket, keeping in mind
considerations for chroot (be sure the path is accessible inside
the chroot) and uid/gid (be sure the path is appropriately
writeable).

———————————————

haproxy 可以把log 打印去两个地方,一个是 监听着 514 udp 端口的 syslog ,一个是 unix socket 。而 syslog 的 -r 参数,就是让 syslog 监听514 port 的。

又或者让 haproxy 连接去 syslog 的 unix socket 也行,

syslogd -a /etc/haproxy/syslog.sock  让 syslogd 监听在unix socket ,这时,haproxy 可以这样配置

log /etc/haproxy/syslog.sock   local0

此 socket 必须在 haproxy 的 chroot 环境中。

==========================
update:

centos 下,修改 /etc/sysconfig/syslog ,把

SYSLOGD_OPTIONS=”-m 0″

改为

SYSLOGD_OPTIONS=”-m 0 -r”