A主机:192.168.1.10
B主机:192.168.1.11
C主机:192.168.1.12
sudo yum -y install keepalived
keepalived有两个配置文件,一个是/etc/sysconfig/keepalived,一个是/etc/keepalived/keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER # B C 主机设为BACKUP
interface eth0 # IP对应的网卡
virtual_router_id 20 # 三台主机这个id要一致,如果局域网内还有其他的vip,注意这个值要与其他vip不同
priority 100 # MASTER设100,BACKUP设99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.20 # vip
}
}
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP # B C 主机设为BACKUP
interface eth0 # IP对应的网卡
virtual_router_id 20 # 三台主机这个id要一致
priority 99 # MASTER设100,BACKUP设99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.20 # vip
}
}
[Unit]
Description=LVS and VRRP High Availability Monitor
After=syslog.target network.target
[Service]
Type=forking
KillMode=process
EnvironmentFile=-/etc/sysconfig/keepalived
ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
sudo systemctl enable keepalived