Original: implementation of LVS-based Linux server load balancer technology

Source: Internet
Author: User
Article Title: Original: Linux server load balancer technology based on LVS. 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.

Implementation of LVS-based Linux server load balancer technology-basic NAT and dr lvs cluster construction

This is the first actual LVS configuration example. The entire structure is based on NAT operations. In this example, the structure is relatively simple:

LVS3.PNG (7.39 KB)
?

In the above example, I have not added a backup LVS Router for the moment. Instead, I only use a master LVS Router to act as the scheduler.
The configuration steps are as follows:
First, configure the network parameters:
Basic parameters on LVS Router:
[Root @ localhost ~] # Ifconfig | grep inet
? ?? ?? ? Inet addr: 192.168.1.10 ?? Bcast: 192.168.1.255 ?? Mask: 255.255.255.0
? ?? ?? ? Inet6 addr: fe80: 20c: 29ff: fe08: a162/64 Scope: Link
? ?? ?? ? Inet addr: 10.0.0.10 ?? Bcast: 10.0.0000255 ?? Mask: 255.255.0.0
? ?? ?? ? Inet6 addr: fe80: 20c: 29ff: fe08: a16c/64 Scope: Link
[Root @ localhost ~] # Sysctl-a | grep ip_forward
Net. ipv4.ip _ forward = 1
[Root @ localhost ~] # Sysctl? P

