Home Operation and Maintenance Nginx Can nginx be clustered?

Can nginx be clustered?

Aug 28, 2019 pm 12:00 PM
nginx

Can nginx be clustered?

Can nginx be clustered?

nginx realizes cluster high availability

Everyone knows that NGINX can achieve load balancing as a reverse proxy server and can also be used as a static file server. Its characteristics That is, the concurrency support is large, and a single machine can support 30,000 concurrencies at the same time. Now many websites use NGINX as a gateway portal to uniformly schedule and allocate back-end resources. However, if NGINX goes down, the entire backend service will be unusable; or when the concurrency is really large, reaching the level of 100,000, there is still a limit to one NGINX, so at this time, it is necessary to perform master-slave operation on NGINX. Backup ensures high availability of services, and clusters are used to share concurrency pressure. Currently, NGINX mainly has the following solutions in these two areas. I will introduce them to you respectively:

NGINX master-slave backup

NGINX currently implements master-slave backup The mainstream solution is Keepalived Nginx to implement dual-machine hot backup.

Keepalived introduction:

Keepalived is a service high-availability solution based on the VRRP protocol. It can be used to avoid IP single points of failure. Similar tools include heartbeat, corosync, and pacemaker. But it generally does not appear alone, but works together with other load balancing technologies (such as lvs, haproxy, nginx) to achieve high availability of the cluster.

VRRP protocol:

The full name of VRRP is Virtual Router Redundancy Protocol, which is the virtual routing redundancy protocol. It can be considered a fault-tolerant protocol to achieve high availability of routers. N routers that provide the same functions are formed into a router group. This group has a master and multiple backups, but it looks like one router to the outside world. , constitute a virtual router, with a virtual IP (vip, that is, the default route of other machines in the LAN where the router is located). The master that owns this IP is actually responsible for ARP response and forwarding IP packets, and other routers in the group serve as backup roles. Standby. The master will send multicast messages. When the backup fails to receive vrrp packets within the timeout period, it is considered that the master is down. At this time, a backup needs to be elected as the master based on the VRRP priority to ensure the high availability of the router.

In the VRRP protocol implementation, the virtual router uses 00-00-5E-00-01-XX as the virtual MAC address. XX is the unique VRID (Virtual Router IDentifier). This address only has one physical router at the same time. occupied. In the physical router group in the virtual router, notification messages are sent regularly through the multicast IP address 224.0.0.18. Each Router has a priority level between 1-255, and the highest priority will become the master router. By lowering the priority of the master, the router in the backup state can preempt (pro-empt) the state of the main router. The larger of the two IP addresses with the same backup priority is the master and takes over the virtual IP.

Specific implementation principle:

1) Master is not down, then Master occupies VIP and nginx is running on Master

2) Master is down, Then the backup seizes the VIP and runs the nginx service on the backup

3) If the nginx service on the master server hangs, the VIP resources are transferred to the backup server

4) Detect the back-end server Health status

Both Master and Backup have nginx services enabled. Regardless of Master or Backup, when one of the keepalived services stops, VIP will drift to the node where the keepalived service is still there

Can nginx be clustered?

NGINX and keepalived installation and configuration

There are many installation configurations for them, as well as writing scripts to monitor each other, alarm, etc., so we will give a special lesson Lecture, this lesson mainly talks about solutions and principles.

NGINX Distributed Cluster

If there are multiple NGINX and you want to achieve load balancing,

1. Each nginx has a public network address. Setting multiple directions to the same domain name at the domain name is the easiest way to implement round robin. But the fault cut-off will be slower.

2. One public network nginx is distributed to multiple nginxes on the intranet through the upstream function, wheel, IP, and url. But if nginx on the public network is down, the entire internal network will be affected.

3. A pair of public network nginx plus three public network IPs, achieve high availability through keepalive, and then upstream to the intranet (this is the master-slave backup we just talked about in the previous section).

Generally speaking, the above 1, 2, and 3 methods can basically solve the problem. It is recommended to use 2 or 3;

If the amount of concurrency is really huge, it is generally necessary to use hardware F5 and other equipment To do load balancing, cooperate with DNS, CDN and other service providers to do domain name resolution forwarding and cache configuration. This is also the current architectural configuration of most major manufacturers.

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

The above is the detailed content of Can nginx be clustered?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to check whether nginx is started? How to check whether nginx is started? Apr 14, 2025 pm 12:48 PM

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

How to start nginx in Linux How to start nginx in Linux Apr 14, 2025 pm 12:51 PM

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

How to solve nginx403 How to solve nginx403 Apr 14, 2025 am 10:33 AM

How to fix Nginx 403 Forbidden error? Check file or directory permissions; 2. Check .htaccess file; 3. Check Nginx configuration file; 4. Restart Nginx. Other possible causes include firewall rules, SELinux settings, or application issues.

See all articles