Linux cluster -- simple LVS-DNAT and LVS-DR

Source: Internet
Author: User
LVS-DNAT Working principle: Before a packet enters the internal machine, it changes its destination address (which needs to be implemented in the kernel) LVS's working mechanism is similar to iptables, part of the work in the user space (ipvsadm ), part of the work in the kernel space to install ipvsadm software is enough to implement LVS functions using ipvsadm, early need to re-compile the kernel,

LVS-DNAT

Working principle:

Change the destination address of a data packet before it enters the kernel)

 

The working mechanism of LVS is similar to iptables. Some work in the user space (ipvsadm) and some work in the kernel space.

Installing ipvsadm is enough to implement LVS functions.

When using ipvsadm, the kernel needs to be re-compiled earlier, but the current version of REdBy default, Hat directly enters the kernel.

# Check whether the kernel contains ipvs

Grep? I? C 5 S/boot/config -'Uname-R'

IpvsadmCommandUsage:

Ipvsadm Function

1: DefinitionClusterService

2: Define real REALSERVER

3: view the defined information

1. Define cluster services

Ipvsadm

-T based on tCpCluster Service

-U based on udp

-F based on fireWallCluster service, firewall type

-A: Add A new cluster.

-E. modify a cluster.

-S: Specify the default wlc algorithm.

-D. delete a cluster.

-G | I | m gateway | internet | net DR | TUN | DNAT Model

-W weight

-C clear rules

-S: Save the rule to a file.

-R: Restore rules from a file

-L | l View

-N -- display address in numeric Mode

--StatS: displays statistics (abbreviated as statistics)

-- Rate: Display rate information

-Z: Clear the counter

Add/delete ctor end

Ipvsadm-A |-E-t |-u VIP: port-s

Ipvsadm-D-t |-u VIP: port

Add/delete reaLsErver end

Ipvsadm-a |-e-t |-u VIP: port-r REALSERVER [-g |-I |-m] [-w weight]

Ipvsadm-d-t |-u VIP: port-r READSERVER

Configure and install LVS

1. Install OS

2. install apache

3. Set the default route

4. Install lvs

5. Configure LVS and define rules

6. Test

 

1. Two apache servers serve as realserver and only provide static pages

2. Enable the forwarding function in Directory

3. The two realservers are in the same network segment

Preparation:

1) 3 clean VMS: RS1 RS2 ctor (a NIC is required)

2) configure the respective yum sources

I. Configure the address and install the software.

Realserver:

IfconfigEth0 10.0.0.11/8

RouteDdDefault gw 10.0.0.1/8

Yum installHttpd PhpPhp-mysql mysqlmysql-server php-mbsTrIng-y

# Test whether the webpage is displayed

Vim/var/www/html/indEx. Html

Realserver1

Service httpd start

Elinks http: // 10.0.0.11

 

Directory:

Ifconifg eth0 10.0.0.1/8

Yum install ipvsadm

 

 

# Enable ipforward

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

 

# Add director

Ipvsadm-A-t 172.16.14.1: 80-s rr

# View Cluster services

Ipvsadm-L-n

# Add realserver

Ipvsadm-a-t 172.16.14.1: 80-r 10.0.0.11-m

Ipvsadm-a-t 172.16.14.1: 80-r 10.0.0.12-m

Ipvsadm-L-n

 

The cluster has been built .... Test with a browser

 

# Stress testing, 10 concurrent connections, initiated 10000 times

AB-c 10-n 10000 http: // 172.16.14.1/index.html

# View results

Ipvsadm-Ln

# Use weighted least join

Ipvsadm-E-t 172.16.14.1: 80-s wlc

# Modifying Weights

Ipvsadm-e-t 172.16.14.1: 80-r 10.0.0.11-m-w 3

 

# Stress testing, 10 concurrent connections, initiated 10000 times

AB-c 10-n 10000 http: // 172.16.14.1/index.html

 

# Use another algorithm to test the effect.

Watch-n 1 'ingress SADM-L-N'

 

# Save the ipvsadm result. Otherwise, the system will not be started.

# For RedHat

Service ipvsadm save

ChkconfigIpvsadm on

# Or

Ipvsadm-S>/etc/sysconfig/ipvsadm

########## It is recommended that you write your own scripts to implement the save function. It is best to include startstop restart.


 


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.