HAProxy is frequently used as a load-balancer in front of a Galera cluster. While diagnosing an issue with HAProxy configuration, I realized that logging doesn’t work out of the box on CentOS 6.5. Here is a simple recipe to fix the issue.
If you look at the top of /etc/haproxy/haproxy.cfg
, you will see something like:
1 2 3 |
global log 127.0.0.1 local2 [...] |
This means that HAProxy will send its messages to rsyslog on 127.0.0.1. But by default, rsyslog doesn’t listen on any address, hence the issue.
Let’s edit /etc/rsyslog.conf
and uncomment these lines:
1 2 |
$ModLoad imudp $UDPServerRun 514 |
This will make rsyslog listen on UDP port 514 for all IP addresses. Optionally you can limit to 127.0.0.1 by adding:
1 |
$UDPServerAddress 127.0.0.1 |
Now create a /etc/rsyslog.d/haproxy.conf
file containing:
1 |
local2.* /var/log/haproxy.log |
You can of course be more specific and create separate log files according to the level of messages:
1 2 |
local2.=info /var/log/haproxy-info.log local2.notice /var/log/haproxy-allbutinfo.log |
Then restart rsyslog and see that log files are created:
1 2 3 4 5 6 7 |
# service rsyslog restart Shutting down system logger: [ OK ] Starting system logger: [ OK ] # ls -l /var/log | grep haproxy -rw-------. 1 root root 131 3 oct. 10:43 haproxy-allbutinfo.log -rw-------. 1 root root 106 3 oct. 10:42 haproxy-info.log |
Now you can start your debugging session!
Comments (16)
Well done. Worked like a charm.
Perfect! Thanks for easy-to-follow directions.
Thanks a lot, sir!
thanks,works well
This was awesome, thanks for making such a clear and concise post.
thanks; very clear and concise!
best that 2 kilos of official blabla
Worked like a charm
@del.
if i can add something … to prevent the haproxy messages to continue filling-up /var/log/messages, add
‘& ~’ => rsyslog rsyslog >= v.7
# vi /etc/rsyslog.d/haproxy.conf
local0.* /var/log/haproxy.log
& ~
:wq
credit:
http://serverfault.com/questions/214312/how-to-keep-haproxy-log-messages-out-of-var-log-syslog
Very helpful, thank you!
Works well.
same logic was implemeted, in linux. unfortunately it didn’t work for me. no issues while restarting both rsyslog and haproxy services but no logs were created
Exact same thing happened to me. I followed the instructions to a tee. Still did not work. Did you end up finding a solution?
work perfectly!
ty
Thanks, great post, and it works on CentOS 7 as well.
It didn’t work for me 🙁 the logs are not even created by rsyslog… I’ve been strugling with this issue for a couple of days, googled everything I could, everything leads to the same kind of posts
SO: RHEL 7.5
haproxy version 1.5.18-7.el7
I added the exact config mentioned on this post
any clues?
Thank’s a bunch! For anyone with issues till. Make sure you create the file first and give it any necessary permissions as well. Eg; “touch /var/log/haproxy/haproxy.log”
Comments are closed.
Use Percona's Technical Forum to ask any follow-up questions on this blog topic.