Using LVS to build load-balanced Cluster service on Linux

Source: Internet
Author: User
Tags hash port number

I. The installation and configuration of LVS based on NAT

1. Hardware Requirements and network topology

2. Download software:

(1), Kernel source code: Need to download the 2.4.23 version of the kernel source code. The download address is http://www.kerner.org. The kernel source downloaded in this article is: linux-2.4.30.tar.bz2.

(2), User Configuration Tool ipvsadm, download address: http://www.linuxvirtualserver.org/software/ipvs.html. This article downloads is: http:// Www.linuxvirtualserver.org/software/kernel-2.4/ipvsadm-1.21-11.tar.gz

3. Install the Software:

On the Director (Controller, 202.99.59.110), install the core and configuration tools that support LVs Ipvsadm.

(1), the following options must be selected when the kernel is configured:

(2), compile and install the kernel

Execute separately: Make Bzimage;make modules;make modules_install, then edit the boot configuration file, reboot the system, and select the new kernel at startup.

To confirm that the kernel supports IPVS after the system starts, simply execute the following command: grep ip_vs_init/boot/system.map

(3), compile and install Ipvsadm

Ln-s/usr/src/linux-2.4.30/usr/src/linux TAR-ZXVF ipvsadm-1.21-11.tar.gz

CD ipvsadm-1.21-11

Make all

Make install

Then run: ipvsadm--version command, should have the following content output:

Ipvsadm v1.21 2004/02/23 (compiled with popt Ipvs)

4. Configure LVS

(1), on the 202.99.59.110:

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

echo "0" >/proc/sys/net/ipv4/conf/all/send_redirects

echo "0" >/proc/sys/net/ipv4/conf/default/send_redirects

echo "0" >/proc/sys/net/ipv4/conf/eth0/send_redirects

echo "0" >/proc/sys/net/ipv4/conf/eth1/send_redirects

Clear Ipvsadm Table:

/sbin/ipvsadm-c

Using Ipvsadm to install the LVS service

#add http to VIP with RR sheduling

/sbin/ipvsadm-a-T 202.99.59.110:80-s RR

Add the first realserver:

#forward http to Realserver 192.168.10.1 using Lvs-nat (-M), with Weight=1

/sbin/ipvsadm-a-T 202.99.59.110:80-r 192.168.10.1:80-m-W 1

Add Second Realserver:

#forward http to Realserver 192.168.10.2 using Lvs-nat (-M), with Weight=1

/sbin/ipvsadm-a-T 202.99.59.110:80-r 192.168.10.2:80-m-W 1

(2), realserver configuration

Set their gateways to 192.168.10.254, respectively, on 192.168.10.1 (Realserver1) and 192.168.10.2 (Realserver2), and start the Apache service separately.

When the client uses the browser multiple times to access: http://202.99.59.110/, and then run the Ipvsadm command on 202.99.59.110, there should be output similar to the following:

IP Virtual Server version 1.0.12 (size=4096) prot localaddress:port Scheduler Flags-> remoteaddress:port Forward Activeconn inactconntcp 202.99.59.110:http RR-> 192.168.10.1:http masq 1 0-> 192.168.10.2:http Masq 1 0 33

As can be seen from the above results, our LVS server has been successfully run.

[NextPage]

Ii. the configuration of LVS based on direct routing (DR)

1. Hardware Requirements and network topology:

2. Install the SOFTWARE:

Install the kernel and management software on director (202.99.59.109) by installing the above method.

3. Configure LVS

(1), on the 202.99.59.109:

Modify kernel run parameters, that is, modify the contents of the/etc/sysctl.conf file as follows: Net.ipv4.ip_forward = 0 Net.ipv4.conf.all.send_redirects = 1net.ipv4.conf.default.send_redirects = 1net.ipv4.conf.eth0.send_redirects = 1 and then execute the following command: The kernel-modified parameter takes effect immediately. Sysctl- P Configuration VIP Address:/sbin/ifconfig eth0:0 202.99.59.110 broadcast 202.99.59.110 netmask 255.255.255.255 up/sbin/route add-host 202.99.59.110 Dev eth0:0 Clear ipvsadm table:/sbin/ipvsadm-c use Ipvsadm to install the LVS service:/sbin/ipvsadm-a-T 192.168.1.110:http-s RR increase Realserver: #forward http to realserver using direct routing with weight 1/sbin/ipvsadm-a-T 192.168.1.110:http-r 192 .168.1.12-g-W 1/sbin/ipvsadm-a-T 192.168.1.110:http-r 192.168.1.12-g-W 1

