Directory
Preface... 1
1. LVS environment networking... 2
2. Prepare ipvsadm before installation... 2
3. Download httpd and ipvsadm... 3
4. LVS Server Load balancer configuration... 4
5. Real WEB server configuration and arp suppression... 5
6. LVS load balancing test... 6
7. Appendix: arp suppression parameters... 7
Preface
This article mainly describes the centos5.x lvs dr mode, Environment setup, and theoretical knowledge, please refer to the LVS Chinese official website
Http://www.linuxvirtualserver.org/zh/index.html
The page may show garbled, if there is garbled, right-click on IE to hook up the status bar, then select encoding in the drop-down options in the page bar, there (GB2312 and UTF-8), if the UTF-8 shows garbled, select GB2312. If garbled characters are displayed on GB2312, select the UTF-8.
1. LVS environment networking
Because the VM environment is used, the PC is used as the client (that is, the public network address), The scheduler and the server are both VMS in the VM, so the customer and all servers are physically and directly connected to the network, the logical topology is as follows:
2. Prepare ipvsadm before installation
External IP Address
Internal IP Address
Role
10.0.0.30/24
192.168.1.1/24
LVS scheduler (Virtual Machine)
10.0.0.237/24
192.168.1.2/24
RS1 (Virtual Machine)
10.0.0.238/24
192.168.1.3/24
RS2 (Virtual Machine)
10.0.0.130/24
None
Client (PC)
Note: In actual applications, RS1 RS2 does not have an external address. In the current environment, there is no physical dual-nic environment. Multiple IP addresses are configured for one Nic.
3. Download httpd and ipvsadm
1) modify the host name on each server:
[Root @ LVS1 ~] # Hostname LVS1
[Root @ RS1 ~] # Hostname RS1
[Root @ RS2 ~] # Hostname RS2
2) install the httpd service on RS1 RS2
[Root @ RS2 ~] # Yum installhttpd-y
[Root @ RS2 ~] #/Etc/init. d/httpd start
[Root @ RS2 ~ # Ps-ef | grephttpd
[Root @ RS1 ~] # Yum installhttpd-y
[Root @ RS1 ~] #/Etc/init. d/httpdstart
[Root @ RS1 ~ # Ps-ef | grephttpd <= check whether the httpd service is enabled
[Root @ RS1 ~] # Cat/etc/httpd/conf/httpd. conf | grep DocumentRoot <= find the directory path of the system site
# DocumentRoot: The directoryout of which you will serve your
DocumentRoot "/var/www/html"
# This shoshould be changed towhatever you set DocumentRoot.
# DocumentRoot/www/docs/dummy-host.example.com
[Root @ RS1 ~] # Echo "RS1">/var/www/html/index.html
[Root @ RS2 src] # echo "RS2">/var/www/html/index.html
Httpd service test:
Test successful!
3) download ipvsadm
Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
Wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
Download directory of my source package/usr/local/src
My LVS environment:
[Root @ RS1 src] # cat/etc/redhat-release
CentOS release 5.8 (Final)
[Root @ RS1 src] # uname-rm
2.6.18-308. el5 x86_64
The ipvsadm-1.26 has requirements on the kernel and requires kernel versions 2.6.28 and later. If it meets the system environment, install the dependency package yum install libnl * popt *-y.
My kernel version does not meet, using ipvsadm-1.24.
[Root @ LVS1 src] # tar -zxf1_sadm-1.24.tar.gz
[Root @ LVS1 src] # ln-s/usr/src/kernels/2.6.18-348.12.1.el5-x86_64/usr/src/linux <= the compiling path is/usr/ src/linux, it can be viewed in Makefile. If no link is left, compilation will fail.
[Root @ LVS1 src] # ll/usr/src/
Total 16
Drwxr-xr-x 2 root 4096 May11 2011 debug
Drwxr-xr-x 3 root 4096Aug 5 3:53 kernels
Lrwxrwxrwx1 root 43 Aug 5 linux->/usr/src/kernels/2.6.18-348.12.1.el5-x86_64 <= use ll/usr/src/to view, if a soft link flash, the link fails.
[Root @ LVS1 src] # cd ipvsadm-1.24
[Root @ LVS1 ipvsadm-1.24] # make & make install <= If the compilation fails, follow the steps above to troubleshoot the problem step by step.
[Root @ LVS1 ipvsadm-1.24] # lsmod | grepip_vs <= check whether the kernel module has ipvsadm
[Root @ LVS1 ipvsadm-1.24] # ipvsadm
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: portsched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
# There is also a method for loading ipvsadm, using modprobe ip_vs
[Root @ LVS1 ipvsadm-1.24] # lsmod | grepip_vs <= view the kernel module, which indicates that ipvsadm is loaded into the kernel. At this time, LVS has been installed.
Ip_vs 122113 0
4. LVS Server Load balancer Configuration
1) Configure VIP and DIP
For IP configuration, refer to step 2 for installation preparation.
[Root @ LVS1 ~] # Ifconfig eth010.0.0.30 netmask 255.255.255.0 # VIP
[Root @ LVS1 ~] # Ifconfigeth0: 1 192.168.1.1 netmask 255.255.255.0 # DIP
2) add real servers
[Root @ LVS1 ~] # Define SADM-C <= manually clear the original table content
[Root @ LVS1 ~] # Ipvsadm -- set30 5 60 <= set the connection timeout value
[Root @ LVS1 ~] # Ipvsadm-A-t10.0.0.30: 80-s wrr-p 20 <=-A add address,-t specify the vip tcp port,-s specify the scheduling algorithm-p session persistence time
[Root @ LVS1 ~] # Ipvsadm-L-n <= View table content, added a set of VIP addresses and ports
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: portsched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 10.0.0.30: 80 wrr persistent 20
[Root @ LVS1 ~] # Ipvsadm-a-t10.0.0.30: 80-r 192.168.1.2: 80-g-w 1 <=-a specifies the Real Server, VIP on-t lvs, -r: Real Server ip address and port,-w weight,-g: Select DR mode (-m is NAT Mode)
[Root @ LVS1 ~] # Ipvsadm-a-t10.0.0.30: 80-r 192.168.1.3: 80-g-w 1
[Root @ LVS1 ~] # Ipvsadm-L-n <= View table content and add two real servers for load forwarding
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: portsched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 10.0.0.30: 80 wrr persistent 20
-> 192.168.1.2: 80 Route 1 0 0
-> 192.168.1.3: 80 Route 1 0 0
If an error occurs when adding A server address, run the following command to delete the server address: Change "a" to "D" to "d", and change "A" to "D" to "delete ".
Ipvsadm-D-t10.0.0.30: 80-s wrr
Ipvsadm-d-t10.0.0.30: 80-r 192.168.1.2: 80
5. Real WEB server configuration and arp Suppression
[Root @ RS1 ~] # Ifconfig eth0 | grep "inet addr" <= This address is used to log on to the device using the CRT software on your computer and send arp requests to the client MAC (because the client directly returns the page to the client, the current network is the same physical network segment and must be the same network segment ).
Inet addr: 10.0.0.237 Bcast: 10.0.0.255 Mask: 255.255.255.0
[Root @ RS1 ~] # Ifconfig eth0: 1194251.2 netmask 255.255.255.0 <= configure the internal IP address
[Root @ RS1 ~] # Ifconfig lo10.0.0.30 netmask 255.255.255.255 <= VIP must be configured for each Real Server
Why is VIP bound? Because the principle of DR mode is that The LVS scheduler modifies the mac address to the actual server address, the destination IP address or VIP address of the message is not modified ,, the NIC only sends messages of the destination MAC address and destination IP address to the CPU. Therefore, VIP must be configured on the Real Server!
Why is lo port used? Because the lo port is a local loopback port, it prevents IP address conflicts on the local Lan!
[Root @ RS2 src] # ifconfigeth0 | grep "inet addr" <= This address is used to log on to the device using CRT software on your computer, it is also used to send arp requests to the client MAC (because the client directly returns the page, and the current network is the same physical network segment, it must be the same network segment ).
Inet addr: 10.0.0.238 Bcast: 10.0.0.255 Mask: 255.255.255.0
[Root @ RS2 src] # ifconfig eth0: 11920.1.3 netmask 255.255.255.255.0 <= configure the internal IP address
[Root @ RS2 src] # ifconfig lo10.0.0.30 netmask 255.255.255.255
The configuration is complete, but a problem occurs during the test. When you log on to the 10.0.0.30 address in the CRT again, log on to RS1, refresh, and log on to rs2. How can this problem be solved?
Through analysis, it is concluded that when accessing 10.0.0.30, the mac address of the arp request 10.0.0.30 will be sent, and there are 3 10.0.0.30 addresses in this network. At this time, who will send the arp request to the client, who is the access. If the arp response of RS1 is sent first, RS1 is accessed.
Solution:
ARP response suppression
This suppression is only configured on the Real Server.
[Root @ RS1 ~] # Echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
[Root @ RS1 ~] # Echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
[Root @ RS1 ~] # Echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
[Root @ RS1 ~] # Echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
[Root @ RS2 src] # echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
[Root @ RS2 src] # echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
[Root @ RS2 src] # echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
[Root @ RS2 src] # echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
1 2 indicates what the content is. You can view it in the last appendix or search for it on your own.
6. LVS load balancing test
The displayed value is RS1, And the link is allocated to 192.168.1.2.
We use the wrr Scheduling Algorithm. In this algorithm, who has a high weight will give priority
View the configuration and find that the weight is the same
[Root @ LVS1 ~] # Ipvsadm-L-n
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: portsched1_flags
-> RemoteAddress: Port ForwardWeight ActiveConn InActConn
TCP 10.0.0.30: 80 wrr persistent 20
-> 192.168.1.2: 80 Route 1 0 0
-> 192.168.1.3: 80 Route 1 0 0
Since the session persistence function is available, the weight value is modified later.
[Root @ LVS1 ~] # Ipvsadm-d-t10.0.0.30: 80-r 192.168.1.3: 80 <= Delete the original configuration
[Root @ LVS1 ~] # Ipvsadm-a-t10.0.0.30: 80-r 192.168.1.3: 80-g-w 2 <= reconfigure the weight to 2
[Root @ LVS1 ~] # Ipvsadm-L-n
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: portsched1_flags
-> RemoteAddress: Port ForwardWeight ActiveConn InActConn
TCP 10.0.0.30: 80 wrr persistent 20
-> 192.168.1.3: 80 Route 2 0 0
-> 192.168.1.2: 80 Route 1 0 0
Test again:
7. Appendix: arp suppression Parameters
Arp response restrictions
1) arp_ignore:
Define ARP queries with the target IP address as the local IP address in different response modes 0
0-(default): responds to arp query requests from any network interface to any local IP address.
1-only answers ARP query requests whose target IP address is the local address of the Access Network Interface
2-only answers ARP query requests whose target IP address is the local address of the access network interface. The access IP address must be in the subnet segment of the network interface.
3-do not return arp requests in the network, but only respond to the set unique and connection address
4-7-reserved unused
8-does not respond to arp queries for all (local addresses)
2) arp_announce:
ARP responds to the issue of local IP addresses on the network interface, and limits the corresponding level: determine the limits to different degrees, and announce the interface for sending Arp requests to local IP addresses.
0-(default) any local address on any network interface (eth0, eth1, lo)
1-avoid arp responses from local addresses that are not in the subnet segment of the network interface. it is useful when the source IP address that initiates an ARP request is set to reach this network interface through a route. check whether the access IP address is one of the ip addresses in the subnet segment of all interfaces. if the access IP address does not belong to the subnet segment of each network interface, level 2 is used for processing.
2-use the most appropriate local address for the query target. in this mode, the source address of the IP packet is ignored and the local address that can communicate with the IP packet is selected. first, select the local address of the destination IP address in the out-of-the-box access subnet of all network interfaces. if no suitable address is found, the current sending network interface or other network interfaces that may receive the ARP response will be selected for sending.
This article from the "this is my hometown" blog, please be sure to keep this source http://yangrong.blog.51cto.com/6945369/1287534