HAProxy Logging with Rsyslog on CentOS 8

Need to configure HAProxy Logging Rsyslog on CentOS 8?

This guide will help you.

HAProxy (High Availability Proxy) is used for TCP and HTTP-based applications. 

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform Software Installation and Configuration on Ubuntu Servers.

In this context, we shall look into how to set up HAProxy Logging with Rsyslog on CentOS.

How To Configure HAProxy Logging Rsyslog on CentOS 8?

High Availability Proxy or HAProxy is a widely used TCP and HTTP-based proxy server that runs on Linux, Solaris, and FreeBSD.

On most of the CentOS 8 installations, HAProxy is not set up in a way to write its log output to a file by default.

Let's see how to configure this with some quick and easy steps.

Steps to follow are provided below:

1. Installing and Enabling HAProxy

First, run the following dnf command:

$ sudo dnf install haproxy

Then we have to enable and start it using the systemctl command:

$ sudo systemctl enable haproxy.service

We will get the following output:

Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service/usr/lib/systemd/system/haproxy.service.

Now we can start the service to ensure that it runs with a default configuration using the following command.

$ sudo systemctl start haproxy.service

To check the status of the service we can use the following command:

$ sudo systemctl status haproxy.service

Once we ensure that HAProxy is enabled and running, we can continue to configure HAProxy’s logging directives.

2. Configuring HAProxy Logging Directives

To configure HAProxy’s logging directives first, we have to open /etc/haproxy/haproxy.cfg in vi or your preferred editor:

$ sudo vi /etc/haproxy/haproxy.cfg

Then find the line “log local2” and comment it out by adding a # character to the beginning of the line, as given in the following example:

# /etc/sysconfig/syslog
# local2.* /var/log/haproxy.log
#log local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid

Now we have to add a line directly after the commented out line with the following contents:

log /dev/log local0

The log /dev/log local0 line will create a file inside that directory that Rsyslog will use to collect log entries from.

After that save the changes made in  /etc/haproxy/haproxy.cfg.

The final step is to create the /var/lib/haproxy/dev directory since it does not exist by default.

We can create the directory using the mkdir command and then restart HAProxy:

$ sudo mkdir /var/lib/haproxy/dev
$ sudo systemctl restart haproxy.service

3. Configuring Rsyslog to Collect HAProxy Logs

To collect logs from the HAProxy service, first, open a new file /etc/rsyslog.d/99-haproxy.conf using vi.

$ sudo vi /etc/rsyslog.d/99-haproxy.conf

Then add the following lines into the file:

$AddUnixListenSocket /var/lib/haproxy/dev/log
# Send HAProxy messages to a dedicated logfile
:programname, startswith, "haproxy" {

Once we complete editing /etc/rsyslog.d/99-haproxy.conf,  we have to save the changes made.

We have now configured HAProxy to Log Rsyslog.

[Need urgent assistance to configure Packages in Ubuntu Servers? We are happy to help you!]


This article will guide you on how to set up #HAProxy Logging #Rsyslog with some quick and easy steps. HAProxy is installed with RightScale load #balancer ServerTemplates. Load-balancer servers are also known as front-end servers. Generally, their purpose is to direct users to available #application servers. HAProxy can be installed in front of them to provide load balancing and high availability.

For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com