LVS+Keepalived实现LVS NAT模式热备配置

lvs nat模式LB热备配置网上几乎找不到相关文档,找到几个但都不靠谱,做LB主备切换时都会出现问题,无奈方案之急需,自己参考研究半天,终于用lva+keepalived获得成功,现分享一下
 
环境:CentOS 5.5 x_64
 
两个外部请求VIP:
 
VIP=192.168.1.210(对外服务端口80)
 
VIP2=192.168.1.220(对外服务端口80)
 
内部VIP(作为realserver的网关)
 
NVIP=192.168.10.210
 
主LB IP配置
 
eth0:192.168.1.211(外网)
 
eht1:192.168.10.211(内网)
 
备LB IP配置
 
eth0:192.168.1.212(外网)
 
eht1:192.168.10.212(内网)
 
两个real server IP配置
 
eth1:192.168.10.213(real server 1)
 
eht1:192.168.10.214(real server 2)
 
配置步骤:
 
1.安装ipvsadm和keepalived(主备调试器LB都安装)
 
yum install kernel-devel gcc openssl-devel
 
ln -s /usr/src/kernels/2.6.18-194.el5-x86_64/ /usr/src/linux
 
tar zxvf ipvsadm-1.24.tar.gz
 
cd ipvsadm-1.24
 
make
 
make install
 
 
 
tar zxvf keepalived-1.1.20.tar.gz
 
cd keepalived-1.1.20
 
./configure
 
make
 
make install
 
 
 
将keepalived加入系统服务中
 
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
 
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
 
mkdir /etc/keepalived
 
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
 
cp /usr/local/sbin/keepalived /usr/sbin/
 
chkconfig --add keepalived
 
chkconfig keepalived on
 
2.主备LB上打开路由转发功能
 
echo "1">/proc/sys/net/ipv4/ip_forward
 
3. 主备LB上分别配置keepalived
 
vi /etc/keepalived/keepalived.conf
 
! Configuration File for keepalived
 
 
 
global_defs {
 
  notification_email {
 
    crazyrhce@163.com
 
  }
 
  notification_email_from  crazyrhce@163.com
 
  smtp_server mail.domob.cn
 
  smtp_connect_timeout 30
 
  router_id LVS_1  #备LB此处改为LVS_2,主备LB此处id最好不要一样
 
}
 
 
 
vrrp_instance VI_1 {
 
    state MASTER #备为BACKUP
 
    interface eth0
 
    virtual_router_id 51  #实验时主备LB不能成功切换时把此值改一下
 
    priority 100 #备为99
 
    advert_int 1
 
    authentication {
 
        auth_type PASS
 
        auth_pass 1111
 
    }
 
    virtual_ipaddress {
 
        192.168.1.210
 
        192.168.1.220
 
    }
 
}
 

!配置内网虚IP
 
vrrp_instance LAN_GATEWAY {
 
    state MASTER #备LB配置为BACKUP
 
    interface eth1
 
    virtual_router_id 62 #此处值和上面不要一样
 
    priority 100
 
    advert_int 1
 
    authentication {
 
        auth_type PASS
 
        auth_pass 1111
 
    }
 
    virtual_ipaddress {
 
        192.168.10.210
 
    }
 
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/74ef69f58a6b097d144e1cad68ea7a1f.html