How to Configure HAProxy Logging on CentOS Linux

HAProxy is an open source software that provides a high availability, load balancer and proxy server for TCP and HTTP based applications that spreads requests across multiple server. Most of the HAProxy installation is not configured with store logs.

Steps to install and configure HAProxy with store log is as follows

Installation and Enabling HAProxy

# dnf install haproxy

To enable and start the service

#systemctl enable haproxy.service

On running the command, the following output is shown

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

To start the service, use the following command –

#systemctl start haproxy.service

To check the status of the service, use the following command –

                #systemctl status haproxy.service

HAProxy service is running on server now. The next step is to configure the logging process

Configuring HAProxy Logging

Open /etc/haproxy/haproxy.cfg in any editor like vim or vi or nano

#vi /etc/haproxy/haproxy.cfg

Comment out the line “log 127.0.0.1 local2”

#log 127.0.0.1 local2

chroot /var/lib/haproxy

pidfile /var/run/haproxy.pid

The next step is to add a line “log/dev/log local0”below the commented (# ) line

This will create a file inside the directory that has Rsyslog and it will use Rsyslog to collect log entries.

Save the changes made to /etc/haproxy/haproxy.cfg

The next step is to create the dev directory in /var/lib/haproxy

                # mkdir /var/lib/haproxy/dev

                # systemctl restart haproxy.service

Configuration of Rsyslog to collect HAProxy Logs

Create a new file /etc/rsyslog.d/xyz-haproxy.conf using an editor like vi, vim or nano

                # vi /etc/rsyslog.d/xyz-haproxy.conf

Add the following lines to the file and save the file.

# AddUnixListenSocket /var/lib/haproxy/dev/log

# Send HAProxy messages to a dedicated logfile

:programname, startswith, “haproxy” {

/var/log/haproxy.log

stop

}

Haproxy will log the details in rsyslog.

At Velan, our server support engineers can help you configure HAProxy and setup logging to a file on your server. We troubleshoot problems like these for our clients every day. If you are interested in our service, please fill the Quick connect form to get in touch with us

Credentials

Quick Connect With Us


    captcha
    reload