Enable or fix logging for HAProxy load balancer

After configuration of HAProxy to balance web traffic, I’ve noticed that HAProxy is not generating any logs in my server. Due to its load balancer role, logging is vital to diagnose any issue that might come in future.

In its default config, HAProxy send logs to a syslog facility: local0, via a socket connection. By default, your syslog configuration probably doesn’t accept socket connections, and even doesn’t have a local0 facility, so you have no HAProxy log. If you want it, configure syslog to accept TCP connections by adding -r to syslogd parameters.

On a RedHat/CentOS server, edit the value of SYSLOGD_OPTIONS in /etc/sysconfig/syslog:

SYSLOGD_OPTIONS="-m 0 -r"

On a Debian/Ubuntu server, edit the value of SYSLOGD in /etc/default/syslogd:

SYSLOGD="-r"

Then set up syslog facility local0 and direct it to file /var/log/haproxy.log or your desired location by editing /etc/syslog.conf:

local0.* /var/log/haproxy.log

finally, restart syslog service to apply changes:

$ /etc/init.d/syslog restart

You can see that HAProxy logging is started.

Other useful article on this blog that you may like to read:
* Configure HAProxy for content switching
* 5 Steps to secure your Production Linux Server
* Ensuring secure access to your Production Linux Server
* Bash script to backup essential log files in Linux Server

6 Responses to “Enable or fix logging for HAProxy load balancer”

  1. Thank you. This is exactly what I needed. Worked perfectly except to restart syslog in ubuntu the command is:

    “/etc/init.d/sysklogd restart”

  2. just what i needed thanks

  3. Thanks Curtis for your comment and tip.

  4. Thanks Malena for comment. Glad to know it helped you.

  5. Hi, thanks for the excellent guide.

    Newer versions of Ubuntu, however, uses rsyslog – not syslog.

    The guide to setup HAproxy logging for rsyslog can be read here :

    http://kevin.vanzonneveld.net/techblog/article/haproxy_logging/

    Enjoy.

  6. Proxy Blog…

    [...]Enable or fix logging for HAProxy load balancer | Linux Admin Zone[...]…

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.