Ubuntu 14.04
Sponsored Link

HAProxy : Load Balancing on Layer4
2016/01/07
 
Configure HAProxy on Layer4 Mode.
This example based on the environment like follows.
       |
-------+-----------------------------------------------
       |
       +-------------------+--------------------+
       |10.0.0.30          |10.0.0.31           |10.0.0.32
 +-----+-----+     +-------+------+     +-------+------+
 | Frontend  |     |   Backend#1  |     |   Backend#2  |
 |  HAProxy  |     |    MariaDB   |     |    MariaDB   |
 +-----------+     +--------------+     +--------------+

[1] Configure HAProxy.
root@dlp:~#
vi /etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2 info
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     256
    user        haproxy
    group       haproxy
    daemon

defaults
      # set "mode tcp" for Layer4

    mode               tcp
    log                global
    timeout connect    10s
    timeout client     30s
    timeout server     30s

# define frontend and backend servers

frontend  mysql-in
    bind *:3306
    default_backend    backend_servers

backend backend_servers
    balance            roundrobin
    server             db01 10.0.0.31:3306 check
    server             db02 10.0.0.32:3306 check

root@dlp:~#
/etc/init.d/haproxy restart

[2] Make sure all works fine to access to the frontend server from a Client with SQL like follows.
root@desktop:~#
mysql -u keystone -p -h 10.0.0.30 keystone -e "select * from table01;"

Enter password:
+------+-------------------+
| id   | name              |
+------+-------------------+
|    1 | db01.srv.world |
+------+-------------------+

root@desktop:~#
mysql -u keystone -p -h 10.0.0.30 keystone -e "select * from table01;"

Enter password:
+------+-------------------+
| id   | name              |
+------+-------------------+
|    1 | db02.srv.world |
+------+-------------------+
Matched Content
 
Tweet