Instance resolution: Server Load balancer experiment of Lvs in virtual machines

Source: Internet
Author: User
Article Title: instance resolution: Lvs Server Load balancer experiment in a virtual machine. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Environment, three virtual machine systems, debian, centos, and rhel. SLB Based on ipvsadm adopts the DR mode. rhel is the lctor ctor of lvs, and the other two are real. The server Load balancer service is web.

The implementation is as follows:

Required Software: OS (nonsense), ipvsadm, and related library files (by default)

Ipvsadm: the source code package is used for the download of ipvsadm.

Installation tips:

1. ipvsadm requires OS kernel source path support. download the latest kernel from www.kernel.org, put it in/usr/src, and decompress it.

The general decompress is the linux-2.6.x directory, the use of command # ln-s linux-2.6.x linux this has generated the/usr/src/linux, which is the default compiler of ipvsadm contains the file path, otherwise, an error is reported! Remember.

2. The director server must enable the ip_forward function,

Add net. ipv4.ip _ forward = 1 to/etc/sysctl. conf.

Script echo "net. ipv4.ip _ forward = 1">/etc/sysctl. conf

You need to configure a virtual ip address. The NIC is eth0: 192.168.1.154, And the vip is eth0: 0192.168.1.2.

Script ifconfig eth0 192.168.1.154 broadcast 192.168.1.255 netmask 255.255.255.0

Ifconfig eth0: 0 192.168.1.2 broadcast 192.168.1.255 netmask 255.255.255.0

Routing needs to be set

Script route add-host 192.168.1.2 dev eth0: 0

Ipvsadm setting script:

Ipvsadm? C

Ipvsadm-A-t 192.168.1.2: 80-s wcl

Ipvsadm-a-t 192.168.1.2: 80-r 192.168.1.138-g-w 3

Ipvsadm-a-t 192.168.1.2: 80-r 192.168.1.156-g-w 1

Ipvsadm

You can add the preceding script to/etc/rc. local and run it automatically upon startup.

3. The real machine must disable arp; otherwise, packets cannot be received.

Add the following lines to the/etc/sysctl. conf file:

Net. ipv4.ip _ forward = 1

Net. ipv4.conf. lo. arp_ignore = 1

Net. ipv4.conf. lo. arp_announce = 2

Net. ipv4.conf. all. arp_ignore = 1

Net. ipv4.conf. all. arp_announce = 2

4. The script for setting local virtual addresses for real machines is as follows:

Ifconfig lo: 0 192.168.1.2 broadcast 192.168.1.2 netmask 255.255.255.255

For linux machines, directly create the file etc/sysconfig/network-scripts/ifcfg-lo: 0,

Write script

DEVICE = lo: 0

IPADDR = 192.168.1.2

NETMASK = 255.255.255.255.255

ONBOOT = yes;

5. Install the apache service on the real Server.

6. It is recommended that you do not install a firewall on The lvs server. Even if the firewall is installed, you should set up rules as needed. Otherwise, the firewall will not take effect. In this example, port 80 must be enabled.

After the installation and configuration are complete, the configuration takes effect.

To facilitate the test, I used the links tool in linux to perform the test. After Repeated execution, I saw that the web pages were repeatedly displayed between two apache servers.

Software usage summary:

OS kernel:

Debian: Linux debian CPU 2.6.18-4-686 #1 SMP Wed May 9 23:03:12 UTC 2007 i686 GNU/Linux

Centos: Linux localhost. localdomain 2.6.18-8.1.4.el5xen #1 SMP Thu May 17 05:27:09 EDT 2007 i686 i686 i386 GNU/Linux

Rhel: Linux localhost. localdomain 2.6.18-8. el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux

Applications:

Ipvsadm-1.24

Apache2

Iptables1.4.1

Related Article

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.