I. Deployment environment:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/86/wKioL1Oz64aTB0YMAAHTDg8ffvg779.jpg "Title =" LVS-DR-1.png "alt =" wkiol1oz64atb0ymaahtdg8ffvg779.jpg "/>
Ii. Requirement analysis: the scheduling server and web server are both in the LAN environment of the same network segment. user-submitted requests are allocated by the scheduler and specified to the web server, at the same time, ensure the high availability of the service (after any website server goes down, the scheduler will remove it until the server returns to normal; after the master scheduler goes down, it takes over from the scheduler until it returns to normal .).
Iii. Related Configuration:
#!/bin/shmkdir toolscd tools/# yum install lrzsz# rz# lswget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz# ls -lrttar zxvf ipvsadm-1.24.tar.gz cd ipvsadm-1.24# ls# uname -rln -s /usr/src/kernels/2.6.32-431.17.1.el6.x86_64 /usr/src/linux# ll /usr/src/ |grep linux# lsmakemake installipvsadm# lsmod|grep ip_vs
#!/bin/sh# ipvs_ctlStart/Stop ipvsadm portmapper## chkconfig: 345 96 97## description: IPVSadm## processname: ipvs_ctl#create by stephen#2014-07-01VIP=(192.168.2.29# 192.168.2.28)RIP=(192.168.2.19192.168.2.20)GW=192.168.2.1. /etc/init.d/functionsstart(){for ((i=0;i<${#VIP[*]};i++))doifconfig eth1:$i ${VIP[$i]} broadcast ${VIP[$i]} netmask 255.255.255.255 up# ifconfig eth1:$iroute add -host ${VIP[$i]} dev eth1:$i# echo "1" >/proc/sys/net/ipv4/ip_forwardipvsadm -Cipvsadm -A -t ${VIP[$i]}:80 -s rr -p 600for ((j=0;j<${#RIP[*]};j++))doipvsadm -a -t ${VIP[$i]}:80 -r ${RIP[$j]}:80 -gdone# ipvsadmdone}stop(){for ((i=0;i<${#VIP[*]};i++))doifconfig eth1:$i down# route del -host ${VIP[$i]} dev eth1:$i# ipvsadm -Cipvsadm -D -t ${VIP[$i]}:80for ((j=0;j<${#RIP[*]};j++))doarping -c 1 -I eth1 -s ${VIP[$i]} $GW >/dev/null 2>&1donedone}case "$1" instart)action "ipvs started" /bin/truestart;;stop)action "ipvs stopped" /bin/truestop;;*)echo "Usage:$0 {start|stop}";;esac
#!/bin/sh# created by stephen#2014-07-01# description: config real server lo and apply non-arpVIP=(192.168.2.29# 192.168.2.28). /etc/init.d/functionsstart(){for ((i=0;i<${#VIP[*]};i++))doifconfig lo:$i ${VIP[$i]} broadcast ${VIP[$i]} netmask 255.255.255.255 upifconfig lo:$iroute add -host ${VIP[$i]} dev lo:$idoneecho "1" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "1" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" >/proc/sys/net/ipv4/conf/all/arp_announce}stop(){for ((i=0;i<${#VIP[*]};i++))doifconfig lo:$i downdoneif [ ${#VIP[*]} -le 1 ];thenecho "0" >/proc/sys/net/ipv4/conf/lo/arp_ignoreecho "0" >/proc/sys/net/ipv4/conf/lo/arp_announceecho "0" >/proc/sys/net/ipv4/conf/all/arp_ignoreecho "0" >/proc/sys/net/ipv4/conf/all/arp_announcefi}case "$1" instart)action "realserver vip is tied" /bin/truestart;;stop)action "realserver vip is canceled" /bin/truestop;;*)echo "Usage:$0 {start|stop}";;esac
#!/bin/sh#created by stephen#2014-07-02VIP=192.168.2.29PORT=80RIP=(192.168.2.19192.168.2.20)while truedofor ((i=0;i<${#RIP[*]};i++))doPORT_COUNT=`nmap ${RIP[$i]} -p $PORT|grep open|wc -l`if [ $PORT_COUNT -ne 1 ];thenif [ `ipvsadm -Ln|grep ${RIP[$i]}|wc -l` -ne 0 ];thenipvsadm -d -t $VIP:$PORT -r ${RIP[$i]}:$PORT >/dev/null 2>&1fielseif [ `ipvsadm -Ln|grep ${RIP[$i]}|wc -l` -eq 0 ];thenipvsadm -a -t $VIP:$PORT -r ${RIP[$i]}:$PORT -gfifidonesleep 10done
#!/bin/sh#created by stephen#2014-07-02DIP=192.168.2.21VIP=192.168.2.29PORT=22while truedoPORT_COUNT=`nmap $DIP -p $PORT|grep open|wc -l`if [ $PORT_COUNT -ne 1 ];thenif [ `ipvsadm -Ln|grep $VIP|wc -l` -eq 0 ];then/etc/init.d/ipvs_ctl startfielseif [ `ipvsadm -Ln|grep $VIP|wc -l` -eq 1 ];then/etc/init.d/ipvs_ctl stopfifisleep 5done
1. enable port 80:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT/etc/init.d/iptables save/etc/init.d/iptables restart
2. After the scheduler is configured, modify its execution permissions and add the configuration file to the auto-start item:
cp ipvs_ctl /etc/init.d/ipvs_ctlchmod 700 /etc/init.d/ipvs_ctlchkconfig --add ipvs_ctlchkconfig --list|grep ipvs
3. Because we can detect the server port by checking the server port enabling status, we will use NMAP here:
yum install nmap -y
4. Modify the scheduler's High Availability Configuration File Execution permission, and execute it in the background, and view and cancel the background process command:
chmod 700 check_lb.sh sh check_lb.sh &watch ipvsadm -Ln --statsjobsfg
5. Use tcpdump to capture packets and Analyze network traffic:
tcpdump -i eth1 tcp port 80 -s 1500
This article is from the "little devil's territory" blog, please be sure to keep this source http://zhoufwind.blog.51cto.com/1029821/1433684