nginx(负载均衡)+keepalived(HA) 实现双备

来源:互联网 发布:2015年网络红歌 编辑:程序博客网 时间:2024/05/11 04:05

 nginx做负载均衡

keepalived实现高可用性

 

 nginx做负载均衡

keepalived实现高可用性

 

安装就不说了。直接进入配置文件

192.168.0.111

192.168.0.112

 

vip:192.168.0.113

www.test.com指向vip 192.168.0.113

主的配置:

首先对/etc/keepalived/keepalived.conf做配置

 

global_defs {

  router_id Nginx_Id_1

}

vrrp_script chk_http_port {

   script "/opt/nginx_pid.sh"//监控nginx脚本

  interval 4

weight 2

}

 

vrrp_instance Nginx1 {

state MASTER

interface eth0

mcast_src_ip 192.168.0.111

virtual_router_id 71

priority 150

authentication {

auth_type PASS

auth_pass 1111

 

}

track_script {

chk_http_port

}

virtual_ipaddress {

192.168.0.103

}

}

 

以上是主的配置

注意:

script "/opt/nginx_pid.sh"是一个监控脚本。作用是监控nginx。如果nginx进程停止,这监控脚本会停止keepalived进程

这时候备的服务器建管虚拟ip

 

 下篇是nginx_pid.sh的写法(记得要给权限 chmod 755 /opt/nginx_pid.sh)