通过Keepalived + nginx 实现主备机及负载均衡 下载本文

通过Keepalived + nginx 实现主备机及负载均衡

实现原理

Keepalived实现VIP 主备机控制:

VIP 是外网访问的IP地址,通过 keepalived 设置,以及 VRRP 将 VIP 绑定到主机和备机上,通过权重实现控制。当主机挂掉后,keepalived 释放对主机的控制,备机接管VIP。

Nginx通过轮询应用服务实现负载均衡:

主机和备机可进一步延伸,它们只通过 Nginx 提供负载均衡。

1. Nginx Master: 130.75.131.172 2. Nginx Backup: 130.75.131.173 3. VIP: 130.75.131.174

4. server 130.75.3.171:8088; #web应用服务器1 5. server 130.75.3.169:8080; #web应用服务器2

主机环境搭建

130.75.131.172 VMware(centos 6.5) 与 网络环境设置自定义桥接模式

130.75.131.173 VMware(centos 6.5)

网络拓扑图

130.75.131.172主机 Keepalived Nginx VIP 130.75.131.174 路由 130.75.131.173备机 Keepalived Nginx VIP 130.75.131.174 130.75.3.169:8088; #web应用服务器2 130.75.3.171:8088; #web应用服务器1 Keepalived安装

准备库的安装

1. [root@localhost keepalived]# yum -y install openssl-devel 2. [root@localhost keepalived]# yum install popt-devel –y

下载并安装

3. [root@localhost keepalived]#wget

http://www.keepalived.org/software/keepalived-1.1.17.tar.gz