Keepalived安装与配置
下载并解压Keepalived安装包到两台nginx所在的服务器
- 192.168.200.1
- 192.168.200.2
执行编译安装(安装目录设置为 /usr/local/keepalived )
./configure --prefix=/usr/local/keepalived && make && make install
修改keepalived运行环境
- 将keepalived启动命令软连接到/usr/bin下
ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/keepalived
- 拷贝配置文件到Keepalived需要的目录
/usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
配置Keepalived,整合nginx(仅保留默认配置文件中的以下部分,并修改红色部分)
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 node1(备机这里为node2)
}
vrrp_instance VI_1 {
state MASTER( 备机为BACKUP )
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.200.1(备机为192.168.200.2)
priority 100(备机为99)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.135.102.88(主备机这里都一样)
}
}
启动/停止Keepalived
- /usr/bin/keepalived(手工启动)
- kill -9 keepalived_pid(强行停止)
参考资料: