Home > Backend Development > PHP Tutorial > lvs-dr experimental setup

lvs-dr experimental setup

WBOY
Release: 2016-07-28 08:28:13
Original
929 people have browsed it

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

  1. #!/bin/bash

  2. echo "1" > /proc/sys/ net/ipv4/ ip_forward

  3. IPVSADM='/sbin/ipvsadm'

  4. VIP=10.57.220 .144

  5. RS1 =10.57.220.20

  6. RS2=10.57.220.195



  7. ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up

  8. route add -host $VIP dev eth0:1



  9. $IPVSADM -C /*Clear virtual server information*/

  10. $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 */

  11. $IPVSADM -a- t $VIP:81 -r $RS1:81 -g -w 1 /*Add a physical machine to the virtual server*/

  12. $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

  1. #!/bin/bash

  2. #Description :RealServer

  3. #Write by :hugwww

  4. #Last Modefiy:2009.1.24

  5. VIP=10.57.220.144

  6. /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

  7. /sbin/route add -host $VIP dev lo:0

  8. 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*/

  9. 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*/

  10. echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

  11. echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

  12. sysctl -p

  13. #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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template