Implementation of LVS high concurrency load Balancing

Source: Internet
Author: User
Tags http redirect

First, Load balancer server:

Lvs:lvs is a shorthand for Linux virtual server, which means that Linux is a virtualized server cluster system. Founded in May 1998 by Dr. Zhangwensong, this project is one of the earliest free software projects in China.

Nginx:nginx ("Engine X") is a high-performance HTTP and reverse proxy server and a IMAP/POP3/SMTP server. Nginx was developed by Igor Sysoev for the second rambler.ru site of Russian traffic, and the first public version 0.1.0 was released on October 4, 2004. It publishes the source code in the form of a BSD license, which is known for its stability, rich feature set, sample configuration files, and consumption of low system resources.

The Apache:mod_backhand is an Apache load balancing module. It defines an HTTP redirect for each request in a heterogeneous Apache server cluster. Each request is processed and runs through a set of "candidate functions" to determine which server is the most appropriate response. The request is then proxied to the server. The facility is in place to allow you to write your own dynamic load decision algorithm. All relevant requirements and currently available resources can be used in the decision-making process.

As for the comparison between the three believe that there will be a lot of Baidu, in short: Load software selection for the actual business needs close fit, but the relative LVS should be a better choice, because nginx after all there is a single point of problem, and LVS can achieve a master and slave hot standby and because he is working in the network four layer, The efficiency is extremely high.

OK, first configure the VIP:

$ cd/etc/init.d$ VI realserver

     Input:

vip=192.168.8.100case  "$"  instart )/sbin/ifconfig lo:0  $VIP  broadcast  $VIP  netmask 255.255.255.255 up/sbin/route add -host  $VIP  dev lo:0echo   "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 -pecho  "Realserver start";; stop )/sbin/ifconfig lo:0 down/sbin/ifconfig lo:1 down/sbin/route del -host   $VIPecho   "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 stop";; * ) echo  "Argment is wrong" exit 1esacexit 0

With LVs above the linux2.6 version, only the keepalived needs to be installed.

1, install the keepalived on the main standby machine,

The steps are as follows: Download keepalived-1.1.15.tar.gz, then unzip the installation

$ #tar zxvf keepalived-1.1.15.tar.gz$ #cd keepalived-1.1.15$ #./configure$ #make $ #make Install

2, Configuration keepalived

The state master in the configuration determines the node as the primary node

Priority is prioritized, such as when there are multiple backup nodes, the priority value of the primary node after the failure of the takeover.

The master node is configured as follows:

