|
一、环境
系统:CentOS 6.4x64最小化安装
DR:192.168.3.20
RS1:192.168.3.21
RS2:192.168.3.22
VIP: 192.168.3.23
二、Realserver配置httpd服务做测试
RS1配置
1
2
3
4
5
6
7
8
9
10
11
12
13
| [iyunv@RS1 ~]# yum install httpd -y
[iyunv@RS1 ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for RS1
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
#关闭防火墙,避免对实验造成影响
[iyunv@RS1 ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[iyunv@RS1 ~]# echo "RS1 Server" >/var/www/html/index.html
[iyunv@RS1 ~]# curl http://127.0.0.1
RS1 Server
|
RS2配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@RS2 ~]# yum install httpd -y
[iyunv@RS2 ~]# service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for RS2
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
#关闭防火墙,避免对实验造成影响
[iyunv@RS2 ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[iyunv@RS2 ~]# echo "RS2 Server" >/var/www/html/index.html
[iyunv@RS2 ~]# curl
RS2 Server
|
三、DR配置安装
安装基础软件包
1
| [iyunv@DR ~]# yum install make popt libnl libnl-devel popt-static gcc* -y
|
下载软件包并安装
1
2
3
4
5
6
7
| [iyunv@DR ~]# wget http://www.linuxvirtualserver.or ... ipvsadm-1.26.tar.gz
[iyunv@DR ~]# tar xf ipvsadm-1.26.tar.gz
[iyunv@DR ~]# cd ipvsadm-1.26
[iyunv@DR ipvsadm-1.26]# make
[iyunv@DR ipvsadm-1.26]# make install
#安装完成后执行ipvsadm --help,如果帮助信息输出,表示安装正常
[iyunv@DR ipvsadm-1.26]# ipvsadm --help
|
四、配置Realserver的VIP
在Realserver上执行脚本配置VIP,脚本内容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| #!/bin/bash
VIP=192.168.3.23
source /etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/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
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
route del $VIP >/dev/null 2>&1
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 "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
|
执行脚本
1
2
3
4
| [iyunv@RS1 ~]# sh realserver.sh start
RealServer Start OK
[iyunv@RS1 ~]# ip a|grep 3.23
inet 192.168.3.23/32 brd 192.168.3.23 scope global lo:0
|
在RS2上执行同样的操作
1
2
3
4
| [iyunv@RS2 ~]# sh realserver.sh start
RealServer Start OK
[iyunv@RS2 ~]# ip a |grep 3.23
inet 192.168.3.23/32 brd 192.168.3.23 scope global lo:0
|
五、在DR上添加集群服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| #在DR上配置VIP
[iyunv@DR ~]# ifconfig eth0:0 192.168.3.23
[iyunv@DR ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:e0:ca:92 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.20/24 brd 192.168.3.255 scope global eth0
inet 192.168.3.23/24 brd 192.168.3.255 scope global secondary eth0:0
inet6 fe80::20c:29ff:fee0:ca92/64 scope link
valid_lft forever preferred_lft forever
[iyunv@DR ~]# ipvsadm -A -t 192.168.3.23:80 -s rr
#说明
#-A 表示添加
#-t 表示添加VIP记录,监听端口是80
#-s 表示调度算法是轮询
[iyunv@DR ~]# ipvsadm -a -t 192.168.3.23:80 -r 192.168.3.21 -g
[iyunv@DR ~]# ipvsadm -a -t 192.168.3.23:80 -r 192.168.3.22 -g
#上述命令表示添加后端的realserver服务 ,-g表示DR模式
[iyunv@DR ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.3.23:80 rr
-> 192.168.3.21:80 Route 1 0 0
-> 192.168.3.22:80 Route 1 0 0
#关闭DR的防火墙
[iyunv@DR ~]# service iptables stop
|
测试1:直接访问http://192.168.3.23
测试2:删除后端的RS1,验证http://192.168.3.23是否能访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| [iyunv@DR ~]# ipvsadm -d -t 192.168.3.23:80 -r 192.168.3.21
[iyunv@DR ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.3.23:80 rr
-> 192.168.3.22:80 Route 1 0 0
#此时realserver只有192.168.3.22提供httpd服务,访问结果应该是RS2 Server
#测试访问http://192.168.3.23,结果正确
[iyunv@qa-web ~]# curl http://192.168.3.23
RS2 Server
[iyunv@qa-web ~]# curl http://192.168.3.23
RS2 Server
|
|
|