Basic parameters on Real Server:
First:
[Root @ localhost ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
HWADDR = 00: 0c: 29: b2: 60: a5
IPADDR = 10.0.0.100
NETMASK = 255.255.0.0
GATEWAY = 10.0.0.254
Second:
[Root @ localhost ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
HWADDR = 00: 0c: 29: b2: 60: a5
IPADDR = 10.0.0.200
NETMASK = 255.255.0.0
GATEWAY = 10.0.0.254

Then install the piranha tool on the LVS Router:
[Root @ localhost ~] # Rpm-ihv ipvsadm-1.24.8.1.i386.rpm
[Root @ localhost ~] # Rpm-ihv piranha-0.8.4-7.el5.i386.rpm
After that, set a password for piranha-gui and start the service:
[Root @ localhost ~] #/Usr/sbin/piranha-passwd
New Password:
Verify:
Updating password for user piranha

[Root @ localhost ~] # Service piranha-gui restart
Shutting down piranha-gui :[?? OK?]
Starting piranha-gui :[?? OK?]
[Root @ localhost ~] # Chkconfig piranha-gui on

Enter http: // localhost: 3636 in the browser and enter the username: piranha and the password you just defined to enter the configuration interface of the piranha configuration tool:
In this interface, the first place to be set is CONTROL/MONITORING. in this interface, set the options in MONITOR:
On the Auto update check box, Update Interval is automatically defined as 10 s. The lvs routing table and lvs process are invisible before the service is started. Select Update information now.

The second place to be set on this interface is global settings. in this interface:
Primary server public IP: 192.168.1.10? ?? ?? ?? ?? ? (Real external address)
Primary server private IP: 10.0.0.10? ?? ?? ?? ?? ?? ? (Real internal address)
Use network type :? ?? ?? ? NAT? ?? ?? ?? ?? ?? ?? ?? ??? (LVS mode)
NAT Router IP :? ?? ?? ?? ?? ? 10.0.0.254? ?? ?? ?? ?? ??? (Internal floating IP address)
NAT Router MASK :? ?? ?? ? 255.255.0.0? ?? ?? ?? ?? ? (Internal floating mask)
NAT Router Device :? ?? ?? ? Eth1: 1? ?? ?? ?? ?? ?? ?? ? (Devices running floating IP addresses)
Select accept configuration
? ?? ???
The third place to be set on this interface is REDUNDANCY, in this interface:
Because no redundant configuration is added to this structure, you can DISABLE it or set it to ENABLE but leave the configuration empty. In this example, my configuration is empty:
Redundant server public IP :? ?? ?? ?? ?? ? 0.0.0.0
Redundant server private IP:
Heartbeat Interval (seconds ):? ?? ?? ? 6
Assume dead after (seconds ):? ?? ?? ? 18
Heartbeat runs on port :? ?? ?? ?? ?? ?? ?? ? 539
Monitor NIC links for failure :? ?? ?? ?? ?? ? Uncheck
Select accept configuration

The fourth place to be set on this interface is virtual servers:
Each Virtual Servers represents a service provided. because there is only one service HTTP, select ADD and enter the following information in the prompt:
Name :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? HTTP
Application port :? ?? ?? ?? ?? ?? ?? ?? ??? 80
Protocal :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? TCP
Virtual Server Address :? ?? ?? ?? ?? ??? 192.168.1.250
Virtual IP Network Mask :? ?? ?? ?? ?? ? 255.255.255.0
Firewall Mark :? ?? ?? ?? ?? ?? ?? ?? ?
Device :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??? Eth0: 1
Re-entry Time :? ?? ?? ?? ?? ?? ?? ?? ?? ? 15
Service Timeout :? ?? ?? ?? ?? ?? ?? ?? ??? 6
Quiesce :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? No
Load Monitor Tool :? ?? ?? ?? ?? ?? ?? ?? ? None
Scheduling :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? Weighted least-connections? Weighted least join (default )??? ?? ?? ?? ?? ?? ?? ? --
Persistence :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
Persistence Network Mask :? ?? ?? ?? ? Unused
Select accept and enable the service

The fifth place to be set on this interface is real servers:
Name :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? Localhost. localdomain
Address :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 10.0.0.100
Weighted :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 1
Name :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? Localhost. localdomain
Address :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 10.0.0.200
Weighted :? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? 1
Select accept and enable the service

The sixth place to be set on this page is monitoring scripts. keep the default value.

After the configuration is complete, make sure that all the configurations are saved. The LVS configuration is complete. The final task is to start the master service on the Router of LVS:
# Service pulse start
# Chkconfig pulse on
At this time, we can see that eth0: 1 and eth1: 1 have been automatically created:
[Root @ localhost ~] # Ifconfig
Eth0: 1? ? Link encap: Ethernet ?? HWaddr 00: 0C: 29: 08: A1: 62 ??
? ?? ?? ? Inet addr: 192.168.1.250 ?? Bcast: 192.168.1.255 ?? Mask: 255.255.255.0
? ?? ?? ? Up broadcast running multicast ?? MTU: 1500 ?? Metric: 1
Eth1: 1? ? Link encap: Ethernet ?? HWaddr 00: 0C: 29: 08: A1: 6C ??
? ?? ?? ? Inet addr: 10.0.0.254 ?? Bcast: 10.0.0000255 ?? Mask: 255.255.0.0
? ?? ?? ? Up broadcast running multicast ?? MTU: 1500 ?? Metric: 1
? ?? ?? ? Interrupt: 19 Base address: 0x2080
And the related services are also enabled:
[Root @ localhost ~] # Service ipvsadm status
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddressort sched1_flags
?? -> RemoteAddressort? ?? ?? ??? Forward Weight ActiveConn InActConn
TCP ?? 192.168.1.250: 80 wlc
?? -> 10.0.0.200: 80? ?? ?? ?? ?? ? Masq? ? 1? ?? ? 0? ?? ?? ? 0? ?? ?? ?
?? -> 10.0.0.100: 80? ?? ?? ?? ?? ? Masq? ? 1? ?? ? 0? ?? ?? ? 15? ?? ???
[Root @ localhost ~] # Ps-ef | grep nanny
Root? ?? ? 3614 ?? 3596 ?? 0 ?? ?? ??? 00:00:03/usr/sbin/nanny-c-h 10.0.0.100-p 80-s GET/
HTTP/1.0 \ r \ n-x HTTP-a 15-I/sbin/ipvsadm-t 6-w 1-V 192.168.1.250-M m-U none -- lvs
Root? ?? ? 3615 ?? 3596 ?? 0 ?? ?? ??? 00:00:03/usr/sbin/nanny-c-h 10.0.0.200-p 80-s GET/
HTTP/1.0 \ r \ n-x HTTP-a 15-I/sbin/ipvsadm-t 6-w 1-V 192.168.1.250-M m-U none -- lvs
Root? ?? ? 4078 ?? 3632 ?? 0 23:56 pts/1? ? 00:00:00 grep nanny

Enable the http service on the two real servers at the same time, and create the same test page in the service directories on the two hosts respectively.
# Chkconfig httpd on
# Service httpd start

Now, access the LVS server on the client to perform the test: http: // 192.168.1.250. you can see that the real server provides the page.

At this time, the current router table information displayed after refreshing the piranha configuration tool interface has changed:
CURRENT LVS ROUTING TABLE
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddressort sched1_flags
-> RemoteAddressort Forward Weight ActiveConn InActConn
TCP 192.168.1.250: 80 wlc
-> 10.0.0.200: 80 Masq 1 0 0
-> 10.0.0.100: 80 Masq 1 0 0
The content also appears in the current LVS process list:
CURRENT LVS PROCESSES
Root 3678 0.0 0.1 1880 332? Ss pulse
Root 3702 0.0 0.2 1872 596? Ss/usr/sbin/lvsd -- nofork-c/etc/sysconfig/ha/lvs. cf
Root 3720 0.0 0.2 1852 628? Ss/usr/sbin/nanny-c-h 10.0.0.100-p 80-s GET/HTTP/1.0 \ r \ n
-X HTTP-a 15-I/sbin/ipvsadm-t 6-w 1-V 192.168.1.250-M m-U none -- lvs
Root 3721 0.0 0.2 1852 628? Ss/usr/sbin/nanny-c-h 10.0.0.200-p 80-s GET/HTTP/1.0 \ r \ n
-X HTTP-a 15-I/sbin/ipvsadm-t 6-w 1-V 192.168.1.250-M m-U none -- lvs

After refreshing the page several times, you can see that the content of current lvs routing table has been updated:
[Root @ localhost Desktop] # cat lvs
CURRENT LVS ROUTING TABLE
IP Virtual Server version 1.2.1 (size = 4096)
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddressort sched1_flags
-> RemoteAddressort Forward Weight ActiveConn InActConn
TCP 192.168.1.250: 80 wlc
-> 10.0.0.200: 80 Masq 1 0 7
-> 10.0.0.100: 80 Masq 1 0 6

That is to say, the traffic is evenly distributed to two hosts. if we find another client for a simple stress test:
Command: # AB-c 1000-n 100000 http: // 192.168.1.250/index.html
The obtained lvs routing table is as follows:
[Root @ localhost ~] # Cat Desktop/lvs
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddressort sched1_flags
-> RemoteAddressort Forward Weight ActiveConn InActConn
TCP 192.168.1.250: 80 wlc
-> 10.0.0.200: 80 Masq 1 0 317
-> 10.0.0.100: 80 Masq 1 0 1007

Because the weighted least connection algorithm is used, the load cannot be evenly distributed to two servers.
The configuration file content:
[Root @ localhost ~] # Cat/etc/sysconfig/ha/lvs. cf
Serial_no = 67
Primary = 192.168.1.10
Primary_private = 10.0.0.10
Service = lvs
Backup_active = 1
Backup = 0.0.0.0
Heartbeat = 1
Heartbeat_port = 539
Keepalive = 6
Deadtime = 18
Network = nat
Nat_router = 10.0.0.254 eth1: 1
Nat_nmask = 255.255.0.0
Debug_level = NONE
Monitor_links = 0
Virtual HTTP {
? ??? Active = 1
? ??? Address = 192.168.1.250 eth0: 1
? ??? Vip_nmask = 255.255.255.0
? ??? Port = 80
? ??? Send = "GET/HTTP/1.0 \ r \ n"
? ??? CT = "HTTP"
? ??? Use_regex = 0
? ??? Load_monitor = none
? ??? Schedlc = wlc
? ??? Protocol = tcp
? ??? Timeout = 6
? ??? Reentry = 15
? ??? Quiesce_server = 0
? ??? Server localhost. localdomain {
? ?? ?? ? Address = 10.0.0.100
? ?? ?? ? Active = 1
? ?? ?? ? Weight = 1
? ???}
? ??? Server localhost. localdomain {
? ?? ?? ? Address = 10.0.0.200
? ?? ?? ? Active = 1
? ?? ?? ? Weight = 1
? ???}
}
The experiment is successful.

[1] [2] Next page

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.