zhangxinba 发表于 2018-12-30 13:47:20

Nginx+keepalived(部分配置)

https://s5.运维网.com/wyfs02/M00/99/83/wKioL1lJDYrTZE35AADvDgGFhMs149.png
https://s2.运维网.com/wyfs02/M02/99/83/wKiom1lJDYug3J5zAADpNT01XxI704.png
https://s4.运维网.com/wyfs02/M01/99/83/wKiom1lJDYyi_LCKAADM_GwjXBU992.png
https://s4.运维网.com/wyfs02/M02/99/83/wKioL1lJDY2hGSm_AACGpX6SNnU933.png
https://s4.运维网.com/wyfs02/M01/99/83/wKioL1lJDY6yzHYNAAC-EY8D5vw110.png
https://s3.运维网.com/wyfs02/M02/99/83/wKiom1lJDY_ibbn5AACraCNl3Ko496.png
Nginx-S上面也要配置跟Nginx-M上面一样的Nginx代理服务配置
  

Nginx-M和Nginx-S的keepalived服务配置:
https://s1.运维网.com/wyfs02/M00/99/83/wKiom1lJDY-xSuvkAACgeCHODYw041.png
https://s1.运维网.com/wyfs02/M00/99/83/wKioL1lJDZCAD_paAACKAz0haDE994.png
配置文件模板:
! Configuration File for keepalived
global_defs {
notification_email {
ops@wangshibo.cn
tech@wangshibo.cn
}
notification_email_from ops@wangshibo.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id master-node
}
vrrp_script chk_http_port {
script "/opt/chk_nginx.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
mcast_src_ip 192.168.115.173
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.115.100
}
track_script {
chk_http_port
}
}
https://s1.运维网.com/wyfs02/M01/99/83/wKiom1lJDZGDn4oyAACvFqbbVV8267.png
此监控脚本Nginx-S服务器上面也需要:
脚本模板:
#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
service nginx restart
sleep 2
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
service keepalived stop
fi
fi


WEB服务器上面只需要搭建Apache服务即可,不需要做其他的网络设置
将Nginx-M和Nginx-S服务器上面的keepalived和Nginx服务开启,再将/opt/下面的监控脚本执行,之后停掉任何一台Nginx代理服务器查看效果验证是否一台Nginx代理服务器宕机的情况下,另一台继续工作
  




页: [1]
查看完整版本: Nginx+keepalived(部分配置)