安裝部署完Haproxy之后,默認是沒有開啟日志記錄的,需要相應的手工配置使其日志功能開啟。
【創(chuàng)建日志記錄文件夾】
mkdir /var/log/haproxy
chmod a+x /var/log/haproxy
【開啟rsyslog記錄haproxy日志功能】
vim /etc/rsyslog.conf
修改:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
開啟514 UDP監(jiān)聽
添加:
# Save haproxy log
local0.* /var/log/haproxy/haproxy.log
指定日志存放點
【修改/etc/sysconfig/rsyslog】
vim /etc/sysconfig/rsyslog
添加以下內容:
# Options for rsyslogd
# Syslogd options are deprecated since rsyslog v3.
# If you want to use them, switch to compatibility mode 2 by “-c 2”
# See rsyslogd(8) for more details
SYSLOGD_OPTIONS=”-r -m 0 -c 2″
【haproxy配置】
vim /etc/haproxy/haproxy.conf
添加:
global #在此上級目錄下配置
log 127.0.0.1 local0 info
配置local0事件
【驗證服務是否生效】
###重啟服務
systemctl restart haproxy
systemctl restart rsyslog
###查看日志記錄
tailf /var/log/haproxy/haproxy.log