Chinaunix首页 | 论坛 | 博客
  • 博客访问: 422158
  • 博文数量: 58
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 623
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-26 18:48
个人简介

在生存面前,那纯洁的理想,原来是那么脆弱不堪!

文章分类

全部博文(58)

文章存档

2022年(1)

2021年(1)

2019年(3)

2018年(6)

2017年(6)

2016年(14)

2015年(10)

2014年(16)

2013年(1)

我的朋友

分类: 架构设计与优化

2017-02-14 17:06:16

今天尝试配置 Nginx + Keepalive 做前端高可用。最开始在Openstack平台上做,发现keepalive配置的VIP在平台会被限制访问。然后就通过kvm直接创建了两台虚拟机,保证网络完全畅通。vip不受限制。

1,IP规划:
  VIP:172.16.115.200
  MASTER:172.16.115.201
  BACKUP: 172.16.115.202

2,keepalive配置文件:(这里直接给配置文件,配置方法,网上很多,也很好)

点击(此处)折叠或打开

  1. ! Configuration File for keepalived

  2. global_defs {
  3. notification_email {
  4.         pingshunbobo@sina.cn
  5.    }

  6.    notification_email_from pingshunbobo@sina.cn
  7.    smtp_server 127.0.0.1
  8.    smtp_connect_timeout 30
  9.    router_id LVS_DEVEL

  10. }

  11. vrrp_script check_run {
  12.    script "/opt/nginx_check.sh"
  13.    interval 2
  14.    weight -5
  15.    fall 3
  16.    rise 2
  17. }

  18. vrrp_instance VI_1 {
  19.     state MASTER                    #备机使用 BACKUP
  20.     interface eth0
  21.     virtual_router_id 51
  22.     mcast_src_ip 172.16.115.201     #备机使用172.16.115.202
  23.     priority 101                    #备机使用 99 小于主机
  24.     advert_int 1
  25.     authentication {
  26.         auth_type PASS
  27.         auth_pass 1111
  28.     }

  29.     virtual_ipaddress {
  30.         172.16.115.200
  31.     }

  32.     track_script {
  33.         check_run
  34.     }
  35. }
注意:keepalive配置文件中 { 前,通常有空格,省去会出错


3,检测脚本:

/opt/nginx_check.sh

  1. #!/bin/sh
  2. # check nginx server status
  3. netstat -tlnp | grep 80 | grep nginx > /dev/null
  4. if [ $? -ne 0 ];then
  5.     /etc/init.d/nginxa restart
  6.     sleep 3
  7.     netstat -tlnp | grep 80 | grep nginx > /dev/null
  8.     [ $? -ne 0 ] && /etc/init.d/keepalived stop
  9. fi
4,原理说明:
脚本检测到本台机器的ng没有正常监听,直接关闭keepalive,backup机器接收不到advertisement会抢占使用VIP,提供服务。
阅读(2561) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~