JS技术

基于keepalived+nginx部署强健的高可用7层负载均衡方案20151214 - xuyaqun的专栏 - 博客(2)

字号+ 作者:H5之家 来源:H5之家 2015-12-15 09:14 我要评论( )

###运维管理用途: 用于区别vip跑在那台服务器上 server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } ## nginx monitor use only ###add by lai

###运维管理用途: 用于区别vip跑在那台服务器上
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

## nginx monitor use only
###add by lai monitor nginx status
                location /server-status {
                        stub_status on;
allow 127.0.0.1;
allow 192.168.0.0/24;
                }
        }



通过启停keepalived和nginx来模拟故障,测试vrrp 实例的状态切换过程(即VIP的漂移):

/etc/init.d/keepalived start/stop

/etc/init.d/nginx stop start/stop


查看VIP跑在那台服务器上:

# ip addr show|grep 192.168
    inet 192.168.0.101/24 brd 192.168.0.255 scope global em1
    inet 192.168.0.105/32 scope global em1


测试:

[root@test28 ~]$ curl 192.168.0.101
Mon Dec 14 16:27:10 CST 2015 proxy101 INSTANCE YN_API_GATEWAY MASTER 202
[root@test28 ~]$ curl 192.168.0.102
Mon Dec 14 16:34:40 CST 2015 proxy102 INSTANCE YN_API_GATEWAY BACKUP 199
[root@test28 ~]$ curl 192.168.0.105
Mon Dec 14 16:27:10 CST 2015 proxy101 INSTANCE YN_API_GATEWAY MASTER 202


# tail /var/log/keepalived.notify.log
Mon Dec 14 16:25:13 CST 2015 [proxy101] keepalived HA role state transition:
Mon Dec 14 16:25:13 CST 2015 [proxy101] keepalived HA role state transition: INSTANCE YN_API_GATEWAY MASTER 202
---------------
---------------
Mon Dec 14 16:26:34 CST 2015 [proxy101] keepalived HA role state transition:
Mon Dec 14 16:26:34 CST 2015 [proxy101] keepalived HA role state transition: INSTANCE YN_API_GATEWAY BACKUP 200
---------------
---------------
Mon Dec 14 16:27:10 CST 2015 [proxy101] keepalived HA role state transition:
Mon Dec 14 16:27:10 CST 2015 [proxy101] keepalived HA role state transition: INSTANCE YN_API_GATEWAY MASTER 202


# tail /var/log/messages
Dec 14 16:27:08 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) forcing a new MASTER election
Dec 14 16:27:08 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) forcing a new MASTER election
Dec 14 16:27:09 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) Transition to MASTER STATE
Dec 14 16:27:10 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) Entering MASTER STATE
Dec 14 16:27:10 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) setting protocol VIPs.
Dec 14 16:27:10 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) Sending gratuitous ARPs on em1 for 192.168.0.105
Dec 14 16:27:10 localhost Keepalived_healthcheckers[74307]: Netlink reflector reports IP 192.168.0.105 added
Dec 14 16:27:10 localhost Keepalived_vrrp[74308]: Remote SMTP server [127.0.0.1]:25 connected.
Dec 14 16:27:10 localhost Keepalived_vrrp[74308]: SMTP alert successfully sent.
Dec 14 16:27:15 localhost Keepalived_vrrp[74308]: VRRP_Instance(YN_API_GATEWAY) Sending gratuitous ARPs on em1 for 192.168.0.105


主备状态转换通知邮件:



通过抓包查看来了解详细的工作过程:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 基于云平台+云服务打造自己的在线翻译工具 - 无知人生,记录点滴 - 博客频道 - CSDN.NET 无知人生,记录点滴

    基于云平台+云服务打造自己的在线翻译工具 - 无知人生,记录点滴 -

    2015-12-13 13:10

  • Javascript实例教程(7) 利用Javascript基于浏览器类型的重定向_javascript教程教程

    Javascript实例教程(7) 利用Javascript基于浏览器类型的重定向_javas

    2015-10-02 17:07

  • JavaScript教程_基于YUI2.8的层染色褪色效果_Javascript教程

    JavaScript教程_基于YUI2.8的层染色褪色效果_Javascript教程

    2015-10-01 15:14

  • 基于YUI3的Slider自动轮播幻灯组件教程源码_Javascript教程

    基于YUI3的Slider自动轮播幻灯组件教程源码_Javascript教程

    2015-10-01 11:16

网友点评