Centos Lvs server load balancer configuration

Source: Internet
Author: User
Tags centos


In this experiment, we used three virtual servers (centos5.5) under Vmware, one as the load scheduler (Lvs-server) and two real web servers (web1 and web2 ).

I. Lvs-nat experiment:

Configure the IP address:

1. Configure the Nic connected to the virtual machine in Windows 7 to 8.8.8.1, and configure the gateway.

2. Two NICS must be configured for the Lvs-server. One (eth0) is used to simulate an Internet connection (connected to Windows in this experiment), and the other (eth1) is used to communicate with the real server. Eth0: 8.8.8.8, eth1: 192.168.10.1

3. web1: eth0: 192.168.10.2

4. web2: eth0: 192.168.10.3

Configure web1. The default gateway address of web2 is Lvs-server eth0, indicating that the returned information is sent to the browser through Lvs-server.

Install Lvs software on Lvs-server, that is, ipvsadm.

Enable Lvs-server routing: echo 1>/proc/sys/net/ipv4/ip_forward (this step must be performed; otherwise, two NICs on Lvs-server cannot communicate with each other)

Then write the scheduling script lvsnat. sh,

#! /Bin/bash

# Lvsnat. sh

Ipvsadm-C (delete all previously added conversion tables)

Ipvsadm-A-t (tcp protocol) 8.8.8.8: 80-s rr (wheel call mode)

Ipvsadm-a-t 8.8.8.8: 80-r 192.168.10.2: 80-m)

Ipvsadm-a-t 8.8.8.8: 80-r 192.168.10.3: 80-m

Ipvsadm-L-n (print execution result)

Save and grant the execution right, and then execute.

Finally, enter 8.8.8.8 in the windows browser to access the webpage on the real server. (Note: You must disable the server firewall in the experiment, including iptables and selinux)

 

II. Lvs ip-tun:

The lab device is the same as before.


Configure the IP address:

1. Configure the Nic connected to the virtual machine in window7 to 200.168.10.4, and configure the gateway.

2. For Lvs-server, you only need to configure one Nic and tun (tunnel NIC ). Eth0: 200.168.10.1, tunl0: 200.168.10.10 netmask 255.255.255.255 (here, four 255 sets 200.168.10.10 to another CIDR block, which has only one Ip address)

3. web1: eth0: 200.168.10.2, tunl0: 200.168.10.10 netmask 255.255.255

4. web2: eth0: 200.168.10.3, tunl0: 200.168.10.10 netmask 255.255.255

Modify route table:

Lvs-server: route add-host 200.168.10.10 dev tunl0

Web1:

Route del default (delete the Gateway added in the previous experiment)

Route add-host 200.168.10.10 dev tunl0

Web2:

Route del default

Route add-host 200.168.10.10 dev tunl0

 

Lvs-server script:

#! /Bin/bash

#..


Ipvsadm-C (delete all previously added conversion tables)

Ipvsadm-A-t (tcp protocol) 200.168.10.10: 80-s rr (wheel call mode)

Ipvsadm-a-t 200.168.10.10: 80-r 200.168.10.2: 80: 80-I (the requests for access to 200.168.10.10: 80 are transferred to the server 200.168.10.2 in the call mode, -I indicates ip-tun mode)

Ipvsadm-a-t 200.168.10.10: 80-r 200.168.10.3: 80: 80-I

Ipvsadm-L-n (print execution result)


Execute scripts

 

Then write the actual server script:

#! /Bin/bash

#..

Echo "1">/proc/sys/net/ipv4/tunlo/arp_ignore

Echo "2">/proc/sys/net/ipv4/tunlo/arp_announce

Echo "1">/proc/sys/net/ipv4/all/arp_ignore


Echo "2">/proc/sys/net/ipv4/all/arp_announce

(Description: This parameter is ignored during external access to 200.168.10.10. When Lvs-server forwards the request, it responds and sends the mac address of 200.168.10.2 to the switch)

Execute scripts

Finally, enter 8.8.8.8 in the windows browser to access the webpage on the real server.

 

Lvs dr is similar to ip-tun, except that eth0: 0 is used in lvs-server to replace tunlo, and lo is used in web1 and web2 to replace tunlo. Other changes are not significant.

Let's take a look at a simple example: LVS load balancing

LvsIP: 118.126.3.42 LvsVIP: 118.126.3.77 Web: 1 118.126.3.47 Web2: 118.126.3.57


Basic configuration of LVS Server

[Root @ LVS ~] # Ifconfig seth0: 0 118.126.3.77 netmask 255.255.255.255.255 set the virtual ip address to zero.
[Root @ LVS ~] # Router add-host 118.126.3.77 dev seth0: 0 add this IP address to the route queue
[Root @ LVS ~] # Yum-y install ipvsadmin * control commands supported by lvs virtual service installation
[Root @ LVS ~] # Ipvsadm-At 118.126.3.77: 80-s rr save virtual server rules
[Root @ LVS ~] # Ipvsadm-at 118.126.7.77: 80-r 118.126.3.47: 80 access 7.77 will point to the 3.47 service
[Root @ LVS ~] # Ipvsadm-at 118.126.7.77: 80-r 118.126.3.57: 80 access 7.77 will point to the 3.57 service
 
Basic Web1 Server configuration

[Root @ WEB 1 ~] # Ifconfig lo: 0 118.126.3.77 network bandwidth 255.255.255 web1 server loopback interface
[Root @ WEB 1 ~] # Router add-host 118.126.3.77 dev lo: 0 add to IP route queue
[Root @ WEB 1 ~] # Echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
[Root @ WEB 1 ~] # Echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
[Root @ WEB 1 ~] # Echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
[Root @ WEB 1 ~] # Echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
 
 
Basic Web2 Server configuration

[Root @ WEB 2 ~] # Ifconfig lo: 0 118.126.3.77 network bandwidth 255.255.255 web1 server loopback interface
[Root @ WEB 2 ~] # Router add-host 118.126.3.77 dev lo: 0 add to IP route queue
[Root @ WEB 2 ~] # Echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
[Root @ WEB 2 ~] # Echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
[Root @ WEB 2 ~] # Echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
[Root @ WEB 2 ~] # Echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce

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.