主keepalived
yum install keepalived -y
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.120.0.12
}
}
virtual_server 10.120.0.12 80 {
delay_loop 6 #健康檢測卡間隔
lb_algo rr #負載均衡調度算法
lb_kind DR #lVS模式
persistence_timeout 50
protocol TCP
real_server 10.120.0.61 80 {
weight 3
TCP_CHECK {
connect_timeout 10 #連接超時時間
nb_get_retry 3 #重連次數
delay_before_retry 3 #重連間隔時間
connect_port 80
}
}
real_server 10.120.0.62 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
從keepalived
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.120.0.12
}
}
virtual_server 10.120.0.12 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 10.120.0.61 80 {
weight 5
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 10.120.0.62 80 {
weight 5
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
ipvsadm -a -t 10.120.0.12:80 -r 10.120.0.61:80 -g
ipvsadm -a -t 10.120.0.12:80 -r 10.120.0.62:80 -g
systemctl start keepalived.service