keepalived项目

DS1:192.168.200.100
DS2:192.168.200.200
RS1:192.168.200.12
RS2:192.168.200.22
下载keepalived
yum -y install keepalived
配置keepalived
vim /etc/keepalived/keepalived.cnf
global_defs {
}
VRRP配置DS1
vrrp_instance VI_1 {
state MASTER #角色类型MASTER|BACKUP
interface ens33 #网卡名称
virtual_router_id 51 #虚拟路由id(需要与BACKUP一致)
priority 100 #优先级
advert_int 1 #每1秒检查一次
#nopreempt #非抢占模式,默认为抢占模式
authentication {
auth_type PASS #认证类型 主备之间必须一样
auth_pass 1111 #认证密码 主备之间必须一样
}
virtual_ipaddress {
192.168.200.100 #虚拟ip(vip)
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 50
priority 66
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.200.200
}
}
virtual_server 192.168.200.100 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.200.12 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.200.22 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.200.200 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.200.12 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.200.22 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
重启添加防火墙
systemctl reestart keepalived
systemctl enable keepalived
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --protocol vrrp -j ACCEPT
DS2:
global_defs {
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
#nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.200.100
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 50
priority 88
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
192.168.200.200
}
}
virtual_server 192.168.200.200 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.200.12 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.200.22 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.200.100 80 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.200.12 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
real_server 192.168.200.22 80 {
weight 1
TCP_CHECK {
connect_timeout 3
retry 3
delay_before_retry 3
}
}
}
重启keepalived添加防火墙
systemctl reestart keepalived
systemctl enable keepalived
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --protocol vrrp -j ACCEPT
RS1配置
ifconfig lo:0 192.168.200.100 broadcast 192.168.100.100 netmask 255.255.255.255 up
route add -host 192.168.200.100 dev lo:0
ifconfig lo:1 192.168.200.200 broadcast 192.168.100.200 netmask 255.255.255.255 up
route add -host 192.168.200.200 dev lo:1
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/net/ipv4/conf/all/arp_announce
RS2配置
ifconfig lo:0 192.168.200.100 broadcast 192.168.200.100 netmask 255.255.255.255 up
route add -host 192.168.200.100 dev lo:0
ifconfig lo:1 192.168.200.100 broadcast 192.168.200.200 netmask 255.255.255.255 up
route add -host 192.168.200.200 dev lo:1
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/net/ipv4/conf/all/arp_announce
浙公网安备 33010602011771号