Haproxy 开启日志记录

安装部署完Haproxy之后,默认是没有开启日志记录的,需要相应的手工配置使其日志功能开启。

   

【创建日志记录文件夹】

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监听

   

添加:

# 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

   

原文地址:https://www.cnblogs.com/liufarui/p/11078172.html