Lvs+keepalived build a highly available load Balancing configuration method (Configuration chapter) _linux

Source: Internet
Author: User
Tags time limit

A brief introduction of LVS

LVS is the short name of Linux virtual server, the Linux VM, a free software project initiated by Dr. Zhangwensong, and its official site is www.linuxvirtualserver.org. Now that LVS is already part of the Linux standard kernel, Before the Linux2.4 kernel, the use of LVS must be recompiled to support the LVS function module, but from the Linux2.4 kernel, has been completely built in the LVS function modules, no need to make any patches to the kernel, you can directly use the various functions of LVS. The goal of using LVS technology is to achieve a high-performance, highly available server cluster through LVS's load balancing technology and Linux operating system, which is reliable, scalable, and operable. In order to achieve the best service performance at low cost.

About the installation and introduction of LVS, in the previous article has been in-depth introduction, here no longer tell.

This article explains the following environment:

Operating system: Unified use of Centos5.3 version, address planning as follows:

Figure 1

The VIP in Figure 1 refers to the virtual IP address, also can be called LVS Cluster service IP, in the DR, Tun mode, the packet is returned directly to the user, so, on the director server and on each node of the cluster need to set this address. This IP is typically bound on a loopback address, such as lo:0, on real server, and, similarly, on director server, virtual IP is bound on a true network interface device, such as eth0:0.
Each real server can be within the same network segment, it can be a separate network segment, or it can be multiple servers that are distributed across the Internet.

The lvs+keepalived high Availability load Balancing cluster topology is shown in Figure 2:

Figure 2

The


II, installation keepalived

keepalived was originally designed for LVS, designed to monitor the status of each service node in the cluster system, and later added the VRRP function. VRRP is the abbreviation of Virtual Router redundancy Protocol, which is the VRRP to solve the problem of single point fault in static routing, which can guarantee the uninterrupted and stable operation of the network. Therefore, keepalived on the one hand has the server health detection function, on the other hand also has the HA cluster function. The official site of the  
 keepalived is http:// www.keepalived.org, you can download to various versions here, we download here is keepalived-1.1.19.tar.gz, installation steps are as follows:
[ROOT@DR1 ~] #tar ZXVF keepalived-1.1.19.tar.gz
[root@dr1 ~] #cd keepalived-1.1.19
[Root@dr1 keepalived-1.1.19]#./configure   --SYSCONF=/ETC \
>--with-kernel-dir=/usr/src/kernels/2.6.18-8.el5-i686
[root@dr1 KEEPALIVED-1.1.19] #make
[root@dr1 keepalived-1.1.19] #make install
[ROOT@DR1 keepalived-1.1.19] #ln-S/usr/ local/sbin/keepalived /sbin/
  in compilation options, "--sysconf" specifies the installation path for keepalived configuration file, that is, the path is/etc/keepalived/ keepalived.conf, "--with-kernel-dir" is an important parameter, but this parameter is not to compile the keepalived into the kernel, but to specify the header file in the kernel source code, which is the include directory. If you want to use LVS, you need to use this parameter, otherwise it is not required.

Third, the configuration keepalived

Keepalived configuration is very simple, only need a configuration file to complete the HA cluster and LVS service node monitoring function, keepalived installation has been described in the above section, in the keepalived to build a highly available LVS cluster instance, the main, The Director server requires the installation of the Keepalived software, and the default profile path is/etc/keepalived/keepalived.conf after the installation is successful. A complete keepalived configuration file, consisting of three components, namely the Global Definition section, the VRRP instance Definition section, and the Virtual Server Definition section, details the detailed meaning and usage of each option in the configuration file below:

#全局定义部分
Global_defs {
Notification_email {
Dba.gao@gmail.com #设置报警邮件地址, you can set multiple, one for each line. Note that if you want to open the mail alarm, you need to turn on the SendMail service.
Ixdba@163.com
}
Notification_email_from keepalived@localhost #设置邮件的发送地址.
Smtp_server 192.168.200.1 #设置smtp server address.
Smtp_connect_timeout #设置连接smtp服务器超时时间.
router_id Lvs_master #运行Keepalived服务器的一个标识. Information that appears in the message header when you send the message
}


