Professional Documents
Culture Documents
Ce document montre l’installation d’un cluster HAProxy afin de configurer l'équilibrage
de charge. Cet exemple basé sur l'environnement comme suit.
1. HAProxy
# systemctl stop firewalld
# firewall-cmd --reload
# yum -y install haproxy
2. Configurer HAProxy
# mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.org
# vi /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2 info
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
# running mode
mode http
# define backend
backend backend_servers
3. Configurer Rsyslog pour log HAProxy
# vi /etc/rsyslog.conf
# ligne 15,16: décommenter, ligne 17: ajouter
$ModLoad imudp
$UDPServerRun 514
$AllowedSender UDP, 127.0.0.1
# ligne 54: changer, ligne 55 ajouter
*.info;mail.none;authpriv.none;cron.none,local2.none /var/log/messages
local2.* /var/log/haproxy.log
# systemctl restart rsyslog
# systemctl restart httpd
4. Test
NB : Toutes les commandes sont effectués sur les 02 serveurs.
IP VIRTUEL AVEC KEEPALIVED
1. Installer et configurer Keepalived
Sur le serveur 01
# yum install keepalived -y
# vi /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {
script "killall -0 haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance VI_1 {
interface eth0 # interface to monitor
state MASTER # MASTER on haproxy1, BACKUP on haproxy2
virtual_router_id 51
priority 101 # 101 on haproxy1, 100 on haproxy2
virtual_ipaddress {
0.0.0.0/24 # virtual ip address
}
track_script {
chk_haproxy
}
}
Sur le serveur 02
# yum install keepalived -y
# vi /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy {
script "killall -0 haproxy" # check the haproxy process
interval 2 # every 2 seconds
weight 2 # add 2 points if OK
}
vrrp_instance VI_1 {
interface eth0 # interface to monitor
state BACKUP # MASTER on haproxy1, BACKUP on haproxy2
virtual_router_id 51
priority 100 # 101 on haproxy1, 100 on haproxy2
virtual_ipaddress {
0.0.0.0/24 # virtual ip address
}
track_script {
chk_haproxy
}
}
2. Configurer le transfert IP
Sur les 02 serveurs
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1
3. Redémarrage des services
# systemctl enable keepalived
# systemctl start keepalived
# systemctl enable haproxy
# systemctl start haproxy
WEBOGRAPHIE :
https://www.server-world.info/en/note?os=CentOS_7&p=haproxy
https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.6/html/hi
gh_availability_guide/configuring_haproxy