global_defs {   notification_email {   #指定keepalived在发生切换时需要发送email到的对象, one line     [email protected]   }   notification_email_from  [email protected]  #指定发件人    smtp_server localhost  #指定smtp服务器地址     smtp_connect_timeout 30  #指定smtp连接超时时间    router_id lvs_devel # Run an identification of the keepalived machine}vrrp_instance inside_network {    state master # Specify that for master, which is backup, if the value set for nopreempt does not work, the master preparation priority decides     interface eth0 # Set network adapter     dont_track_primary  #忽略vrrp的interface错误 for instance bindings (not set by default)      track_interface{  #设置额外的监控, the network card inside the problem will switch     eth0    eth1     }    mcast_src_ip  #发送多播包的地址, if you do not set the default primary ip  using a bound NIC    garp_master_delay  #在切换到master状态后, deferred gratuitous arp request     virtual_router_id 50  #VPID标记     priority 99  #优先级, high-priority campaign for master    advert_int 1   #检查间隔, default 1 seconds     nopreempt  #设置为不抢占   Note: This configuration can only be set on the backup host, and this host priority is higher than the other one     preempt_delay  #抢占延时, default 5 minutes     debug  #debug级别      authentication {  #设置认证         auth_type  pass  #认证方式         auth_pass 111111  #认证密码      }    virtual_ipaddress {  #设置vip          192.168.8.100    }}virtual_server 192.168.202.200 23 {     delay_loop 6  #健康检查时间间隔     lb_algo rr  # RR|WRR|LC|WLC|LBLC|SH|DH&NBSP;&N of LVS scheduling algorithmbsp;  lb_kind dr   #负载均衡转发规则NAT | dr| run    persistence_timeout 5  #会话保持时间     protocol tcp   #使用的协议real_server  192.168.200.5 23 {             weight 1  #默认为1, 0 for failure              inhibit_on_failure  #在服务器健康检查失效时, set it to 0 instead of deleting it directly from Ipvs               notify_up <string> | <quoted-string>   Execute script after #在检测到server  up             notify_ down <string> | <quoted-string>  execute script after #在检测到server  down              TCP_CHECK {connect_timeout 3  #连接超时时间nb_ get_retry 3  #重连次数delay_before_retry  3  #重连间隔时间connect_port  23   #健康检查的端口的端口bindto  <ip>   80  #绑定的端口}}real_server  192.168.201.5 23 {            weight  1  #默认为1, 0 for failure             inhibit_on_ failure  #在服务器健康检查失效时, set it to 0 instead of deleting it directly from the Ipvs               notify_up <string> | <quoted-string>  #在检测到server   Up post Execute script             notify_down <string>  | <quoted-string>  execute script after #在检测到server  down              TCP_CHECK {connect_timeout 3  #连接超时时间nb_get_retry  3 # Re-connect delay_before_retry 3  #重连间隔时间connect_port  23   #健康检查的端口的端口bindto  <ip>    80  #绑定的端口}}}

The

     alternate nodes are configured as follows:

global_defs {   notification_email {   #指定keepalived在发生切换时需要发送email到的对象, one line     [email protected]   }   notification_email_from  [email protected]  #指定发件人    smtp_server localhost  #指定smtp服务器地址     smtp_connect_timeout 30  #指定smtp连接超时时间    router_id lvs_devel # Run an identification of the keepalived machine}vrrp_instance inside_network {    state backup # Specify that for master, which is backup, if the value set for nopreempt does not work, the master preparation priority decides     interface eth0 # Set network adapter     dont_track_primary  #忽略vrrp的interface错误 for instance bindings (not set by default)      track_interface{  #设置额外的监控, the network card inside the problem will switch     eth0    eth1     }    mcast_src_ip  #发送多播包的地址, if you do not set the default primary ip  using a bound NIC    garp_master_delay  #在切换到master状态后, deferred gratuitous arp request     virtual_router_id 50  #VPID标记     priority 99  #优先级, high-priority campaign for master    advert_int 1   #检查间隔, default 1 seconds     nopreempt  #设置为不抢占   Note: This configuration can only be set on the backup host, and this host priority is higher than the other one     preempt_delay  #抢占延时, default 5 minutes     debug  #debug级别      authentication {  #设置认证         auth_type  pass  #认证方式         auth_pass 111111  #认证密码      }    virtual_ipaddress {  #设置vip          192.168.8.100    }}virtual_server 192.168.202.200 23 {     delay_loop 6  #健康检查时间间隔     lb_algo rr  # RR|WRR|LC|WLC|LBLC|SH|DH&NBSP;&N of LVS scheduling algorithmbsp;  lb_kind dr   #负载均衡转发规则NAT | dr| run    persistence_timeout 5  #会话保持时间     protocol tcp   #使用的协议real_server  192.168.200.5 23 {             weight 1  #默认为1, 0 for failure              inhibit_on_failure  #在服务器健康检查失效时, set it to 0 instead of deleting it directly from Ipvs               notify_up <string> | <quoted-string>   Execute script after #在检测到server  up             notify_ down <string> | <quoted-string>  execute script after #在检测到server  down              TCP_CHECK {connect_timeout 3  #连接超时时间nb_ get_retry 3  #重连次数delay_before_retry  3  #重连间隔时间connect_port  23   #健康检查的端口的端口bindto  <ip>   80  #绑定的端口}}real_server  192.168.201.5 23 {            weight  1  #默认为1, 0 for failure             inhibit_on_ failure  #在服务器健康检查失效时, set it to 0 instead of deleting it directly from the Ipvs               notify_up <string> | <quoted-string>  #在检测到server   Up post Execute script             notify_down <string>  | <quoted-string>  execute script after #在检测到server  down              TCP_CHECK {connect_timeout 3  #连接超时时间nb_get_retry  3 # Re-connect delay_before_retry 3  #重连间隔时间connect_port  23   #健康检查的端口的端口bindto  <ip>    80  #绑定的端口}}}

Verify Startup:

$ keepalived-d-f/usr/local/etc/keepalived/keepalived.conf


Implementation of LVS high concurrency 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.