keepalived(主主) 结合lvs(dr工作 模式) 实现高可用性。

keepalived(主主) 结合lvs(dr工作 模式) 实现高可用性。

client: 192.168.100.6
————————————————-

#for i in {1..10};do sleep 0.5;curl 192.168.100.200;done

proxy1: 192.168.100.7
————————————————–
vim /etc/keepalived/keepalived.conf –配置文件
vrrp_instance VI_1 { –主
state MASTER
interface eth1
virtual_router_id 66
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.100/24
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
#lvs-dr
virtual_server 192.168.100.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCP
sorry_server 127.0.0.1 80

real_server 192.168.100.27 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.37 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
# ——lingwai de yige cong—————————–
vrrp_instance VI_2 { –从
state BACKUP
interface eth1
virtual_router_id 88
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 54321
}
virtual_ipaddress {
192.168.100.200/24
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
#lvs-dr
virtual_server 192.168.100.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCP
sorry_server 127.0.0.1 80

real_server 192.168.100.28 80 {
weight 1
HTTP_GET {
url {
path /
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.38 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

proxy2: 192.168.100.17
————————————————–
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 66
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.100/24
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}

virtual_server 192.168.100.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCP
sorry_server 127.0.0.1 80

real_server 192.168.100.27 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.37 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
# ——lingwai de yige zu—————————–
vrrp_instance VI_2 {
state MASTER
interface eth1
virtual_router_id 88
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 54321
}
virtual_ipaddress {
192.168.100.200/24
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
virtual_server 192.168.100.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
# persistence_timeout 50
protocol TCP
sorry_server 127.0.0.1 80

real_server 192.168.100.28 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.100.38 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

自测试:
#curl 192.168.100.37
192.168.100.100 RS2
#curl 192.168.100.38
192.168.100.200 RS2

自测试:
curl 192.168.100.27
192.168.100.100 RS1 –网站内容
curl 192.168.100.28
192.168.100.200 RS1

 

测试用户:
for i in {1..1000};do sleep 0.5;curl 192.168.100.200;curl 192.168.100;100;done
宕机 proxy1
killall -9 keepalived

访问不受影响 .

小结2 : 宕机 RS1
for i in {1..1000};do sleep 0.5;curl 192.168.100.200;curl 192.168.100;100;done
影响2 3 秒 。

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92090

联系我们

400-080-6560

在线咨询

工作时间:周一至周五,9:30-18:30,节假日同时也值班

QR code