0
点赞
收藏
分享

微信扫一扫

Nginx 配置高可用的集群

西曲风 2022-02-03 阅读 67
nginx

一 配置 /etc/keepalived/keepalivec.conf 配置文件

# 全局定义
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
}

# 虚拟 ip 的配置
vrrp_instance VI_1 {
state MASTER # 备份服务器上将 MASTER 改为 BACKUP
interface ens33 // 网卡
virtual_router_id 51 # 主、备机的 virtual_router_id 必须相同
priority 100 # 主、备机取不同的优先级,主机值较大,备份机值较小,备份服务器改为 90
advert_int 1

authentication {
auth_type PASS
auth_pass 1111
}

virtual_ipaddress {
192.168.17.50 // VRRP H 虚拟地址
}
}

二 在/usr/local/src 添加检测脚本

#!/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 和 keepalived 启动

# 启动 nginx
./nginx
# 启动 keepalived
systemctl start keepalived.service

四 测试

1 在浏览器地址栏输入 虚拟 ip 地址 192.168.17.50

2 把主服务器(192.168.17.129)nginx 和 keepalived 停止,再输入 192.168.17.50

举报

相关推荐

0 条评论