Article Directory
Keepalived + Haproxy + nginx
First, the two nginx servers are configured to publish pages on different websites for easy distinction.
Then Haprox provides load balancing for nginx.
Finally, keepalived provides high availability for Haproxy. The
previous blog has completed the load balancing of Haproxy for nginx. This blog mainly focuses on Keepalived for Haproxy to achieve high Available
Keepalived + Haproxy experimental operation
1、haproxy-master 192.168.138.133
slave安装好haproxy后
[root@haproxy-master ~]# \scp /etc/haproxy/haproxy.cfg 192.168.138.131:/etc/haproxy/haproxy.cfg
[root@haproxy-master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id director1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.138.200/24
}
}
[root@haproxy-master ~]# systemctl start keepalived
[root@haproxy-master ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:e7:33:2b brd ff:ff:ff:ff:ff:ff
inet 192.168.138.133/24 brd 192.168.138.255 scope global dynamic ens33
valid_lft 1244sec preferred_lft 1244sec
inet 192.168.138.200/24 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fee7:332b/64 scope link
valid_lft forever preferred_lft forever
2、haproxy-slave 192.168.138.131
[root@haproxy-slave ~]# yum -y install haproxy
[root@haproxy-slave ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id directory2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
nopreempt
virtual_router_id 80
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.138.200/24
}
}
[root@haproxy-slave ~]# systemctl start keepalived
3. Browser access verification, keepalived headshot verification
Verify that VIP access is normal
Headshot verification
4. Check the health of the scheduler Haproxy
[root@haproxy-master ~]# cat /etc/keepalived/check_haproxy.sh
#!/bin/bash
curl -I http://localhost &>/dev/null
if [ $? -ne 0 ];then
systemctl stop keepalived
fi
[root@haproxy-master ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id director1
}
vrrp_script check_haproxy {
script "/etc/keepalived/check_haproxy.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.138.200/24
}
track_script {
check_haproxy
}
}