-
Notifications
You must be signed in to change notification settings - Fork 0
HAProxy
This guide will show how to install the HAProxy and Keepalived on two CentOS servers, using the packages from epel repositories.
This cluster will be assembled of three servers/nodes:
node #1
hostname: ha1
IP: 192.168.70.74
node #2
hostname: ha2
IP: 192.168.70.75
virtual ip
hostname: ha-vip
IP: 192.168.70.76
On all MySQL server install and configure the mysql check with xinetd:
yum -y install xinetd
echo "mysqlchk 9200/tcp" >> /etc/services
chkconfig xinetd on
sed -i s'+/usr/bin/clustercheck+/usr/bin/clustercheck\n\tserver_args\t= clustercheckuser CLUSTERCHECK_PWD+' /etc/xinetd.d/mysqlchk
sed -i 's+log_type.*+log_type = FILE /var/log/xinetd.log+' /etc/xinetd.conf
sed -i 's+log_on_success.*+log_on_success =+' /etc/xinetd.conf
service xinetd start
Change CLUSTERCHECK_PWD with your password
On your mysql cluster add the clustercheckuser user:
GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'CLUSTERCHECK_PWD';
FLUSH PRIVILEGES;
On all two nodes execute:
yum -y install haproxy
On both two nodes execute the following commands (substitute the hostnames percona#.domain and the IPs with those of your cluster):
mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
cat << EOF > /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
uid 188
gid 188
daemon
#debug
#quiet
defaults
log global
mode http
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen mysql_cluster_roundrobin 0.0.0.0:5306
mode tcp
balance roundrobin
option httpchk
server percona1.domain 192.168.70.71:3306 check port 9200
server percona2.domain 192.168.70.72:3306 check port 9200
server percona3.domain 192.168.70.73:3306 check port 9200
listen mysql_cluster-failover 0.0.0.0:3306
mode tcp
balance leastconn
option httpchk
server percona1.domain 192.168.70.71:3306 check port 9200
server percona2.domain 192.168.70.72:3306 check port 9200 backup
server percona3.domain 192.168.70.73:3306 check port 9200 backup
listen admin 0.0.0.0:80
stats uri /
EOF
Start haproxy service on each server:
service haproxy start
chkconfig haproxy on
Keepalived makes the two HAProxy nodes redundant and create a single affidable access point using an virtual IP. This virutal IP is assigned only to one for time of the two HAProxy server and chenge in case of failure.
Install from epel repository:
yum -y install keepalived
Configure keeplalived service:
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.orig
cat << EOF > /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
grid-operations@lists.cnaf.infn.it
}
notification_email_from noreply-keepalived-gridops@cnaf.infn.it
smtp_server smpt.server
smtp_connect_timeout 30
router_id ha1
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 1 # check every second
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER
smtp_alert
virtual_router_id 51
priority 101 # 100 on master, 101 on slaves
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.70.76
}
track_script {
chk_haproxy
}
}
EOF
Configure sysctl on each server:
echo << EOF >> /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind = 1
EOF
sysctl -p
On each server start service:
service keepalived start
chkconfig keepalived on
Check the ip configuration managed by keepalived, on each server use the command and see which server is the master with the virtual IP assigned:
ip addr sh eth0
The master server must have output like this:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:f6:ed:35 brd ff:ff:ff:ff:ff:ff
inet 192.168.70.74/24 brd 192.168.122.255 scope global eth0
inet 192.168.70.76/32 scope global eth0
inet6 fe80::5054:ff:fef6:ed35/64 scope link
valid_lft forever preferred_lft forever