Ten scheduling algorithms and load Balancing of LVS cluster (configuration)

Source: Internet
Author: User

Architecture diagram:

650) this.width=650; "alt=" 130430677.gif "src=" Http://img1.51cto.com/attachment/201107/130430677.gif "/>

1, installation keepalived

Keepalived was originally designed for LVS, specifically to monitor the status of each service node in the cluster system, and later added the VRRP function, VRRP is the abbreviation for virtual Router redundancy Protocol The purpose of VRRP is to solve the problem of single point of failure 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.

[Email protected]:~$ apt-get install Keepalived[email protected]:~$ vi/etc/keepalived/Keepalived.conf[email protected]:~$ cat/etc/keepalived/keepalived.conf#Configuration File for keepalivedglobal_defs {router_id lvs_1##keepalived服务器标识}vrrp_instance vi_1 {State MASTER## #指定Keepalived的角色, master indicates that this host is the primary server and backup represents a standby server. Interface eth0## # #指定HA监测网络的接口. VIRTUAL_ROUTER_ID 51## # #虚拟路由标识, this identifier is a number, and the same VRRP instance uses a unique identity, that is, master and backup must be consistent under the same vrrp_instance. Priority 100##定义优先级, the higher the number, the higher the priority, and under one vrrp_instance, Master's priority must be greater than the priority of backup. Advert_int 1##设定MASTER与BACKUP负载均衡器之间同步检查的时间间隔, the unit is seconds. nopreempt Authentication {## #设定验证类型和密码. Auth_type PASS## #设置验证类型, there are mainly pass and AH two kinds. Auth_pass 1234## #设置验证密码, under a vrrp_instance, master and backup must use the same password to communicate properly. } virtual_ipaddress {192.168.2.218}}virtual_server192.168.2.218 80{Delay_loop3## #设置健康检查时间, units are seconds. Lb_algo WLC## #设置负载调度算法, see: http://strongit.blog.51cto.com/10020534/1728596Lb_kind DR## #设置LVS实现负载均衡的机制, you can have NAT, Tun and Dr three modes selectable. protocol TCP Real_server192.168.2.201 80{tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port80}} real_server192.168.2.202 80{tcp_check {connect_timeout3## #3秒无响应超时Nb_get_retry 3#Retry CountDelay_before_retry 3##重试间隔Connect_port 80}} real_server192.168.2.203 80{tcp_check {connect_timeout3Nb_get_retry3Delay_before_retry3Connect_port80}}}virtual_server192.168.2.218 5672{Delay_loop3Lb_algo WLC lb_kind DR protocol TCP real_server192.168.2.201 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672}} real_server192.168.2.202 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672}} real_server192.168.2.203 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672}}}global_defs {router_id lvs_2}vrrp_instance vi_2 {State MASTER interface eth0 Virtual_rout er_id52 Priority99nopreempt Authentication {auth_type PASS auth_pass1234} virtual_ipaddress {192.168.2.219}}virtual_server192.168.2.219 80{Delay_loop3Lb_algo WLC lb_kind DR#Persistence_timeout 3protocol TCP Real_server192.168.2.221 80{tcp_check {#Connect_timeout 3Nb_get_retry 1Delay_before_retry1Connect_port80}} real_server192.168.2.222 80{tcp_check {#Connect_timeout 3Nb_get_retry 1Delay_before_retry1Connect_port80}} real_server192.168.2.223 80{tcp_check {#Connect_timeout 3Nb_get_retry 1Delay_before_retry1Connect_port80}}}virtual_server192.168.2.219 5672{Delay_loop3Lb_algo LBLCR lb_kind DR protocol TCP real_server192.168.2.221 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672}} real_server192.168.2.222 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672}} real_server192.168.2.223 5672{tcp_check {#Connect_timeout 3Nb_get_retry 3Delay_before_retry3Connect_port5672        }     }}

By default, keepalived will look for the/etc/keepalived/keepalived.conf profile when it starts, and if your profile is placed under a different path, you can use the "keepalived-f" parameter specifies the path to the configuration file you are in.

The configuration of the keepalived is different from the one where the master has priority, which is lower than the priority of the master, and the other places are the same.

2. Web server-side configuration

Add virtual IP (VIP)

Ifconfig lo:0 192.168.2.218 netmask 255.255.255.255

3. Test lvs+keepalived

/etc/init.d/keepalived restart 查看lvs-master日志:

在浏览器里面访问 http://192.168.2.218/ 即可!当你宕掉lvs-master后,lvs-backup会接管变成lvs-master提供服务,当lvs-master故障恢复后,lvs-backup又会变成原来的状态!

4. Practical advice-brain fissure

为了解决脑裂问题,需要把主MASTER和备BACKUP各自的keepalived.conf配置文件里面的state 状态都改成BACKUP,优先级分别设置10090

我们常听说脑裂问题,到底什么是脑裂问题呢?

在集群配置中的split-brain现象是指,主从之间互相检测不到心跳,同时抢占资源,导致服务无法正常访问的情况。所以我们还需要在主备keepalived.conf添加nopreempt 指令!

Attached realserver.sh script file: Excerpt from (Wu Guangko teacher about lvs+keepalived High Availability load Balancing automation configuration)

#!/bin/SH#LVS Client Servervip=192.168.111.138 Case$1  inch                                                                                                                                                                                                                                    Start ifconfigLo0$VIP netmask255.255.255.255Broadcast $VIP/sbin/route add-host $VIP Dev lo:0    Echo "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_announce sysctl-P >/dev/NULL 2>&1    Echo "realserver Start OK"Exit0;; Stop)ifconfigLo0Down Route del $VIP>/dev/NULL 2>&1    Echo "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 OK"Exit1;;*)    Echo "Usage: $ {start|stop}";;Esac

Ten scheduling algorithms for LVS clusters and load balancing (configuration)

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.