How to enable Haproxy Logs in Centos

For performance  reasons HAProxy doesn't log directly to files. So we need to handle  that with syslog server.

But Haproxy also requires a syslog to listen on UDP port ( which in default syslog/rsyslog installation is not enabled )

 

So  here is how you can enable the Haproxy logging in Centos

[root@instance-00000042 haproxy]# cat /etc/rsyslog.d/haproxy.conf
# Enable UDP port 514 to listen to incoming log messages from haproxy
$ModLoad imudp
$UDPServerRun 514
$template Haproxy,"%msg%\n"
local0.=info -/var/log/haproxy/haproxy.log;Haproxy
local0.notice -/var/log/haproxy/admin.log;Haproxy
# don't log anywhere else
local0.* ~

[root@instance-00000042 haproxy]# head /home/prod/lb/conf/GGVA/haproxy/junedtest.1.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info

 

Restart the rsyslog and you will have your log's ( Make sure to enable the log roation )

 

[root@instance-00000042 rsyslog.d]# cd /var/log/haproxy/
[root@instance-00000042 haproxy]# ls -l
total 0
-rw------- 1 root root 0 Aug 5 04:00 admin.log
-rw------- 1 root root 0 Aug 5 04:00 haproxy.log

comments powered by Disqus