第一部分 测试环境
两台CentOS 7服务器,搭建Apache服务器,主机名分别是Node1和Node2。准备三个IP地址,分别是
Node1:192.168.168.13 Node2:192.168.168.32 虚拟IP地址192.168.168.33
第二部分 安装keepalived
进入keepalived官网下载keepalived源码,本次测试下载的源码是keepalived-2.0.18.tar.gz。在Node1和Node2上分别安装keepalived。
解压压缩包
#tar -xzvf keepalived-2.0.18.tar.gz
安装
#./configure --prefix=/usr/local/keepalived --将文件安装在/usr/local/keepalived目录下
#make && make install
第三部分 配置keepalived
在/usr/local/keepalived/etc/keepalived/keepalived.conf进行配置。
主机Node1的配置如下:
! 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_skip_check_adv_addr
# vrrp_strict --必须注释,否则keepalived无法实现双击热备,原因不明
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance LVS {
state MASTER --主机必须为MASTER,备机必须为BACKUP
interface ens192 --主机的网络接口文件
virtual_router_id 51 --配置唯一的路由ID
priority 100 --优先级
advert_int 1
authentication { --设置keepalived主备之间通信验证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.168.33/23 --虚拟ip地址
}
}
备机Node2的配置如下:
! 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_skip_check_adv_addr
# vrrp_strict --必须注释,否则keepalived无法实现双机热备,原因不明
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance LVS {
state BACKUP --主机必须为MASTER,备机必须为BACKUP
interface ens192 --主机的网络接口文件
virtual_router_id 51 --配置唯一的路由ID
priority 90 --优先级
advert_int 1
authentication { --设置keepalived主备之间通信验证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.168.33/23 --虚拟ip地址
}
}
第四部分 启动keepalived,验证双机热备
启用./keepalived。在主机上使用ifconfig命令,发现主机上增加了ip地址192.168.168.33。