How LVS solves server load Balancing

Source: Internet
Author: User
Tags join tomcat linux

LVS is a short version of Linux virtual Server, which means the Linux VM, is a virtual server cluster system. This project was established by Dr. Zhangwensong in May 1998 and is one of the earliest free software projects in China. There are currently three IP load Balancing technologies (Vs/nat, Vs/tun and VS/DR);

10 Kinds of scheduling algorithms (RRR|WRR|LC|WLC|LBLC|LBLCR|DH|SH|SED|NQ).

Official website: http://www.linuxvirtualserver.org/

This trial uses your own small Ben, on the small Ben installed 3 Redhat as 5 through VMware as the test environment. One is a virtual host, the other two are realserver.

1. Basic Environment setting

After installing 3 virtual machines on VMware, set the network type to NAT.

Gateway: 192.168.91.2

(via Wmare--> Edit-> Virtual network Editor, select VMnet8, set to static IP)

dns:192.168.91.2

Configure each IP to:

192.168.91.10 (LVS Host)

192.168.91.11 (real Server 1)

192.168.91.12 (Real Server 2)

2. Download and install LVs

# uname-r    
2.6.18-8.el5    
# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz    
# ln-s/usr/src/kernels/2.6.18-53.el5pae-i686/  /usr/src/linux    
# TAR-XZVF ipvsadm-1.24.tar.gz    
# CD ipvsadm-1.24
# make    
# make install    
# CP ipvsadm/sbin/

3. Configure virtual IP services and load Balancing

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/zs/

To 192.168.91.10 (LVS host) as a LVS host, for the host network card configuration of dual IP, one of the virtual IP as LVS virtual IP.

192.168.91.9 is configured as a virtual IP for the LVS host.

LVS Server Configuration

Executing on a 192.168.91.10LVS virtual server:

# Set native default IP, if already set, can not perform

Ifconfig eth0 192.168.91.10 netmask 255.255.255.0 broadcast up

# set up the local second IP, as the virtual IP LVS

Ifconfig eth0:0 192.168.91.9 netmask 255.255.255.0 broadcast 192.168.91.255 up

# Open IP Forwarding switch

Echo 1 >/proc/sys/net/ipv4/ip_forward

# Add virtual server, virtual IP is 192.168.91.9, Port is 80, the scheduling algorithm is: RR

Ipvsadm-a-T 192.168.91.9:80-s RR

# for Virtual Server 192.168.91.9, add Realserver,ip to 192.168.91.11, specify LVS working mode as direct routing mode

Ipvsadm-a-T 192.168.91.9:80-r 192.168.91.11-g

# for Virtual Server 192.168.91.9, add Realserver,ip to 192.168.91.11, specify LVS working mode as direct routing mode

Ipvsadm-a-T 192.168.91.9:80-r 192.168.91.12-g

# Start LVS

Ipvsadm

IP Virtual Server version 1.2.1 (size=4096)

Prot Localaddress:port Scheduler Flags

-> remoteaddress:port Forward Weight activeconn inactconn

TCP 192.168.91.9:http RR

-> 192.168.91.12:http Route 1 0 0

-> 192.168.91.11:http Route 1 0 0

LVS Real Server Configuration

Execute on 192.168.91.11 and 192.168.91.12

# Set Real Server virtual IP routing

Ifconfig lo:0 192.168.91.9 netmask 255.255.255.0 broadcast 192.168.91.255 up

Route add-host 192.168.91.9 Dev lo:0

Install Tomcat on 4.Real server

Install Tomcat on two realserver respectively

192.168.91.11

192.168.91.12

Save, before starting, change the port to port 80.

6. View the LVS status

Run query commands on the 192.168.91.10/9 virtual server

[Root@hadoop00 ~]# ipvsadm-l--stats

IP Virtual Server version 1.2.1 (size=4096)

Prot localaddress:port Conns inpkts outpkts inbytes

-> Remoteaddress:port

TCP 192.168.91.9:http 0 0 0 0 0

-> 192.168.91.12:http 0 0 0 0 0

-> 192.168.91.11:http 0 0 0 0 0

7. Test complete

# Stop LVS

Ifconfig eth0:0 Down

/sbin/ipvsadm-c

# Stop Real Server

/sbin/ifconfig lo:0 Down

The formal application can turn the LVS virtual service to start and stop writing for the footsteps, join the/etc/init.d/, join the service, set to start automatically.

Original: http://acooly.iteye.com/blog/1151921

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.