...
This page describes how to install and configure HAProxy and Keepalived to get a virtual IP working with a Galera cluster (datanode/services nodes) and Emmett cluster (monitoring nodes) that are already running.
Info |
---|
haproxy HAproxy is a load balancer and keepalived provides a virtual IP for failover functionality |
...
Edit
/etc/my.cnf.d/server.cnf
Add the following:
Code Block [mysqld] port=3307
Restart the service with
service mariadb restart
.
To quickly check that MySQL is listening on the right port, you can use this command:Code Block netstat -tunap | grep mysql
Create an
...
HAproxy user for each node
In MySQL, create an haproxy HAproxy user for each node. You can create the users on one of the clusters and they will replicate on the other nodes.
...
You don’t need to give these users any privileges, haproxy HAproxy will just use them to check the connection.
Install and configure
...
HAproxy
Do the following installation and configuration steps on each services node.
Use the following command to install haproxyHAproxy:
Code Block yum install haproxy -y
Go to the following folder
Code Block cd /etc/haproxy/
Copy the default configuration file
Code Block mv haproxy.cfg haproxy.cfg.bak
Create a new configuration file called
haproxy.cfg
Add the following configuration and save the file
Code Block #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats.sock mode 600 level admin stats timeout 2m #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode tcp log global option httplog option dontlognull option redispatch retries 3 timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout check 10s maxconn 3000 listen haproxy-monitoring *:8090 mode http stats enable stats show-legends stats refresh 5s stats uri / stats realm Haproxy\ Statistics stats auth monitor:AdMiN123 stats admin if TRUE #--------------------------------------------------------------------- # frontend galera-cluster #--------------------------------------------------------------------- frontend haproxy-galera-1 bind *:3306 default_backend galera-cluster #--------------------------------------------------------------------- # round robin balancing galera-cluster backend #--------------------------------------------------------------------- backend galera-cluster balance roundrobin server NodeServices1 ip1.example.com:3307 check server NodeServices2 ip2.example.com:3306 check server NodeServices3 ip3.example.com:3306 check
Here you can see that haproxy is listening on port
3306
, which was previously used by MySQL and it uses around robin
algorithm to balance the three nodes.
You must add the IP of the node that you are configuring, as well as the rest of the nodes, and for the port, when you are configuring a node, you need to add the local MySQL port, which is 3307, and for the other nodes, the haproxy port, which is 3306.
...
Code Block |
---|
chkconfig haproxy on service haproxy start |
Check
...
HAproxy
One way to check that haproxy HAproxy is running properly is to check a socket that the service creates on startup. To check the socket, we recommend the use of socat
.
...
Check that the command returns something different each time, which shows that it is balancing properly.
...
Install and configure
...
Keepalived
Do the following installation and configuration steps on each services node:
Install keepalivedKeepalived:
Code Block yum install keepalived -y
Go to the configuration folder
Code Block cd /etc/keepalived/
Copy the default configuration file
Code Block mv keepalived.conf keepalived.conf.bak
Create a new configuration file
Code Block vim keepalived.conf
...
On the main node of the Galera cluster, add the following configuration for the main node for keepalivedKeepalived:
Code Block |
---|
global_defs { router_id LBL01 } vrrp_sync_group SyncGroup01 { group { FloatIP1 } } vrrp_script check_haproxy { script "killall -0 haproxy" interval 2 weight 2 } vrrp_instance FloatIP1 { state MASTER interface eth0 virtual_router_id 10 priority 101 advert_int 1 virtual_ipaddress { vip.example.com } track_script { check_haproxy } } |
Here you need to specify the virtual IP, which in my the example configuration is 10.10.203.220. Also, keepalived Keepalived works with a main/secondary configuration, and this is the main configuration.
Add this the main configuration to the main node of the galera cluster, so it is also the main node for keepalivedKeepalived.
Then on each of the secondary nodes, make the following changes:
...
As you can see, this is very similar to the command to check that haproxy HAproxy is working, but this time we are connecting to the virtual IP, which is supplied by keepalivedKeepalived, to check keepalivedKeepalived.
...
Changes to API/UI
To make the Abiquo API use the virtual IP, log in to the server and do the following steps:
...
Install haproxy with
yum install haproxy -y
Backup default haproxy configuration file with:
mv /etc/haproxy/haproxy.cfg /etc/haproxy/backup_haproxy.cfg
Create a new configuration file with:
touch /etc/haproxy/haproxy.cfg
Edit the file and paste in the following configuration
Change the IP addresses in
backend monitoring-cluster
section to your monitoring nodes:Code Block #--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global # to have these messages end up in /var/log/haproxy.log you will # need to: # # 1) configure syslog to accept network log events. This is done # by adding the '-r' option to the SYSLOGD_OPTIONS in # /etc/sysconfig/syslog # # 2) configure local2 events to go to the /var/log/haproxy.log # file. A line like the following can be added to # /etc/sysconfig/syslog # # local2.* /var/log/haproxy.log # log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats.sock mode 600 level admin stats timeout 2m #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode tcp log global option httplog option dontlognull option redispatch retries 3 timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout check 10s maxconn 3000 listen haproxy-monitoring *:8090 mode http stats enable stats show-legends stats refresh 5s stats uri / stats realm Haproxy\ Statistics stats auth monitor:AdMiN123 stats admin if TRUE #--------------------------------------------------------------------- # frontend monitoring-cluster #--------------------------------------------------------------------- frontend haproxy-monitoring-1 bind *:36639 default_backend monitoring-cluster #--------------------------------------------------------------------- # round robin balancing monitoring-cluster backend #--------------------------------------------------------------------- backend monitoring-cluster balance roundrobin server MonNode1 10.10.51.21:36638 check server MonNode2 10.10.51.22:36638 check
In the above configuration, haproxy is listening port to
36639 (bind)
, so open the firewall on this port withfirewall-cmd --zone=public --permanent --add-port=36639/tcp
and reboot the firewall service with:systemctl restart firewalld
When you have configured all of the above on all nodes, activate and start the service with:
systemctl enable haproxy
andsystemctl start haproxy
To check if haproxy HAproxy is running, use socket.
Install it with
yum install socat -y
Run the following in the terminal (copy all 3 lines and paste them at the same time):
Code Block socat /var/lib/haproxy/stats.sock readline prompt show stat
The output should be similar to the following
There are two nodes and their status is up.
Install keepalived Keepalived with:
yum install keepalived -y
Back up the configuration file with:
mv /etc/keepalived/keepalived.conf /etc/keepalived/backup_keepalived.conf
Create a new configuration file with: touch
/etc/keepalived/keepalived.conf
...