【Haproxy】To setup logging in HAproxy

以下方法适用于RHEL,其他平台没有测试过。
Step 1: In Global Section of haproxy.cfg put the value log 127.0.0.1 local0 .Like given below
global log 127.0.0.1 local0
log语法:

log

[len ] [format ] [ []]
备注:
address:指明日志存储设备的IP。
facility:日志设备名称(local0~7)
[ []]:空缺表示存储所示级别日志。如果指明,表示存储改级别及以上的日志。
修改/etc/rsyslog.conf,添加local0.none到下面这行保存,并重启rsyslog服务:
*.info;local0.none;mail.none;authpriv.none;cron.none /var/log/messages
备注:
默认情况下,local0.info信息也会被记录到 /var/log/messages。经过这样修改后,只保存到/var/log/haproxy.log文件中。
Step 2: Create new haproxy configuration file in /etc/rsyslog.d . Here we are keeping the log in localhost or in other words we should say HAproxy server
Note:
local0.=info -/var/log/haproxy.log defines the http log will be saved in haproxy.log
local0.notice -/var/log/haproxy-status.log defines the Server status like start,stop,restart,down,up etc. will be saved in haproxy-status.log
UDPServerRun 514 means opening UDP port no. 514 to listen haproxy messages
vi /etc/rsyslog.d/haproxy.conf $ModLoad imudp $UDPServerRun 514 $template Haproxy,”%syslogseverity-text% %msg%\n”
$template Haproxy-status,”%syslogseverity-text% %timereported% %msg%\n”
#大流量情况下,提高消息级别
local0.=info -/var/log/haproxy.log;Haproxy
local0.notice -/var/log/haproxy-status.log;Haproxy-status
service rsyslog restart
Step 3: Now restart the HAproxy service
/etc/init.d/haproxy restart
After restarting the haproxy service two logs will be created itself i.e haproxy.log and haproxy-status.log
Step 4: Check your logrotae file for haproxy also so that logs keep on rotating and compress itself. If bydefault it is not present in /etc/logrotate.d directory then create a new file called haproxy and paste the given below code.
Here I am keeping the logs upto 120 days hence rotate 120 and daily is written in file.
cat /etc/logrotate.d/haproxy
/var/log/haproxy.log {
 missingok
 notifempty
 sharedscripts
 rotate 120
 daily
 compress
 postrotate
   service rsyslog restart >/dev/null2>&1||true
 endscript
}

【Haproxy】To setup logging in HAproxy》有1个想法

  1. 我也按照这篇官方文档配置的,但到了120天后就不再记录日志了。后来发现官方文档中有个地方我没有修改:
    postrotate
    reload rsyslog >/dev/null2>&1||true
    endscript
    晕倒!

回复 匿名 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注