After installing the HAproxy 1.4 in CentOS 6.4 bydefault logging of haproxy was not enable.To enable the logging of HAProxy you have to enable it in rsyslog(In CentOS 6.4 minimal installation,rsyslog version 5.2 is shipped).
To setup logging in HAproxy,follow the given below steps
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
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:
vi /etc/rsyslog.d/haproxy.conf $ModLoad imudp $UDPServerRun 514 $template Haproxy,"%msg%n" local0.=info -/var/log/haproxy.log;Haproxy local0.notice -/var/log/haproxy-status.log;Haproxy ### keep logs in localhost ## local0.* ~
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 reload rsyslog >/dev/null 2>&1 || true endscript }
postrotate
reload rsyslog >/dev/null 2>&1 || true
Dont you mean reload haproxy?
Nope. rsyslogd is the process writing the log, not haproxy.
Along with HAProxy we would neet to restart rsyslog daemon also.
[root@localhost ~ ]# /etc/init.d/rsyslog restart
Great article thank you!
As per
https://www.percona.com/blog/2014/10/03/haproxy-give-me-some-logs-on-centos-6-5/
Works perfectly, had to restart rsyslog to get the logs showing; I’m not sure if that’s specific to my distro, had me tearing my hair out 🙂
On Debian (& alikes) the syslog configrutation needs a
$UDPServerAddress 127.0.0.1
before the “$UDPServerRun 514 ”
and rsyslogd has to be started with the options “-c2 -r514” (the -r is not even in the man pages)
Awesome post, just what i needed. Thanks!!
Thankyou Mahesh,
Regards
Sharad
reload rsyslog >/dev/null 2>&1 || true
Why do you make sure nobody will ever notice if this command fails – which it does?
Hello Gerard,
The post is old, may I know which OS version you are using.
Regards
Sharad
Thankyou Gerard,
Your suggestion is good.
Regards
Sharad
Helpful. Thanks.