部署:
LVS-MASTER : 192.168.1.2
LVS-BACKUP : 192.168.1.3
LVS-VIP : 192.168.1.4
Realserver-1 : 192.168.1.5
Realserver-2 : 192.168.1.6
1. 系统采用最小化安装
2. 安装ipvsadm
# yum install ipvsadm
3. 安装keepalived前提
# yum install -y wget
# yum install -y gcc gcc-c++ make
# yum install -y openssl-devel kernel-devel
4. 安装keepalived
# wget http://www.keepalived.org/software/keepalived-1.2.1.tar.gz
# ln -s /usr/src/kernels/2.6.18-194.26.1.el5-i686 /usr/src/linux
# tar zxvf keepalived-1.2.1.tar.gz
# cd keepalived-1.2.1
# ./configure
(注意这个步骤要看到以下字样才是正常的)
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
# make && make install
5. 配置
# 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 –level 2345 keepalived on
# vi /etc/keepalived/keepalived.conf
01 | ! Configuration File for keepalived |
07 | (function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); |
11 | notification_email_from fjcyz@qq.com |
13 | (function(){try{var s,a,i,j,r,c,l=document.getElementById("__cf_email__");a=l.className;if(a){s='';r=parseInt(a.substr(0,2),16);for(j=2;a.length-j;j+=2){c=parseInt(a.substr(j,2),16)^r;s+=String.fromCharCode(c);}s=document.createTextNode(s);l.parentNode.replaceChild(s,l);}}catch(e){}})(); |
17 | # smtp_connect_timeout 30 |
22 | state MASTER # 备份LB将MASTER改为BACKUP |
25 | priority 100 # 优先级,备份LB值改为比这个值小 |
32 | 192.168.1.4 # 多个VIP换行写 |
36 | virtual_server 192.168.1.4 80 { |
37 | delay_loop 6 #每隔6秒查询realserver状态 |
39 | lb_kind DR # LVS模式 DR是直接路由 |
40 | persistence_timeout 60 #同一IP连接60秒内分配到同一台realserver |
41 | protocol TCP #TCP协议检测realserver状态 |
43 | real_server 192.168.1.5 80 { |
46 | connect_timeout 10 #10秒无响应超时 |
52 | real_server 192.168.1.6 80 { |
6. Realserver主机上执行以下脚本
05 | . /etc/rc.d/init.d/functions |
09 | ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP |
10 | /sbin/route add -host $VIP dev lo:0 |
11 | echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore |
12 | echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce |
13 | echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore |
14 | echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce |
15 | sysctl -p >/dev/null 2>&1 |
16 | echo "RealServer Start OK" |
20 | route del $VIP >/dev/null 2>&1 |
21 | echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore |
22 | echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce |
23 | echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore |
24 | echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce |
25 | echo "RealServer Stoped" |
28 | echo "Usage: $0 {start|stop}" |
7. 检查测试
主备LB上执行
# service keepalived start
# ipvsadm -ln
检查ipvsadm是否服务正常
再把主LB执行
# service keepalived stop
查看备LB是否会自动接管VIP
另外就是做Realserver停止服务的测试,具体就不详说了.
阅读(1509) | 评论(2) | 转发(2) |