1.准备两台服务器 且都安装nginx 和keepalived
安装keepalived
yum install keepalived -y
安装好后linux 的etc 文件夹下面会有keepalived文件夹以及配置文件
2. 修改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.17.129
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/usr/local/src/nginx_check.sh"
interval 2 #(检测脚本执行的间隔)
weight 2
}
vrrp_instance VI_1 {
state BACKUP # 备份服务器上将 MASTER 改为 BACKUP
interface ens33 //网卡
virtual_router_id 51 # 主、备机的 virtual_router_id 必须相同
priority 90 # 主、备机取不同的优先级,主机值较大,备份机值较小
advert_int 1
authentication{
auth_type PASS
auth_pass 1111
}
virtual_ipaddress{
192.168.17.50 // VRRP H 虚拟地址
}
3.添加校验的脚本
#!/bin/bash
A=`ps -C nginx –no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/nginx/sbin/nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
killall keepalived
fi
fi```
以及运行./nginx.check.sh
4.启动两台服务器的nginx 和keepalived
systemctl start keepalived.service
5.测试浏览器输入地址 然后听主机的nginx和keepalived的地址
-------------------------集群配置可能还有问题先记录 后续在修改---------------------------------------