安装
yum install keepalived nginx psmisc
修改系统参数
echo 'net.ipv4.ip_nonlocal_bind = 1' >> /etc/sysctl.conf
sysctl -p
防火墙
firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" destination address="224.0.0.18" protocol value="vrrp" accept' --permanent
Firewall-cmd --reload
架构
Nginx反代配置
nginx MASTER:
upstream websrvs {
server 172.18.67.11:80;
server 172.18.67.12:80;
server 127.0.0.1:80 backup;
}
server {
listen 80 ;
location / {
proxy_pass http://websrvs;
}
}
nginx BACKUP:
upstream websrvs {
server 172.18.67.11:80;
server 172.18.67.12:80;
server 127.0.0.1:80 backup;
}
server {
listen 80 ;
location / {
proxy_pass http://websrvs;
}
}
keepalived
## 主备不同之处
1,router_id 不能一致
2,state MASTER/BACKUP
3, priority 权重不能一致
4, interface ens33 网络接口注意和本机对应
keepalived master
1 |
|
keepalived backup
1 |
|
nginx 进程检查脚本
1 |
|
维护脚本
1 |
|
通知脚本
## 只是发送通知邮件,不是必须的。keepalived 1.5 + postfix 能够发送邮件。
1 |
|
参考
https://www.cnblogs.com/mrlapulga/p/6857294.html