Keepalived是专门针对LVS设计的一款强大的辅助工具,主要用来提供故障切换和健康检查功能–判断LVS负载调度器、节点服务器的可用性,及时隔离并替换新的服务器,当故障主机恢复后将其重新加入集群。
实验环境
客户端:192.168.136.130
虚拟IP:192.168.136.100
LVS1:192.168.136.133
LVS2: 192.168.136.137
RS1: 192.168.136.134
RS2: 192.168.136.135
systemctl stop firewalld
setenforce 0
|
LVS配置
yum install -y keepalived -y ipvsadm
global_defs { router_id LVS-1 }
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.136.100 } }
virtual_server 192.168.136.100 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP
real_server 192.168.136.134 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.136.135 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
global_defs { router_id LVS-2 }
vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 51 priority 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.136.100 } }
virtual_server 192.168.136.100 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP
real_server 192.168.136.134 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.136.135 80 { weight 1 TCP_CHECK { connect_port 80 connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } }
systemctl enable keepalived && systemctl enable ipvsadm
reboot
|
RS1服务器配置
yum install -y httpd
echo "web1" > /var/www/html/index.html
systemctl start httpd && systemctl enable httpd
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0 IPADDR=192.168.136.100 NETMASK=255.255.255.255 ONBOOT=yes
/sbin/route add -host 192.168.136.100 dev lo:0
net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2
reboot
|
RS2配置
yum install -y httpd
echo "web2" > /var/www/html/index.html
systemctl start httpd && systemctl enable httpd
cp /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0 IPADDR=192.168.136.100 NETMASK=255.255.255.255 ONBOOT=yes
/sbin/route add -host 192.168.136.100 dev lo:0
net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.ipv4.conf.default.arp_ignore = 1 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_ignore = 1 net.ipv4.conf.lo.arp_announce = 2
reboot
|