Configure HAproxy with MariaDB using Ubuntu 22.04 LTS


HAProxy is a free HTTP/TCP high accessibility load balancer and intermediary worker. It spreads demands among various workers to moderate issues coming about because of single worker disappointment. HA Proxy is utilized by various prominent sites including GitHub, Bitbucket, Stack Overflow, Reddit, Tumblr, Twitter and Tuenti and is utilized in the OpsWorks item from Amazon Web Services.
Step 1: Update the Systen
You need to use the given command to update the ubuntu current repository and upgrade the ubuntu packages.

sudo apt-get update


sudo apt-get upgrade -y

Step 2: Install HAproxy
You need to install the HAproxy by using the following command.

sudo apt-get install haproxy -y

After installation of the packages you need to verify the haproxy service status, Use the following command to do that.

sudo systemctl status haproxy

You should get the service output like this.

By default you will get the HAproxy service on boot enable and running state while installation the package.

Step 3: Enable Stats
To enable Haproxy stats is optional, You wants to haproxy stats lets do the following configuration in HAproxy main configuration file.


sudo vim /etc/haproxy/haproxy.cfg

and add the given syntac in the end of the configuration.
listen stats 
    bind :1936
    stats enable
    stats hide-version
    stats refresh 30s
    stats show-node
    stats auth username:password
    stats uri  /stats

Save and exit from vim text editor and verify the HAproxy syntax by using the following command.

sudo haproxy -f /etc/haproxy/haproxy.cfg -c 

 If your configuration is valid so then we need to restart the HAproxy service by using the given command.

sudo systemctl restart haproxy

Step 4: HAproxy Stats
To get the HAproxy stats in the browser, You need to open the given url with port.
http://localhost:1936/stats or http://IP_Address:1936/stats along with your username with password.

After login in the Haproxy credentials, You should get the HAproxy dashboard like this.

Here you can find more HAproxy configuration for MariaDB.
For MariaDB configuration.

listen mariadb-cluster
    mode tcp
    option tcpka
    option mysql-check user haproxy_check
    balance roundrobin
    server mariadb-1 check weight 1
    server mariadb-2 check weight 1
    server mariadb
-3 check weight 1


Congrats on effectively designing HAProxy! With an essential burden balancer arrangement, you can extensively expand your web application execution and accessibility. This guide is anyway a prologue to stack offsetting with HAProxy, which is prepared to do substantially more than what could be canvassed in first-time arrangement guidance. We suggest trying different things with various designs with the assistance of the broad documentation accessible for HAProxy, and afterward begin arranging the heap adjusting for your creation climate. 

Configure HAproxy with MariaDB using Ubuntu 22.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top