实验环境:centos6.5系统
软件:ipvsadm-1.24、LVS.sh脚本
realserver.sh脚本
LVS服务器:
/opt/shell/LVS.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/bash
#
# LVS script for VS/DR
#
.
/etc/rc
.d
/init
.d
/functions
#
VIP=10.124.194.10
RIP1=10.124.194.242
RIP2=10.124.194.241
PORT1=80
PORT2=443
#
case
"$1"
in
start)
/sbin/ifconfig
eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route
add -host $VIP dev eth0:1
# Since this is the Director we must be able to forward packets
echo
1 >
/proc/sys/net/ipv4/ip_forward
# Clear all iptables rules.
/sbin/iptables
-F
# Reset iptables counters.
/sbin/iptables
-Z
# Clear all ipvsadm rules/services.
/sbin/ipvsadm
-C
# Add an IP virtual service for VIP 10.124.194.10 port 80
# In this recipe, we will use the round-robin scheduling method.
# In production, however, you should use a weighted, dynamic scheduling method.
/sbin/ipvsadm
-A -t $VIP:$PORT1 -s wlc
/sbin/ipvsadm
-A -t $VIP:$PORT2 -s wlc
# Now direct packets for this VIP to
# the real server IP (RIP) inside the cluster
/sbin/ipvsadm
-a -t $VIP:$PORT1 -r $RIP1 -g -w 1
/sbin/ipvsadm
-a -t $VIP:$PORT2 -r $RIP1 -g -w 1
/sbin/ipvsadm
-a -t $VIP:$PORT1 -r $RIP2 -g -w 2
/sbin/ipvsadm
-a -t $VIP:$PORT2 -r $RIP2 -g -w 2
/bin/touch
/var/lock/subsys/ipvsadm
&>
/dev/null
;;
stop)
# Stop forwarding packets
echo
0 >
/proc/sys/net/ipv4/ip_forward
# Reset ipvsadm
/sbin/ipvsadm
-C
# Bring down the VIP interface
/sbin/ifconfig
eth0:1 down
/sbin/route
del $VIP
/bin/rm
-f
/var/lock/subsys/ipvsadm
echo
"ipvs is stopped..."
;;
status)
if
[ ! -e
/var/lock/subsys/ipvsadm
];
then
echo
"ipvsadm is stopped ..."
else
echo
"ipvs is running ..."
ipvsadm -L -n
fi
;;
*)
echo
"Usage: $0 {start|stop|status}"
;;
esac
|
Realserver服务器端:
/etc/init.d/realserver.sh
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
|
#!/bin/bash
# description: Config realserver lo and apply noarp
SNS_VIP=10.124.194.10
#/etc/rc.d/init.d/functions
case
"$1"
in
start)
ifconfig
lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route
add -host $SNS_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
sysctl -p >
/dev/null
2>&1
echo
"RealServer Start OK"
;;
stop)
ifconfig
lo:0 down
route del $SNS_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
|
本文转自 南非波波 51CTO博客,原文链接:http://blog.51cto.com/nanfeibobo/1722170,如需转载请自行联系原作者