码迷,mamicode.com
首页 > Web开发 > 详细

keeplived 之 主从web服务

时间:2016-02-26 19:05:41      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:keepalived web主从

    由于在当初的系统集成过程中对负载均衡器的配置有问题, 一直都是单机 在跑web应用,由于业务量很小,因此,考虑通过最简单、可靠的主从双机方式解决web应用单点故障问题。

      现网环境:

    web1:    10.0.0.7  (rhel6.2 64位,部署tongweb中间件)

    web2:    10.0.0.8    (rhel6.2 64位,部署tongweb中间件)

    改造 后的系统构成:

    web1:    10.0.0.7  (keepalived+tongweb中间件)

    web2:    10.0.0.8    (keepalived+tongweb中间件)

    VIP:        10.0.0.2  (keepalived中配置为virtual server地址)

1、首先在web1、web2上安装keepalived服务:

    yum install -y keepalived

2、在web1上配置keepalived,配置文件/etc/keepalived/keepalived.conf文件如下:

    ! Configuration File for keepalived  
global_defs {  
    notification_email {  
    yuwb@zycsy.cn  
    }  
    notification_email_from yuwb@zycsy.cn
    smtp_server 127.0.0.1  
    smtp_connect_timeout 30  
    router_id web-ha  
}
 
vrrp_instance VI_1 {
    state master      
    interface em1
    virtual_router_id 52
    priority 100       
    advert_int 1
    nopreempt         
         
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.2
    }
}
 
virtual_server 10.0.0.2 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 1200        
    protocol TCP
    real_server 10.0.0.7 80 {
        weight 3
        notify_down /etc/keepalived/killkeepalived.sh  
        TCP_CHECK {
            connect_timeout 10        
            nb_get_retry 3           
            delay_before_retry 3      
            connect_port 80        
        }
    }
}     

    上面配置文件中用到的脚本 /etc/keepalived/killkeepalived.sh  如下:
#!/bin/sh  
service keepalived stop
增加可执行权限:
chmod +x /etc/keepalived/killkeepalived.sh 


3、在web2上配置keepalived,配置文件/etc/keepalived/keepalived.conf文件与web1的配置文件有区别的地方是:

    vrrp_instance VI_1 {
    state master   <--------将master 改为 slave

    .................

     priority 100   <--------将100改为 80

    ................

     real_server 10.0.0.7 80 {     <--------将10.0.0.7改为 10.0.0.8

    ................

    

    配置文件 /etc/keepalived/killkeepalived.sh 与web1的一样。

4、启动web1、web2的keepalived服务:

    service keepalived start

    将keepalived服务加到自启动服务中:

    chkconfig keepalived on


本文出自 “yuweibing的技术博客” 博客,请务必保留此出处http://yuweibing.blog.51cto.com/3879355/1745367

keeplived 之 主从web服务

标签:keepalived web主从

原文地址:http://yuweibing.blog.51cto.com/3879355/1745367

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!