手机版
你好,游客 登录 注册
背景:
阅读新闻

Ubuntu下配置Nginx+Keepalived做HA

[日期:2012-10-22] 来源:Linux社区  作者:penginpha [字体:大 中 小]

配置keepalived

$sudo vim /etc/keepalived/keepalived.conf //内容如下

MASTER机

  1. vrrp_script chk_nginx { 
  2. script "/tmp/check_http.sh" 
  3. interval 5   
  4. weight 2 
  5. } 
  6.  
  7. global_defs { 
  8.     notification_email { 
  9.     } 
  10.     notification_email_from 
  11.     smtp_server 127.0.0.1 
  12.     smtp_connect_timeout 30 
  13.     router_id LVS_Nginx 
  14. } 
  15.  
  16. vrrp_instance VI_1 { 
  17.     state MASTER 
  18.     interface eth1 
  19.     virtual_router_id 51 
  20.     mcast_src_ip 192.168.0.116 
  21.     priority 100 
  22.     advert_int 3 
  23.     smtp_alert 
  24.  
  25.     authentication { 
  26.         auth_type   PASS 
  27.         auth_pass   123456 
  28.     } 
  29.  
  30. track_script { 
  31.    chk_nginx 
  32.    } 
  33.  
  34. virtual_ipaddress { 
  35.    192.168.0.200 
  36.    } 
  37. } 

BACKUP机

  1. vrrp_script chk_nginx { 
  2. script "/tmp/check_http.sh" 
  3. interval 5   
  4. weight 2 
  5. } 
  6.  
  7. global_defs { 
  8.     notification_email { 
  9.     } 
  10.     notification_email_from 
  11.     smtp_server 127.0.0.1 
  12.     smtp_connect_timeout 30 
  13.     router_id LVS_Nginx 
  14. } 
  15.  
  16. vrrp_instance VI_1 { 
  17.     state BACKUP 
  18.     interface eth1 #实际情况而定 
  19.     virtual_router_id 51 
  20.     mcast_src_ip 192.168.0.117 
  21.     priority 50 
  22.     advert_int 3 
  23.     smtp_alert 
  24.  
  25.     authentication { 
  26.         auth_type   PASS 
  27.         auth_pass   123456 
  28.     } 
  29.  
  30. track_script { 
  31.    chk_nginx 
  32.    } 
  33.  
  34. virtual_ipaddress { 
  35.    192.168.0.200 
  36.    } 
  37. } 

CHECK_HTTP SHELL

$sudo vim  /tmp/check_http.sh

  1. #!/bin/bash 
  2.  
  3. NGINX_PROCESS='ps -C nginx --no-header | ws -l' 
  4. if[$NGINX_PROCESS -eq 0] 
  5.  then 
  6.     /etc/init.d/nginx start 
  7.     sleep 3 
  8.     if[$NGINX_PROCESS -eq 0] 
  9.      then 
  10.          /etc/init.d/keepalived stop 
  11.     fi 
  12. fi 

PS:check_http.sh在双机上相同

最后,启动全部服务进行测试,如停止MASTER机上的nginx,让BACKUP机来接管,测试见下一页 http://www.linuxidc.com/Linux/2012-10/72748p3.htm 。

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款