分类目录

链接

2018 年 1 月
1234567
891011121314
15161718192021
22232425262728
293031  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > DevOps, LINUX, 系统架构 > 正文
nginx+keepalive负载均衡高可用
DevOps, LINUX, 系统架构 暂无评论 阅读(519)

nginx搭建负载均衡详见:

这里不细说。下面说明一下怎么用keepalive实现Nginx高可用

1、准备

两台浮在均衡服务器:

192.168.31.213

192.168.31.246

准备VIP(虚拟IP):192.168.31.31

2、为两台均衡服务器安装keepalive

准备依赖包:

yum -y install gcc pcre-devel zlib-devel openssl-devel
yum -y install popt-devel

下载

wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
安装keepalive

  1. tar zxvf keepalived-1.2.7.tar.gz
  2. cd keepalived-1.2.7
  3. ./configure
  4. make 
  5. make install
  6.  
  7. cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
  8. cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
  9. mkdir /etc/keepalived
  10. cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
  11. cp /usr/local/sbin/keepalived /usr/sbin/

配置keepalived

按照上面的安装方法,keepalived的配置文件在/etc/keepalived/keepalived.conf。主、从服务器的配置相关联但有所不同。如下:

  1. ! Configuration File for keepalived  
  2.   
  3. global_defs {  
  4.    router_id NIGNX_DEVEL  
  5. }  
  6.   
  7. vrrp_script chk_http_port {  
  8.     script "</dev/tcp/127.0.0.1/80"  
  9.     interval 1  
  10.     weight -2  
  11. }  
  12.   
  13. vrrp_instance VI_1 {  
  14.     state MASTER  
  15.     interface eth0  
  16.     virtual_router_id 51  
  17.     priority 100  
  18.     advert_int 1  
  19.     authentication {  
  20.         auth_type PASS  
  21.         auth_pass 1111  
  22.     }  
  23.     virtual_ipaddress {  
  24.         192.168.31.31  
  25.     }  
  26.     track_script {  
  27.         chk_http_port  
  28.     }  
  29. }     

备用节点

  1. ! Configuration File for keepalived  
  2.   
  3. global_defs {  
  4.    router_id NIGNX_DEVEL  
  5. }  
  6.   
  7. vrrp_script chk_http_port {  
  8.     script "</dev/tcp/127.0.0.1/80"  
  9.     interval 1  
  10.     weight -2  
  11. }  
  12.   
  13. vrrp_instance VI_1 {  
  14.     state BACKUP    
  15.     interface eth0  
  16.     virtual_router_id 51  
  17.     priority 99  
  18.     advert_int 1  
  19.     authentication {  
  20.         auth_type PASS  
  21.         auth_pass 1111  
  22.     }  
  23.     virtual_ipaddress {  
  24.         192.168.31.31  
  25.     }  
  26.     track_script {  
  27.         chk_http_port  
  28.     }  
  29. }     

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:nginx+keepalive负载均衡高可用 | Bruce's Blog

发表评论

留言无头像?