LVS-TUN instance in VMlinux

Source: Internet
Author: User
DIP: IP address of the scheduler RIP: IP address of the real server in the background VIP: the TUN mode used for the virtual IPLVS provided by the Service is a compromise between its NAT and DR modes. Like the DR mode, the TUN mode is the same as the single Nic mode, its DIP and VIP can be in the same network segment as realserver

DIP: the IP address of the scheduler.

RIP: Real backend server (reaLsErver) IP Address

VIP: the virtual IP address provided by the Service.

 

LVS's TUN mode is a compromise between its NAT and DR modes. Like the DR mode, LVS adopts a single Nic mode. Its DIP and VIP can be in the same network segment as realserver, it may not be in the same CIDR block, but it is not modified on NAT or DR (or DR, but not here ), it is a brand new tunnel mode. Of course, in the scope of routing and switching, this tunnel mode is also a solution for coexistence of IPV4 and IPV6 versions. It is not used here, of course, the performance of TUN is also between NAT and DR.

 

The specific implementation process is as follows:

1. When the client sends a request message to the scheduler, the scheduler puts the packet on a "coat" (that is, the packet is placed in a specific tunnel) and encapsulates it into a new packet, based on a scheduling algorithm, the destination address is directed to a realserver in the new message, so that the packets are sent to the realserver and the connection is written to the cache.

2. The Realserver receives the packet and removes the "coat" to perform some processing as required. After the processing, it directly points the destination address of the reply packet to the client based on the VIP address bound to it, the source address is the VIP bound to the tunnel mode, so that a request and a reply are completed.

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

[Root @ localhost ~] #Ifconfig// View the original Nic Information

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: 20713 errors: 0 droppEd: 0 overruns: 0 frame: 0

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

ColLisions: 0 txqueuelen: 1000

RX bytes: 9157142 (8.7 MiB) TX bytes: 11059125 (10.5 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: 113 errors: 0 dropped: 0 overruns: 0 frame: 0

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

Collisions: 0 txqueuelen: 0

RX bytes: 10286 (10.0 KiB) TX bytes: 10286 (10.0 KiB)

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

#! /Bin/bash

# LVS script NAT

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 Tun"

/Sbin/ifconfig tunl0 $ VIP broadcast $ VIP netmask bandwidth limit 255 up

/Sbin/route add-host $ VIP dev tunl0

/Sbin/ipvsadm-C

#/Sbin/ipvsadm-A-t $ VIP: 21-s rr-p

#/Sbin/ipvsadm-a-t $ VIP: 21-r $ RIP1: 21-I

#/Sbin/ipvsadm-a-t $ VIP: 21-r $ RIP2: 21-I

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

/Sbin/ipvsadm-a-t $ VIP: 80-r $ RIP1? I // The TUN mode is displayed here.

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

/Sbin/ipvsadm

 

;;

Stop)

Echo "Stop LVS of DirectorServer Tun"

/Sbin/ifconfig tunl0 down

/Sbin/ipvsadm-C

;;

*)

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

ExIt 1

Esac

[Root @ localhost ~] #ChmodA + x/etc/init. d/lvstun

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

Start LVS of DirectorServer Tun

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 Tunnel 1 0 0

-> 192.168.1.193: http Tunnel 1 0 0

[Root @ localhost ~] # Ifconfig // view the nic ip Address binding information

Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: 09: 22: 5D

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.