• keepalived+httpd 做web服务的高可用


     场景:

      环境中有两台httpd服务器,一台做主,一台做备用;平时只用主向外提供http服务;当主宕机后,keepalived把vip绑定到备机上去,这样就由备机提供http服务了。

      **keepalvied 这个软件还是更新的比较快的,主要问题再于它的文档并没能跟上来,不同版本之间的差别比较大,我这里用的是1.2.13版

    【0】环境说明

    主机ip            系统版本                keepavlied版本
    192.168.80.131  centos6.6        keepalived-1.2.13
    192.168.80.132  centos6.6        keepalived-1.2.13

    【1】安装keepalived 所需要的依赖

    yum -y install gcc ipvsadm openssl-devel popt-devel kernel-devel

    **由于keepalived 通常来说是和lvs配合用的,虽然这里还用不着lvs,但是我还是把ipvsadm安装上了

    【2】编译安装keepalived

    tar -xzvf keepalived-1.2.13.tar.gz 
    cd keepalived-1.2.13
    ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.32-504.el6.x86_64
    make
    make install

    【3】修改192.168.80.131主机上的/usr/local/keepalived/etc/keepalived.conf

    ! Configuration File for keepalived
    
    global_defs {
       router_id LVS_001B #router_id 这要个唯一
    }
    
    
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51 #这个virtual_router_id 在两台机器上要相同
        priority 150
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.80.80/24
        }
    }
    
    virtual_server 192.168.80.80 80 {
        delay_loop 2
        lb_algo rr
        lb_kind DR
        persistence_timeout 60
        protocol TCP
        real_server 192.168.80.131 80 {
            weight 1
            notify_down /tmp/stop_keepalive.sh #当检测到real_server 宕机的时候就会执行这个脚本
            TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 2
                delay_before_retry 1
            }
        }
    }

    【4】修改192.168.80.132主机上的/usr/local/keepalived/etc/keepalived.conf

    ! Configuration File for keepalived
    
    global_defs {
       router_id LVS_001B
    }
    
    
    vrrp_instance VI_1 {
        state BACKUP
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            192.168.80.80/24
        }
    }
    
    virtual_server 192.168.80.80 80 {
        delay_loop 2
        lb_algo rr
        lb_kind DR
        persistence_timeout 60
        protocol TCP
        real_server 192.168.80.132 80 {
            weight 1
            notify_down /tmp/stop_keepalive.sh
            TCP_CHECK {
                connect_port 80
                connect_timeout 3
                nb_get_retry 2
                delay_before_retry 1
            }
        }
    }

    【5】脚本/tmp/stop_keepalived.sh的内容如下:

    #!/bin/bash
    pkill keepalived

    【6】启动keepalived程序

    nohup /usr/local/keepalived/sbin/keepalived -D -f /usr/local/keepalived/etc/keepalived/keepalived.conf &
  • 相关阅读:
    ASP.NET 2.0 中动态添加 GridView 模板列的例子
    ASP操作Excel技术总结
    JS实现下拉列表效果
    发布无限制版CodePlusV2.0(转载)
    SQL行列转换(转载)
    [转]详解C中volatile关键字
    [转]68013开发笔记之一
    清除计算机占用串口
    modelsim保存仿真波形
    SQL存储过程分页算法研究(支持千万级) 转
  • 原文地址:https://www.cnblogs.com/JiangLe/p/6076834.html
Copyright © 2020-2023  润新知