keepalived+LVS-DR

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived+LVS-DR相关的知识,希望对你有一定的参考价值。

拓扑 VIP=192.168.2.133 主keepalived IP=192.168.2.129 备keepalived=192.168.2.130
RS1=192.168.2.131 RS2=192.168.2.132
一、安装lvs和keepalived工具

[[email protected] ~]# yum install –y keepalived  ipvsadm
[[email protected] ~]# yum install –y keepalived  ipvsadm
[[email protected] ~]# vim /etc/keepalived/keepalived.conf  
! Configuration File for keepalived

global_defs {
   notification_email {
     [email protected]
   }
   notification_email_from [email protected]
   smtp_server localhost
   smtp_connect_timeout 30
   router_id node1
}

vrrp_instance apache {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.133
    }
}

virtual_server 192.168.2.133 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.255.0
    protocol TCP

    real_server 192.168.2.131 80 {
        weight 1
         TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
              }
           }

     real_server 192.168.2.132 80 {
        weight 1
         TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
                connect_port 80
              }
             }
}

二、编辑主keepalived配置文件

三、将配置文件传至备份keepalived上并修改参数
[[email protected] keepalived]# scp keepalived.conf 192.168.2.130:/etc/keepalived/
注:修改下列参数

 router_id node2  #运行 keepalived 的机器标示符
}
vrrp_instance apache {
    state BACKUP            #当前 LVS 状态为备用分发器
    interface ens32
    virtual_router_id 51
    priority 90             #LVS 优先级,备的要比主的小 
……

RS自动化配置脚本:
[[email protected] ~]# vim /etc/init.d/lvsrsdr #写一个配置RS的脚本
#!/bin/bash
#description:start relserver
VIP=192.168.2.133
source /etc/init.d/functions #加载环境变量(可以加载所有的环境变量)
case $1 in
start)
echo ‘start LVS of Realserver DR‘
/sbin/ifconfig lo:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:1
echo ‘1‘ > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo ‘2‘ > /proc/sys/net/ipv4/conf/lo/arp_announce
echo ‘1‘ > /proc/sys/net/ipv4/conf/all/arp_ignore
echo ‘2‘ > /proc/sys/net/ipv4/conf/all/arp_announce
;;
stop)
/sbin/ifconfig lo:1 down
echo ‘Close LVS of Realserver DR‘
echo ‘0‘ > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo ‘0‘ > /proc/sys/net/ipv4/conf/lo/arp_announce
echo ‘0‘ > /proc/sys/net/ipv4/conf/all/arp_ignore
echo ‘0‘ > /proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage:$0 (start|stop)"
exit 1
esac

[[email protected] ~]# chmod +x /etc/init.d/lvsrsdr
[[email protected] ~]# /etc/init.d/lvsrsdr start
[[email protected] ~]# echo "/etc/init.d/lvsrsdr start" >> /etc/rc.local
[[email protected] ~]# ifconfig -a

以上是关于keepalived+LVS-DR的主要内容,如果未能解决你的问题,请参考以下文章

keepalived+LVS-DR

keepalived实现Lvs-dr集群的高可用

Keepalived+Lvs-DR高可用

LVS-DR+keepalived高可用群集

使用keepalived搭建高可用的LVS-DR集群

LVS-DR与 Keepalived群集