HAProxy启用日志功能
前言
对应于 /etc/rsyslog.conf中的配置,不设置则默认回收info的日志级别
在配置前,我们先来了解一下日志的level:local0~local7 16~23保留为本地使用
emerg 0 系统不可用
alert 1 必须马上采取行动的事件
crit 2 关键的事件
err 3 错误事件
warning 4 警告事件
notice 5 普通但重要的事件
info 6 有用的信息
debug 7 调试信息
HAProxy默认情况下并没有启用日志功能(或者说已经启用了但需配合日志软件方能有效?),查看其配置文件可以窥知一二
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
由配置文件可以知道,haproxy的日志默认定义的设备级别为local2.Linux普遍采用的日志系统是rsyslog而不是syslog,不过rsyslog可以看作syslog的增强版,差别也不大
配置
那么,就开始配置吧+_+.
]# vim /etc/rsyslog.conf
#由于haproxy的日志是用udp传输的,所以要启用rsyslog的udp监听
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
#启用级别为local2的设备,并将该设备的所有级别的日志全部输出到/var/log/haproxy.log下
local2.* /var/log/haproxy.log
配置完毕,之后重启rsyslog服务即可
现象
]# tail /var/log/haproxy.log
Mar 29 20:55:27 localhost haproxy[14363]: Proxy main started.
Mar 29 20:55:27 localhost haproxy[14363]: Proxy webservers started.
测试成功!