多实例部署就是就是在一台DS上搭建多个vip,为多个集群进行调度工作;这里我用1台DS部署2个vip,同时搭建以备DS:
DS
#yum -y install keepalived
主DS
#vim /etc/keepalived/keepalived.conf
修改配置文件
! Configuration File for keepalived
global_defs {
notification_email {
}
}
#第一部分添加一个vrrp_instance VI_2{}
#state都为MASTER
#virtual_router_id不同
#virtual_ipaddress为各自的vip
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.146.250
}
}
vrrp_instance VI_2 {
state MASTER
interface ens33
virtual_router_id 52
priority 100
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.146.150
}
}
#第二部分添加2个virtual_server
virtual_server 192.168.146.250 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.146.211 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.146.212 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.146.150 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.146.213 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.146.214 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
修改完
#systemctl restart keepalived
#yum -y install httpd
#echo -e "201\nsorry" > /var/www/html/index.html
#systemctl restart httpd
备DS
#vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 50
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.146.250
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 52
priority 50
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.146.150
}
}
virtual_server 192.168.146.250 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.146.211 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.146.212 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.146.150 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 192.168.146.213 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.146.214 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
备DS有2处需要修改:
state BACKUP
priority 50优先级要低于主DS
#systemctl restart keepalived
#yum -y install httpd
#echo -e "202\nsorry" > /var/www/html/index.html
#systemctl restart httpd
RS
RS1、RS2
#ifconfig lo:0 192.168.146.250 broadcast 192.168.146.250 netmask 255.255.255.255 up
#route add -host 192.168.146.250 dev lo:0
#echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
#echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
#echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo "2" > /proc/sys/ner/ipv4/conf/all/arp_announce
RS1
#yum -y install httpd
#echo -e "211\n1" > /var/www/html/index.html
#systemctl restart httpd
RS2
#yum -y install httpd
#echo -e "212\n1" > /var/www/html/index.html
#systemctl restart httpd
RS3、RS4
#ifconfig lo:0 192.168.146.150 broadcast 192.168.146.150 netmask 255.255.255.255 up
#route add -host 192.168.146.150 dev lo:0
#echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
#echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
#echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
#echo "2" > /proc/sys/ner/ipv4/conf/all/arp_announce
RS3
#yum -y install httpd
#echo -e "213\n2" > /var/www/html/index.html
#systemctl restart httpd
RS4
#yum -y install httpd
#echo -e "214\n2" > /var/www/html/index.html
#systemctl restart httpd
测试
停掉主DS keepalived,测试;
停掉RS1,测试;
停掉RS2,测试