(2) in Realserver1 (202.99.59.108) and Realserver2 (202.99.59.

107) To do the following settings.

Modify the kernel run parameters, that is, modify the contents of the/etc/sysctl.conf file as follows: Net.ipv4.ip_forward = 0net.ipv4.conf.lo.arp_ignore = 1net.ipv4.conf.lo.arp_ announce = 2net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce = 2 Then execute the following command, which is immediately valid for kernel-modified parameters: Sysctl- P Configuration VIP Address:/sbin/ifconfig lo:0 202.99.59.110 broadcast 202.99.59.110 netmask 255.255.255.255 up/sbin/route add-host 202.99.59.110 Dev lo:0

P> the client uses the browser multiple times to access: http://202.99.59.110/, and then run the Ipvsadm command on 202.99.59.110, there should be output similar to the following:

IP Virtual Server version 1.0.12 (size=4096) prot localaddress:port Scheduler Flags-> remoteaddress:port Forward Activeconn inactconntcp 192.168.100.254:http RR-> 192.168.100.3:http Route 1 0-> 192.168.100.2:http Route 1 0 29

As can be seen from the above results, our LVS server has been successfully run.

Several parameters used by Ipvsadm in the example of a plane are as follows:

-a adds a virtual service that consists of a protocol, an IP address, and a port number, for example:

-a-t 202.99.59.110:80 (Add a grid of virtual services whose protocol (-T indicates UDP for tcp,-u) is TCP, IP is 202.99.59.110, port number is 80.

-s Specifies the algorithm used by the service, the commonly used algorithm parameters are as follows:

RR Wheel Call (Round Robin)

The scheduler assigns external requests sequentially to the real servers in the cluster through a "wheel call" scheduling algorithm, which treats each server equally regardless of the actual number of connections and system load on the server.

WRR weighted wheel called (Weighted Round Robin)

The scheduler dispatches the access request according to the different processing ability of the real server through the "Weighted round call" scheduling algorithm. This ensures that the processing capacity of the server to handle more access traffic. The scheduler can automatically inquire about the load of the real server and adjust its weights dynamically.

LC Minimum Link (least connections)

The scheduler dynamically dispatches network requests to the server with the fewest number of links that have been established through the least-connection scheduling algorithm. If the real server of the cluster system has similar system performance, the "Minimal connection" scheduling algorithm can be used to balance the load well.

WLC weighted Minimum link (weighted least connections)

In the case of the server performance difference in the cluster system, the scheduler uses the "Weighted least link" scheduling algorithm to optimize the load balancing performance, and the server with higher weights will bear a large proportion of the active connection load. The scheduler can automatically inquire about the load of the real server and adjust its weights dynamically.

LBLC minimal links based on locality (locality-based least connections)

The "least local link" scheduling algorithm is based on the load balance of target IP address, and is mainly used in cache cluster system. The algorithm finds the most recently used server for the destination IP address based on the requested destination IP address. If the server is available and is not overloaded, send the request to the server, if the server does not exist, or if the server is overloaded and the server is half of the workload, select an available server with the "least link" principle , the request is sent to the server.

LBLCR-based least-localized links with replication (locality-based least connections with Replication)

The "Local least link" scheduling algorithm with replication is also a load balance for target IP address, which is mainly used in cache cluster system. It differs from the LBLC algorithm in that it maintains mappings from one destination IP address to a group of servers, while the LBLC algorithm maintains mappings from one destination IP address to a single server. The algorithm finds the corresponding server group for the target IP address according to the target IP address of the request. According to the "minimum connection" principle, select a server from the server group, if the server is not overloaded, send the request to the server, if the server overload; Select a server from this cluster by the "minimum Connection" principle, Add the server to the server group and send the request to the server. Also, when the server group has not been modified for some time, the busiest server is removed from the server group to reduce the degree of replication.

DH Target Address hash (destination hashing)

The destination hash scheduling algorithm finds the corresponding server from a statically allocated hash table as the hash key (hash key) according to the requested destination IP address, and if the server is available and not overloaded, sends the request to the server, or returns empty.

SH Source Address hash (source hashing)

The "Source address hash" Scheduling algorithm based on the requested source IP address, as the hash key (hash key) from the statically allocated hash table to find the corresponding server, if the server is available and not overloaded, send the request to the server, otherwise return empty.

/sbin/ipvsadm-a-T 192.168.1.110:http-r 192.168.1.12-g-W 1

-A represents adding a real server to a service

-r Specifies the IP address of real server

-W indicates weight

-G Indicates the use of DR,-M for Nat, and-I for tunneling mode.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.