Configuring the DS
Procedure
- Configuring a virtual IP address for the DS.
1ifconfig lo:0 192.168.1.100 broadcast 192.168.1.100 netmask 255.255.255.255 up
- Configure kernel parameters and enable the DS forwarding function.
1echo "1" > /proc/sys/net/ipv4/ip_forward
- Add the IP address and port number of the LVS cluster to the DS and configure the scheduling algorithm.
1ipvsadm -A -t 192.168.1.100:80 -s rr
-A: adds a cluster service (virtual server).
-t: allows the cluster service to use TCP as the transmission protocol.
-s: specifies the scheduling algorithm used by the cluster service. It can be RR, WRR, LC, or WLC.
- Add LVS cluster hosts to the DS, that is, bind all RIP and RIP applications of the load to ports (in DR mode, the cluster ports must be the same as the RS ports), and set weights.
1ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.2:80 -g -w 1
1ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.3:80 -g -w 1
-a: adds a real server.
-t: allows the cluster service to use TCP as the transmission protocol.
-r: specifies the host IP address and port number of the real server.
-g: specifies the forwarding mode of the real server. The DR mode is used by default.
-w: specifies the weight of the real server.
- To disable the LVS function of the DS, run the following commands
1ipvsadm -C1ifconfig lo:0 down
-C: deletes all cluster services, including the forwarding rules of real servers.
Configuration Script Example
A script can be configured and executed in any directory on the server to perform the preceding steps. The following is an example of the script:
#!/bin/bash
#description:Start LVS of Director Server
if [ $# -eq 0 ];then
echo "usage: $0 start/stop"
exit 1
fi
cnt=5
port=10000;
RIPlist=('192.168.3.101' '192.168.3.102' '192.168.3.103' '192.168.3.104' '192.168.3.105')
net='255.255.255.255'
VIP=192.168.3.150
case $1 in
start)
echo "start LVS of Director Server"
#set virtual IP address and sysctl ip_forward
ifconfig lo:0 $VIP broadcast $VIP netmask $net up
echo "1" > /proc/sys/net/ipv4/ip_forward
#set LVS
#ipvsadm -A -t $VIP:$port -s rr -p
ipvsadm -A -t $VIP:$port -s rr
i=0
while(($i<$cnt))
do
ipvsadm -a -t $VIP:$port -r ${RIPlist[$i]}:$port -g
let "i++"
done
ipvsadm
;;
stop)
echo "stop LVS of ALL Director Server"
echo "0" > /proc/sys/net/ipv4/ip_forward
ipvsadm -C
ifconfig lo:0 down
;;
esac
Parent topic: Configuring LVS