主备之间不一样的地方仅有两处:优先级和状态
主:[root@node7_1 keepalived]# cat keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 172.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777728
virtual_router_id 1
priority 10
advert_int 1
authentication {
auth_type PASS
auth_pass cb77b8da
}
virtual_ipaddress {
192.168.1.251/32 dev eno16777728 #此处写DR模型中的VIP地址
}
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.1.251 80 { #此处写DR模型中的VIP地址
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.1.161 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
real_server 192.168.1.162 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
}
备:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 172.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
state MASTER
interface eno16777728
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass cb77b8da
}
virtual_ipaddress {
192.168.1.251/32 dev eno16777728 #此处写DR模型中的VIP地址
}
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.1.251 80 { #此处写DR模型中的VIP地址
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.1.161 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
real_server 192.168.1.162 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
}
本文出自 “Linux” 博客,请务必保留此出处http://ridingonhorse.blog.51cto.com/11265295/1873172
原文地址:http://ridingonhorse.blog.51cto.com/11265295/1873172