NET Distributed System three: Keepalived+lvs+nginx Load balancer High Availability

Source: Internet
Author: User

The previous article written the Nginx load balancer, this article realizes the high Availability (HA). The overall design of the system is to use Nginx to do load balancing, if there is an nginx single-machine failure, the whole system will not function properly. For the high-availability requirements of system architecture design, we need to solve the requirement of normal operation of the system when the single machine failure occurs in nginx load balancer. Therefore, the system architecture introduces keepalived components to achieve high system availability.

  I. Introduction of Keepalived

Keepalived is a highly available software for distributed Deployment system solution systems, combined with LVS (Linux Virtual Server), which functions like heartbeat and solves the problem of single-machine outages.

  Second, the principle of keepalived technology

Keepalived is based on the VRRP protocol, the VRRP full name virtual Router Redundancy Protocol, that is, the VPN routing redundancy protocol. Through the VRRP protocol combined with LVS, the group server monitoring situation, if Master has a downtime, the VIP drift to the backup machine. Realize the high availability of distributed system. Can be understood as: Keepalived is the management software LVS, according to the monitoring situation, the outage server removed from the Ipvsadm.

  Three, Keepalived+lvs+nginx realize system high availability

  

Server IP Address Description
Virtual IP 192.168.1.120:80
Host 192.168.1.104:80
Standby machine 192.168.1.103:80
Web Site A 192.168.1.101:8081 Different ports
Web Site B 192.168.1.101:8082 Different ports

  

1. Install the IPVSADM,CENTOS7 with the installation package and install it through Yum. Implement system Support LVS

Yum Install Ipvsadm

2, install keepalived software, and set the keepalived boot

Yum Install keepalived
Systemctl Enable keepalived

  

3, for keepalived.conf configuration, if it is the master machine, the state backup is changed to state MASTER.

vim/etc/keepalived/keepalived.conf# Configuration of content! Configuration File for Keepalivedglobal_defs {notification_email {[email protected] #收到通知的邮件地址} notifica  Tion_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout-router_id LVS_DEVEL}vrrp_script monitor_nginx{script "/usr/local/etc/keepalived/script/monitor_nginx.sh" Interval 1 weight-15}vrrp_instance VI_1        {State BACKUP interface eno16777736 virtual_router_id advert_int 1 Authentication { Auth_type PASS auth_pass 1111} virtual_ipaddress {192.168.1.120} track_script {m Onitor_nginx}}virtual_server 192.168.1.120 {delay_loop 6 lb_algo wrr lb_kind DR persistence_timeout 5            0 Protocol TCP real_server 192.168.1.103 {weight 1 Tcp_check {connect_timeout 10 Nb_get_retry 3 delay_before_retry 3 Connect_port}} real_sErver 192.168.1.104 {Weight 5 tcp_check {connect_timeout Nb_get_retry 3 Delay_before_retry 3 Connect_port 80}}

4. Configure the Monitor shell script

(1) Created: vim/usr/local/etc/keepalived/script/monitor_nginx.sh

(2) Shell file contents
#!/bin/bash If ["$ (Ps-ef | grep "Nginx:master Process" | Grep-v grep) "= =" "]then systemclt start nginx.service sleep 5 If [" $ (Ps-ef | grep "Nginx:master Process" | Grep-v grep) "= =" "] then killall keepalived fi fi

Above to complete the relevant configuration, Nginx and Web services above a blog content consistent. The following functions are validated for testing.

  Iv. implementation of the test show

1, Access system situation: through the VIP (192.168.1.120) access to the system page. Because the polling schedule is set, refreshing the page accesses different sites.

2, the MASTER (192.168.1.104) before and after the shutdown, check the relevant VLS situation:

(1) before the shutdown:

(2) After shutting down the machine:

We saw the removal of 104 servers from LVS. The subsequent request is forwarded to the 103 server at this point.

3, after the shutdown, the backup server keepalived log display can not connect 104, and remove

  

5, after the boot, will automatically detect the server normal, and added LVs.

  

Author: Andon
Source: Http://www.cnblogs.com/Andon_liu
About the focus on Microsoft Platform Project architecture, management. Familiar with design patterns, domain drivers, architecture design, agile development and project management. is mainly engaged in ASP, Wcf/web API, SOA, MSSQL, Redis aspects of project development, architecture, management work. If you have questions or suggestions, please learn to discuss together!
This article is copyrighted by the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link.
If you have questions, you can email: [Email protected] contact me, thank you.

NET Distributed System three: Keepalived+lvs+nginx Load balancer High Availability

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.