#vrrp实例定义部分
Vrrp_instance Vi_1 {
State Master #指定Keepalived的角色, master indicates that this host is the primary server, and backup represents the standby server.
Interface Eth0 #指定HA监测网络的接口.
virtual_router_id #虚拟路由标识, this identity is a number, and the same VRRP instance uses a unique identifier, that is, under the same vrrp_instance, master and backup must be consistent.
Priority #定义优先级, the larger the number, the higher the priority, in a vrrp_instance, master priority must be greater than the priority of backup.
Advert_int 1 #设定MASTER与BACKUP负载均衡器之间同步检查的时间间隔, the unit is seconds.
Authentication {#设定验证类型和密码.
Auth_type Pass #设置验证类型, mainly have pass and ah two kinds.
Auth_pass 1111 #设置验证密码, under a vrrp_instance, master and backup must use the same password to communicate properly.
}
virtual_ipaddress {#设置虚拟IP地址, you can set up multiple virtual IP addresses, one per line.
192.168.12.135
}
}

#虚拟服务器定义部分
Virtual_server 192.168.12.135 {       #设置虚拟服务器, You need to specify a virtual IP address and a service port, separated by a space between the IP and the port.
    delay_loop 6       #设置健康检查时间, in seconds. The
    Lb_algo rr   #设置负载调度算法, which is set to RR, the polling algorithm.
    Lb_kind dr                        #设置LVS实现负载均衡的机制, you can have NAT, Tun and Dr three modes optional.
Persistence_timeout 50                   #会话保持时间, the unit is seconds, this option for dynamic Web pages is very useful, for the cluster system session sharing provides a good solution. With this session retention feature, the user's request is distributed to a service node until the session is held up for longer. It is to be noted that this session retention time is the maximum no response timeout, which means that if the user does not perform any action within 50 seconds when the dynamic page is being manipulated, the next operation is distributed to the other node, but if the dynamic page is being manipulated, it is not subject to a 50-second time limit.
    Protocol tcp       #指定转发协议类型, there are two kinds of TCP and UDP.

Real_server 192.168.12.246 {  #配置服务节点1, you need to specify real server's true IP address and port, separated by a space between IP and port.
Weight 3  #配置服务节点的权值, the weight value is expressed as a number, the larger the number, the higher the weight value, the size of the set weight can be different performance of the server to assign a variety of load, can be high performance of the server set a higher weight value, For the lower performance of the server set a relatively low weight, so that the rational use and allocation of system resources.
        tcp_check {    #realserve的状态检测设置部分, units are seconds
             connect_timeout 10     #10秒无响应超时
            nb_get_retry 3   #重试次数
             delay_before_retry 3    #重试间隔
       }
   }

    real_server 192.168.12.237 {   #配置服务节点2
         Weight 1   
        Tcp_check {
             connect_timeout 3   
             Nb_get_retry 3            
            delay_before_retry 3
       }
   }

When configuring keepalived.conf, you need to pay special attention to the syntax format of the configuration file, because Keepalived does not detect the correctness of the configuration file at startup, even if there is no configuration file, keepalived can start up, so the configuration file must be correct.
By default, keepalived looks for/etc/keepalived/keepalived.conf configuration files at startup, and if your profile is placed on a different path, you can go through "keepalived-f" parameter specifies the profile path you are in.
Once the keepalived.conf is configured, copy the file to the Alternate Director server path, and then make two simple modifications:
 Change "state MASTER" to "state BACKUP"
 Change priority 100 to a smaller value, which is changed to "priority 80"
Finally, configure the cluster's real server node to communicate with Director server and ignore ARP, and the content of the script has been introduced in previous articles, without explanation.

adjourned

This article is from the "Technology Achievement Dream" blog, please be sure to keep this source http://ixdba.blog.51cto.com/2895551/586898

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.