预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

nginx做负载均衡+keepalived 在前面两篇文章中,阿堂就单nginx主机搭建负载均衡环境作了详细介绍。实际上,这样的负载均衡环境还是有问题的,因为只有一台nginx主机作负载均衡,这样就会存在单点的问题,不算是最理想的架构。所以这篇文章中,阿堂就进行了进一步的深入研究探讨,考虑设计了nginx也作负载均衡的架构设计,这里阿堂用到了keepalived来作nginx的负载均衡功能。阿堂的最终的具体web架构考虑设计如下。 Nginx_MASTER:192.168.7.211提供负载均衡 Nginx_SLAVER:192.168.7.218负载均衡备机 Nginx_VIP_TP:192.168.7.219网站的VIP地址(虚拟IP) Web1server:192.168.7.211提供web服务 Web2server:192.168.7.160提供web服务 原理: VIP是外网访问的IP地址,通过keepalived设置,以及VRRP将VIP绑定到主机和备机上,通过权重实现控制。当主机挂掉后,keepalived释放对主机的控制,备机接管VIP。 安装Nginx(省略)请参考阿堂的前两篇文章安装Keepalived,让其分别作web及Nginx的HA#wgethttp://www.keepalived.org/software/keepalived-1.1.15.tar.gz#tarzxvfkeepalived-1.1.15.tar.gz#cdkeepalived-1.1.15#./configure--prefix=/usr/local/keepalived#make#makeinstall#cp/usr/local/keepalived/sbin/keepalived/usr/sbin/#cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/#cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/#mkdir/etc/keepalived#cp/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived#cd/etc/keepalived/ 设置主备nginx机器上的配置文件内容: vi/etc/keepalived/keepalived.conf !ConfigurationFileforkeepalived global_defs{ notification_email{ heyitang@qq.com } notification_email_frommaxhe@lotery.hk smtp_server127.0.0.1 smtp_connect_timeout30 router_idLVS_DEVEL } vrrp_instanceVI_1{ stateMASTER interfaceeth0 virtual_router_id51 #此处是主Nginx的IP地址. mcast_src_ip192.168.7.211 #该机的priority(优先)为100 priority100 advert_int1 authentication{ auth_typePASS auth_pass1111 } virtual_ipaddress{ 192.168.7.219 } } 前面的结构那里已经规定好了VIP和主备机的IP,所以这里按上面的填。 备机的配置文件: !ConfigurationFileforkeepalived global_defs{ notification_email{ heyitang@qq.com } notification_email_frommaxhe@lotery.hk smtp_server127.0.0.1 smtp_connect_timeout30 router_idLVS_DEVEL } vrrp_instanceVI_1{ stateSLAVER interfaceeth0 virtual_router_id51 #此处是备Nginx的IP地址. mcast_src_ip192.168.7.218 #该机的priority(优先)为99 priority99 advert_int1 authentication{ auth_typePASS auth_pass1111 } virtual_ipaddress{ 192.168.7.219 } } 这时候ping192.168.7.219是不通的。 然后在两台机器上分别启动keepal