How to enable HAProxy logs on CentOS 8

Published Jan 6, 20202 min read 0 comments

Tags: linux centos haproxy

What is HAProxy?

HAProxy is an open-source, high availability load balancer that quietly sits in front of any TCP/HTTP service. It's well-known for its efficiency and reliability, and often used to manage the traffic of high-volume and distributed systems.

If you're using HAProxy, you may have come across a situation where you're looking through application logs only to realize that you can't find the information you're looking for. For example, maybe you're looking in apache logs trying to isolate the IP of a web crawler and instead find the IP of your HAProxy instance. Logically, you log in to the machine running HAProxy for further analysis where you hit a roadblock.

Where are HAProxy logs stored?

The default configuration in /etc/haproxy/haproxy.cfg defines the global log parameter, but a search for HAProxy logs will come up empty. That is because rsyslog only uses the imjournal and imusock modules for message reception out of the box.

File: /etc/haproxy/haproxy.cfg

    log local2
    # Additional parameters...

In order to enable logging from HAProxy, you need to configure rsyslog to use the imupd module as well. As root, find and uncomment the following lines in your configuration file:

File: /etc/rsyslog.conf

input(type="imudp" port="514")

Now create a configuration file that tells rsyslog where to log HAProxy messages.

sudo echo "local2.* /var/log/haproxy.log" > /etc/rsyslog.d/haproxy.conf

and restart the rsyslog service.

sudo systemctl restart rsyslog

You should now see /var/log/haproxy.log and can get back to debugging. Additional configuration details for logging can be found here:

More Articles
Install MySQL Community Server on CentOS 8
Install MySQL Community Server on CentOS 8
Jan 14, 2020
Where does MariaDB save output from SELECT INTO OUTFILE on CentOS 8?
Where does MariaDB save output from SELECT INTO OUTFILE on CentOS 8?
Feb 1, 2020
Copyright © 2017-2023   Mark Brody | Blog