Implementation of Linux CentOS cluster LVS load Balancing

Source: Internet
Author: User

Tag: Address file path shell script uses Evel Aliyun try directory 127.0.0.1

Preparatory work

Environment: WIN10 under Centos6.4 virtual machine.

Load Balancing: Two units (one master and one standby) LVS + keepalived.

HTTP Server: 3 units.

Configure IP for each server

1. VIP (virtual IP): The IP address used to provide the virtual Server service. are bound on the director of a physical network card (external receiving request packet) and the loopback device RS (loopback device needs to bind two IP, one is 127.0.0.1, the other is VIP).

Vulgar speaking, load balancing is the Linux virtual server, that is, add a virtual machine, the virtual machine has an IP, also known as the Vip;linux virtual machine itself also has an IP, that is, the local IP, these two IP is the same status.

2, DIP (director IP): with the VIP bound on a physical network card, used to forward the request packet to the RS rip corresponding Mac, this device can get the MAC address of RIP corresponding to the ARP request.

3. RIP (real server IP): It is bound on a physical NIC on RS to receive the request packets forwarded from directory. That is, the IP of the real server.

Say the IP of each server I tested:

LVS Load Balancer Master (192.168.132.244), LVS load Balancing standby (192.168.132.245)

HTTP1 (192.168.132.251), HTTP2 (192.168.132.252), HTTP3 (192.168.132.242)

First, each HTTP server shuts down the firewall to try to access, start the httpd service, and then give a marked distinction. This puts the index.html page of each server out of the current IP.

Add the Lo:0 interface on each station (HTTP server) real server network and set the virtual IP on this interface
# cd/etc/init.d/ # Vim Realserver
sns_vip=192.168.132.200#define VIP variables 192.168.132.200. /etc/rc.d/init.d/functions#Guide Script Library Case"$" in#The case statement is passed to the first parameter of the shell scriptstart) ifconfig Lo: 0$SNS _VIPNetmask 255.255.255.255 Broadcast$SNS _VIP  #set lo:0 VIP netmask and broadcast/sbin/route Add-host$SNS _VIPDev lo:0#Route del add local routeEcho"1" >/proc/sys/net/ipv4/conf/lo/Arp_ignoreEcho"2" >/proc/sys/net/ipv4/conf/lo/arp_announceEcho"1" >/proc/sys/net/ipv4/conf/all/Arp_ignoreEcho"2" >/proc/sys/net/ipv4/conf/all/Arp_announcesysctl-P >/dev/NULL2>&1#-P <file (default/etc/sysctl.conf) Enter standard information into device empty fileEcho"Realserver Start OK";; Stop) ifconfig Lo: 0Downroute del$SNS _VIP>/dev/NULL2>&1#Route del Delete local routeEcho"0" >/proc/sys/net/ipv4/conf/lo/Arp_ignoreEcho"0" >/proc/sys/net/ipv4/conf/lo/arp_announceEcho"0" >/proc/sys/net/ipv4/conf/all/Arp_ignoreEcho"0" >/proc/sys/net/ipv4/conf/all/arp_announceEcho"Realserver stoped";;*)Echo"Usage: $ {start|stop}"#the name of the script itselfExit1#indicates that the process exited gracefullyEsac#Case closedExit0#indicates that the process is not properly exited
# chmod realserver      #给此脚本赋予权限 #chkconfig realserver on         #设置开机自启动此脚本 # service realserver start          #开启此脚本realserver start OK         # indicates a successful startup! # ifconfig        #查看一下是否真的成功添加了lo: 0 interface

OK, check to see if all three HTTP servers are working, then proceed to the next step

Start Building Load Balancing

Eight different scheduling algorithms are available in LVS

For more information, please refer to: http://blog.csdn.net/u014649204/article/details/25115039

1: Round call dispatch (Round-robin scheduling)

2: Weighted round call dispatch (Weighted round-robin scheduling)

3: Minimum connection schedule (least-connection scheduling)

4: Weighted minimum connection schedule (Weighted least-connection scheduling)

5: Minimum link based on locality (locality-based Least Connections scheduling)

6: Local least-Link with replication (locality-based Least Connections with Replication scheduling)

7: Target Address hash dispatch (Destination Hashing scheduling)

8: Source Address hash dispatch (source Hashing scheduling)

9: Shortest expected delay schedule (shortest expected delay scheduling)

10: No queue scheduling (never queue scheduling)

Correspondence: RR|WRR|LC|WLC|LBLC|LBLCR|DH|SH|SED|NQ

LVS Load Balancer Host:

Look at the CentOS kernel first, if the kernel is 2.6, then the LVS virtual machine already exists in the kernel.

Use Yum to install keepalived here

Yum-y Install keepalived

After the installation is complete, use the RPM-QL command to view the installation information for keepalived

RPM-QL keepalived

Depending on the keepalived profile path in the prompt, overwrite the configuration file and write to the following command. Detailed instructions are explained at the end.

Global_defs {#Notification_email {#[email protected]#   }#notification_email_from [email protected]#Smtp_server smtp.exmail.qq.com#Smtp_connect_timeoutrouter_id lvs_devel}vrrp_instance vi_1 {State MASTER#Master    InterfaceEth1#look at the IP on the load Balancer host, this is eth1.     Be careful here. VIRTUAL_ROUTER_ID 51 Priority100#Priority LevelAdvert_int 1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.132.200}}virtual_server192.168.132.200 80{Delay_loop6Lb_algo wrr lb_kind DR nat_mask255.255.255.0Persistence_timeout0protocol TCP Real_server192.168.132.251 80 {#First HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80}} real_server192.168.132.252 80 {#Second HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80}} real_server192.168.132.242 80 {#Third HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80        }    }}

Then start the keepalived service, sometimes although the prompt starts successfully, but not necessarily, because KeepAlive does not have the configuration file verification function, it is best to check the log.

Service keepalived start    // Start Services tail-f/var/log/message     //  View Logs

After successful launch, the browser accesses 192.168.132.200 to observe the changes.

OK, shunt successful.

Then we try to shut down an HTTP server, observe the discovery of access, the other two still have normal access, and then start the server just shut down, and then resumed.

LVS Load balancer Standby machine:

Global_defs {#Notification_email {#[email protected]#   }#notification_email_from [email protected]#Smtp_server smtp.exmail.qq.com#Smtp_connect_timeoutrouter_id lvs_devel}vrrp_instance vi_1 {State BACKUP#prepared    InterfaceEth1#look at the IP on the load Balancer host, this is eth1.     Be careful here. VIRTUAL_ROUTER_ID 51 Priority99#priority, lower than hostAdvert_int 1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.132.200}}virtual_server192.168.132.200 80{Delay_loop6Lb_algo wrr lb_kind DR nat_mask255.255.255.0Persistence_timeout0protocol TCP Real_server192.168.132.251 80 {#First HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80}} real_server192.168.132.252 80 {#Second HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80}} real_server192.168.132.242 80 {#Third HTTPWeight 3Tcp_check {connect_timeout10Nb_get_retry3Delay_before_retry3Connect_port80        }    }}

After the configuration is completed, and then try to shut down the host, continue to access 192.168.132.200, everything is normal, the host after the boot, the host continues to do the eldest brother, standby machine continue to stand by.

Complete!

Implementation of Linux CentOS cluster LVS load Balancing

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.