lvs-dr experimental setup 2012-04-19
18:00:59
Category: LINUX
Environment:
lvs director: 10.57.220.198:80 Ubuntu 10.04 LTS vmware virtual machine
real server1 10.57.220.195: 80 Ubuntu 11.10 nginx server
real server2 10.57. 220.20:80 Ubuntu 11.10 nginx server
Virtual ip (vip): 10.57.220.144
1. Download ipvsadm
Download on 3 machines respectively
apt-get install ipvsadm
2. ipvsadm settings
dpkg-reconfigure ipvsadm
The first one Choose no (automatically load ipvs rules on boot?)
The second choice is none
3. Configuration script
1) director script
lvs-dr.sh
Click (here) to collapse or open
- #!/bin/bash
- echo "1" > /proc/sys/ net/ipv4/ ip_forward
- IPVSADM='/sbin/ipvsadm'
- VIP=10.57.220 .144
- RS1 =10.57.220.20
- RS2=10.57.220.195
- ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255
up
- route add -host $VIP dev eth0:1
- $IPVSADM -C /*Clear virtual server information*/
-
- $IPVSADM -A -t $VIP:81 -s rr
/*Create a virtual server record, the scheduling algorithm is rr. See http://www.it165.net/admin/html/201401/2248.html */
- $IPVSADM -a- t $VIP:81 -r
$RS1:81 -g -w
1 /*Add a physical machine to the virtual server*/
- $IPVSADM -a-t $VIP:81 -r
$RS2:81 -g -w
1 /*Add a physical machine to the virtual server*/
chmod 777 lvs-dr.sh
2) realserver script
The same for all realservers
lvs-rs.sh
Click (here) to collapse or open
- #!/bin/bash
- #Description :RealServer
- #Write by :hugwww
- #Last Modefiy:2009.1.24
- VIP=10.57.220.144
-
-
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255
up
-
/sbin/route add -host $VIP dev lo:0
- echo "1"> /proc/ sys/net/ipv4/conf/lo/arp_ignore
/*Only answer ARP query requests whose target IP address is the local address of the visiting network interface*/
- echo "2">/proc/sys/net /ipv4/conf/lo/arp_announce
/*Use the most appropriate local address for the query target. In this mode the source address of this IP packet will be ignored and an attempt will be made to select a local address that can communicate with that address. The first priority is to select all network interfaces in the subnet The local address of the target IP address in the outbound access subnet. If no suitable address is found, the current sending network interface or other network interfaces that are likely to receive the ARP response will be selected for sending*/
- echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
- echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
- sysctl -p
- #end
chmod 777 lvs-rs.sh
4. Execution and testing
Execute the corresponding scripts on three machines respectively
Pay attention to starting them in advance. nginx server
firfox access 10.57.220.144:81
You can use ipvsadm -ln to check the status
5. Pay attention to the problem
The firewall should be turned off, under Linux it is iptables
The ports of each server are consistent, otherwise it will not work. For example, they are all port 80, some cannot be port 80, and some can be port 81.
In this case, the VIP and the real IP are in the same network segment. The VIP and the real IP can be in different network segments. Please refer to Dr. Zhang’s answer http://zh.linuxvirtualserver.org/node/155. The load scheduler only needs to have a network port and be connected to the real server through an unsegmented network. The real server can send the response message to the client through its own router.
For the scheduling algorithm, see: http://zh.linuxvirtualserver.org/node/2903
Architecture reference http://zh.linuxvirtualserver.org/node/28
The above has introduced the experimental setup of lvs-dr, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.