六、keepalived配置文件的详解
(1)RS1里面的keepalived.conf上的配置
Keepalived.conf的脚本
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass keepalivedpass
}
virtual_ipaddress {
172.16.9.1
}
}
virtual_server 172.16.9.1 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
nat_mask 255.255.0.0
persistence_timeout 50
protocol TCP
real_server 192.168.0.54 80 {
weight 1
SSL_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 172.16.9.1 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.0.0
# persistence_timeout 50
protocol TCP
real_server 192.168.0.54 80 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 1
}
}
real_server 192.168.0.55 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 1
connect_port 80
}
}
}
然后把RS1上的keepalived.com复制到RS2上,并把其中的stata改成BACKUP,priority修改为100,其他内容不变
RS2里面的keepalived.conf脚本
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass keepalivedpass
}
virtual_ipaddress {
172.16.9.1
}
}
virtual_server 172.16.9.1 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.0.0
# persistence_timeout 50
protocol TCP
real_server 192.168.0.54 80 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 1
}
}
real_server 192.168.0.55 {
weight 2
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 1
connect_port 80
}
}
}
启动keepalived服务;
访问虚拟IP地址