keepalived软件的相关应用

『1』keepalived的后端健康检查与负载均衡

1、yum install libnl-devel iptables-devel openssl-devel
libnfnetlink-devel -y
2、./configure --prefix=/usr/local/keepalived --with-init=SYSV
3、make
4、make install

keepalived软件的相关应用_第1张图片    

                                                             ----此为编译完成,该程序的依赖性镜像中并非都有,libnfnetlink-devel的rpm包可使用wget的方法:

wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-1.0.0-1.el6.x86_64.rpm
wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm
rpm -ivh libnfnetlink-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-1.0.0-1.el6.x86_64.rpm包

rpm -ivh libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm包

5、ln -s /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/
      ln -s /usr/local/keepalived/etc/keepalived/ /etc/
      ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
      ln -s /usr/local/keepalived/sbin/keepalived /sbin/
      chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived

                                                                ----制作软链接,方便keepalived的管理与设置,并给他的脚本执行权限

6、/etc/init.d/keepalived start              ----启动keepalived

keepalived软件的相关应用_第2张图片

***********************************                  keeppalived的安装完成          ************************************************

『2』设置并检测

! Configuration File for keepalived

global_defs {
   notification_email {
        root@localhost                     ----运行时发送邮件地址
   }
   notification_email_from [email protected]
   smtp_server 127.0.0.1             ----设置smtp server 地址
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
#   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER                       ----指定角色,MASTER表示该服务器为主机
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.25.35.100                  ----设置虚拟地址
    }
}

virtual_server 172.25.35.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR                          ----设置lvs负载均衡机制
    #persistence_timeout 50
    protocol TCP

    real_server 172.25.35.2 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }

    real_server 172.25.35.3 80 {
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }
}
                                                            ----配置文件如上
keepalived软件的相关应用_第3张图片                ----配置完成后访问结果,实现负载均衡

『3』keepalived的高可用            --DRRP协议

1、server4 yum源中添加高频
2、server1:scp -r keepalived/ 172.25.254.4:/usr/local/
3、server4:添加软链接
ln -s /usr/local/keepalived/etc/keepalived/ /etc/
ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived
修改配置文件:
vrrp_instance VI_1 {
    state BACKUP            ----表示次服务器为替补服务器
    interface eth0
    virtual_router_id 51    ----id要与主服务器对应
    priority 50                    ----优先级(数字越大越高)
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.25.35.100
    }
}

keepalived软件的相关应用_第4张图片

此为server1与server4同时打开时物理机访问vip中调度机的物理地址

keepalived软件的相关应用_第5张图片

此为关闭server1keepalived服务后物理机后访问vip中调度机的物理地址

*******二者不相同,说明keepalived实现了高可用当server1出现问题时调度任务会自动在server4上运行*****

你可能感兴趣的:(keepalived软件的相关应用)