1、两台机器成功搭建keepalived并启动。
master:192.168.5.200 backup:192.168.5.100 virtualIP:192.168.5.199
主配置文件如下:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
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 {
192.168.5.199
}
}
备配置文件如下:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.199
}
}
主备份keepalived都启动时,并且192.168.5.100与192.168.5.200两台服务器的apache都启动,则此时在主服务器上发现此时192.168.5.199绑定在eth0上。
这时访问:192.168.5.199会访问的是主的apache项目。
当主keepalived停止后,在backup服务器上ip a会发现virtualIP 192.168.5.199漂移到了备份服务器上,并绑定了备份服务器的eth0端口,则此时访问192.168.5.199是访问的备份服务器上的apache项目。