IT技术互动交流平台

Lvs+Keepalived构建双机高可用

作者:liuwanbing198  发布日期:2013-08-06 08:56:06
应用 IP地址 网关 Vip 公网地址
Virtual IP 10.0.1.100 119.188.13x.x(网通nat)
218.98.3x.20x(电信nat)
Lvs(master) 10.0.1.101 eth0 10.0.1.254
Lv(slave) 10.0.1.102 eth0 10.0.1.254
Real-server 10.0.1.103 eth0 10.0.1.254 10.0.1.100  lo:0
Real-server 10.0.1.104 eth0 10.0.1.254 10.0.1.100  lo:0
Virtual IP 10.0.1.200 119.188.13x.4(网通nat)
218.98.3x.201(电信nat)
Real-server 10.0.1.105 eth0 10.0.1.254 10.0.1.200  lo:0
Real-server 10.0.1.106 eth0 10.0.1.254 10.0.1.200  lo:0
1、安装LVS
rpm -ivh ipvsadm-1.24-13.el5.x86_64
2、ipvsadm检查安装
3、lsmod |grep ip_vs检查是否加装ip_vs模块
4、realserver真实节点服务器配置(103、104配置相同)
vi/etc/init.d/lvsrsdr
#!/bin/bash
#description : start realserver DR
VIP=10.0.1.100
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of RealServer DR"
/sbin/ifconfig lo:0 $VIP broadcast $VIPnetmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
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:0 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
脚本可执行模式
chmod +x /etc/init.d/lvsrsdr
启动脚本(以服务方式启动)
service lvsrsdr start
5、realserver真实节点服务器配置(105、106配置相同不同于103、104vip地址不同)
vi/etc/init.d/lvsrsdr
#!/bin/bash
#description : start realserver DR
VIP=10.0.1.200
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "start LVS of RealServer DR"
/sbin/ifconfig lo:0 $VIP broadcast $VIPnetmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
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:0 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
LVS高可用配置

1、下载安装(Master和Backup都必须安装Keepalive)
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
tar zxvf keepalived-1.2.7.tar.gz
cd keepalived-1.2.7
./configure
make

make install
2、将Keepalived以服务启动(Master和Backup同时配置)
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
service keepalived start|stop 
3、配置MASTER
cp /etc/keepalived/keepalived.conf/etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server192.168.200.1
smtp_connect_timeout 30
router_idLVS_DEVEL
}
 
vrrp_instance VI_1 {
state MASTER
interfaceeth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.1.100
10.0.1.200
}
}
 
virtual_server 10.0.1.100 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
nat_mask255.255.255.0
persistence_timeout 50
protocol TCP
 
real_server10.0.1.103 80 {
weight 1
TCP_CHECK {

connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
 
real_server10.0.1.104 80 {
weight 1
TCP_CHECK {

connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
 
}
virtual_server 10.0.1.200 80 {
delay_loop 6
lb_algo wlc
lb_kind DR
nat_mask255.255.255.0
persistence_timeout 50
protocol TCP
 
real_server10.0.1.105 80 {
weight 1
TCP_CHECK {
 
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
 
real_server10.0.1.106 80 {
weight 1
TCP_CHECK {
 
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
 
}
 
 
3、配置BACKUP          
vrrp_instance VI_1 {
state BACKUP  
    interfaceeth0           
    virtual_router_id 51
 priority 99

Tag标签: Lvs   Keepalived   双机高可用  
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规