LVS-DR instance in VMlinux

Source: Internet
Author: User
DIP: the IP address RIP of the Scheduler: the IP address VIP of the real server in the background: The DR mode of the virtual IPLVS used for the service is more complex than the NAT mode, and it is not easy to implement, this mode is closer to hardware-based load balancing. Although the performance is inferior to that of hardware-based load balancing scheduling

 

DIP: the IP address of the scheduler.

RIP: Real backend server (reaLsErver) IP Address

VIP: the virtual IP address provided by the Service.

 

The DR mode of LVS is more complex than the NAT mode, and is not easy to implement, because this mode is closer to the hardware-basedServer Load balancerAlthough there is still a gap between the performance and the hardware Load Balancing scheduling, the performance has greatly improved with the NAT and TUN modes, it requires that the scheduler and realserver be in the same network segment (you can use a vswitch to connect to the server, or you can also use an IP-based network connection). Here, the Scheduler only uses one Nic, whether DIP is equal to VIP is acceptable. The biggest advantage of DT mode is that it greatly improves the service quality. At the same time, it is necessary to set some restrictions on ARP on realserver.

 

The specific implementation process is as follows:

1. When the client sends a request message to the scheduler, the scheduler does not perform in-depth processing when it receives the packet. It only modifies the target MAC address to the MAC address of a real server in the realserver pool according to the algorithm, cache a connection record at the same time (ensure that all the packets for this connection are uploaded to the same realserver)

2. The Realserver receives the packet and performs relevant processing as required. After the processing is completed, it will rewrite the source and target addresses of the packet based on the VIP address bound to its Nic and directly reply the packet to the client, instead of passing through the scheduler, the scheduler's burden is reduced objectively.

Linux server hosts under three VMS on the experimental platform (CentOS 5.5 and kernel version 2.6 support LVS by default, so you can directly use it without re-compiling the kernel ), one is used as the scheduler, and the other two are used as the realserver.

 

1. settings on the Scheduler:

[Root @ localhost ~] # Yum-y install ipvsadm // install LVS management tool

[Root @ localhost ~] #Ifconfig// View the initial Nic information (only one Nic is used here)

Eth0 Link eNcAp: Ethernet HWaDdR 00: 0C: 29: 09: 22: 5D

Inet addr: 192.168.1.196 Bcast: 192.168.1.255 Mask: 255.255.255.0

Inet6 addr: fe80: 20c: 29ff: fe09: 225d/64 Scope: Link

Up broadcast running multicast mtu: 1500 MeTrIc: 1

RX packets: 17657 errors: 0 droppEd: 0 overruns: 0 frame: 0

TX packets: 17945 errors: 0 dropped: 0 overruns: 0 carrier: 0

ColLisions: 0 txqueuelen: 1000

RX bytes: 7404853 (7.0 MiB) TX bytes: 10817894 (10.3 MiB)

Interrupt: 169 Base address: 0x2000

Lo Link encap: Local Loopback

Inet addr: 127.0.0.1 Mask: 255.0.0.0

Inet6 addr: 1/128 Scope: Host

Up loopback running mtu: 16436 Metric: 1

RX packets: 88 errors: 0 dropped: 0 overruns: 0 frame: 0

TX packets: 88 errors: 0 dropped: 0 overruns: 0 carrier: 0

Collisions: 0 txqueuelen: 0

RX bytes: 6797 (6.6 KiB) TX bytes: 6797 (6.6 KiB)

[Root @ localhost ~] # Vi/etc/init. d/lvsdr // writeClusterYou can also add scripts one by one.

#! /Bin/bash

# Description: start LVS of Directorserver DR

VIP = 192.168.1.200

RIP1 = 192.168.1.193

RIP2 = 192.168.1.195

#./Etc/rc. d/init. d/functions

Case "$1" in

Start)

Echo "start LVS of DirectorServer DR"

/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up

/Sbin/route add-host $ VIP dev eth0: 0

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

/Sbin/ipvadm-C

/Sbin/ipvsadm-A-t $ VIP: 80-s rr // still A round Algorithm

/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP1? G //-g indicates that the direct routing mode is used.

/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP2-g

/Sbin/ipvsadm

;;

Stop)

Echo "stop LVS of DirectorServer DR"

Echo "0">/proc/sys/net/ipv4/ip_forward

/Sbin/ipvsadm-C

/Sbin/ifconfig eth0: 0 down

;;

*)

Echo "Usage: $0 {start | stop }"

ExIt 1

Esac

[Root @ localhost ~] #ChmodA + x/etc/init. d/lvsndr // Add executable permission

[Root @ localhost ~] #/Etc/init. d/lvsdr start

Start LVS of DirectorServer DR

/Etc/init. d/lvsdr: line 13:/sbin/ipvadm: NoSuChFileOr directory

IP Virtual Server version 1.2.1 (size = 4096)

Prot LocalAddress: Port ScheDuLer Flags

-> RemoteAddress: Port Forward Weight ActiveConn InActConn

TCP 192.168.1.200: http rr

-> 192.168.1.195: http Route 1 0 0

-> 192.168.1.193: http

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.