架构师_程序员_码农网

Retrieve password
Register

QQ登录

Just one step to get started

Search
View:5464|Reply: 1
打印 上一主题 下一主题

Web High Availability Tutorial with Keepalived and Nginx

[copy link]
跳转到指定楼层
owner
发表于 2021-10-18 23:08:11| 看该作者回帖奖励|ReverseBrowse|Read Mode
Keepalived software is mainly through the VRRP protocol to achieve high-availability features. VRRP is the acronym for Virtual Router Redundancy Protocol (VRRP), VRRP appeared in order to solve the problem of static routes with a single point of failure, which ensures that when an individual node is down, the whole network can be uninterrupted operation. Therefore, Keepalived on the one hand has the function of configuration and management of LVS, but also has the function of health checking the nodes below the LVS, on the other hand, it can also realize the function of high availability of the system network services.

Keepalived Highly Available Failover Principle

The failover transfer between Keepalived highly available service pairs is realized through VRRP (Virtual Router Redundancy Protocol).

When the Keepalived service is working normally, the master node sends heartbeat messages to the backup node to tell the backup node that it is still alive. When the master node fails, it can't send heartbeat messages, and the backup node can't detect heartbeats coming from the master node. When the master node fails, it cannot send heartbeat messages, and the backup node cannot detect the heartbeat from the master node, so it calls its own takeover program to take over the IP resources and services of the master node. When the master node recovers, the backup node releases the IP resources and services it took over when the master node failed and returns to its original standby role.

Keepalived high availability pairs communicate with each other through VRRP.

(1) VRRP, full name Virtual Router Redundancy Protocol, Chinese name for Virtual Route Redundancy Protocol, VRRP appeared in order to solve the static route of a single point of failure.
(2) VRRP is a campaign protocol mechanism to give routing tasks to a particular VRRP router.
3) VRRP uses IP multicast ( default multicast address (224.0.0.18) ) to realize communication between highly available pairs.
4) When working, the master node sends packets and the backup node receives packets. When the backup node cannot receive the packets sent by the master node, it starts the takeover program to take over the resources of the master node. The backup node can have more than one, through the priority campaign, but generally Keepalived system operation and maintenance work is a pair.
(5) VRRP uses a cryptographic protocol to encrypt data. but Keepalived officials still recommend configuring authentication types and passwords in plaintext.

How the Keepalived service works

(1) Keepalived highly available pairs are communicating with each other through VRRP. VRRP determines the master and the backup through the election mechanism, and the priority of the master is higher than that of the backup, so the master will have priority to obtain all the resources at work, and the backup node is in a waiting state. When the master hangs up, the backup node will take over the resources of the master node, and then take over from the master node to provide services to the outside world.

(2) In the Keepalived service pairs, only the server as the master will keep sendingVRRPbroadcast packets to tell the backup that it is still alive, at this time, the backup will not seize the master, when the master is not available, i.e., the backup can't listen to the broadcast packets sent by the master, it will start the related services to take over the resources, to ensure the continuity of the service. The fastest takeover speed can be less than 1 second.

Test Environment

System: CentOS 8

IP Address Description
192.168.50.222 VIP Address
192.168.50.227 MASTER Master Node
192.168.50.131 BACKUP Standby node

Let's look at the finished build as follows:


Install the Nginx service

Use yum to install nginx directly on the primary and standby node servers with the following commands:


Edit the nginx configuration files of the master and standby nodes respectively at /etc/nginx/nginx.conf with the following configuration:



Start the nginx command and test accessing port 8055 through a browser as shown below:



Install Keepalived
Install on both servers, the primary and standby nodes, with the following commands:




Configuration file address: /etc/keepalived/keepalived.conf



Here you need to configure a health check script, create a new chk_nginx.sh file with the following code:

Upload the script to the /etc/keepalived directory. Upload the script to the /etc/keepalived directory and give it execute permission with the following command:



192.168.50.227 The master node keepalived.conf is configured as follows:

192.168.50.133 The standby node keepalived.conf is configured as follows:

Set up power-on startup on each of the two servers and start the



At this point, the configuration is complete (see the top of the article for the effect), you can test through the nginx service, the command is as follows:

(end)




Previous: OpenFeign connect timed out executing exception
Next:Stumble upon the site
Code farmer network, only published in the practice process, encountered technical difficulties, not mislead others.
sofa
owner|Posted on 2021-11-20 09:05:11|Only see this author
Configuring Active-Active High Availability and Additional Passive Nodes with keepalived https://docs.nginx.com/nginx/adm ... a-keepalived-nodes/
The code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
You need to log in before you can post back Log in | Register

This version of the integral rules

DISCLAIMER:
All software, programming materials or articles published by Code Farmer are limited to be used for learning and research purposes only; the above contents shall not be used for commercial or illegal purposes, otherwise, all the consequences shall be borne by the users themselves. This site information from the network, copyright dispute has nothing to do with this site. You must completely remove the above content from your computer within 24 hours of downloading. If you like the program, please support the genuine software, buy registration and get better genuine service. If there is any infringement, please contact us by email to deal with it.

Mail To:help@itsvse.com

QQ| ( ICP备14021824号-2 )|Sitemap

GMT+8, 2024-9-18 17:47

Quick ReplyBack to topBack to list