In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to achieve load balancing in Nginx. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
Or the picture is relatively clear, the following I use aliases:
PA: load balancer server / WEB ingress server / www.mydomain.com P1: WEB server / split 1max 192.168.2.3 P2: WEB server / split 2Universe 192.168.2.4 P3: WEB server / split 3pm 192.168.2.5
PS: first of all, before we start to learn this, children's shoes who do not understand firewalls, I suggest you turn off the firewalls of PA, P1, P2 and P3 and try not to cause unnecessary trouble.
First of all: PA, P1, P2, P3 all installed Nginx, will not install can go to the official website to see the tutorial: http://www.nginx.cn/install (Chinese version of the tutorial, very Niu X)
After installing, ha, we first find the nginx.conf configuration file of PA.
Add the following code to the http section:
Upstream servers.mydomain.com {server 192.168.2.3 server; server 192.168.2.5; server 192.168.2.5;}
Of course, the servers.mydomain.com took it at will.
Then the server configuration of PA is as follows:
Add the following code to the http section:
Server {listen 80; server_name www.mydomain.com; location / {proxy_pass http://servers.mydomain.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
Then the configurations of P1, P2 and P3 are as follows:
Server {listen 80; server_name www.mydomain.com; index index.html; root / data/htdocs/www;} someone asked, "is it possible for me to use other ports? of course, it is also possible, assuming that PA's nginx.conf profile upstream servers2.mydomain.com {server 192.168.2.3 listen 8080; server 192.168.2.4 server_name www.mydomain.com; index index.html; root 8081; server 192.168.2.5 server 8082;} listen 80" Server_name www.mydomain.com; location / {proxy_pass http://servers2.mydomain.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
Then the configuration of P1 is as follows:
Server {listen 8080; server_name www.mydomain.com; index index.html; root / data/htdocs/www;}
P2 configuration:
Server {listen 8081; server_name www.mydomain.com; index index.html; root / data/htdocs/www;}
P3 configuration:
Server {listen 8082; server_name www.mydomain.com; index index.html; root / data/htdocs/www;}
After the restart, we visited, well, it was good, it was really good.
When we shut down a server.
Visit the URL, or OK. Explanation: the load balancer also needs to know how to fix him (T flirting with girls)
So how does the load balancer keep talking?
Of course, there are several options now, and we are only talking about one this time.
IP hash strategy
Advantages: it can better allocate multiple requests from the same client to the same server for processing, avoiding the requirement that weighted polling is not suitable for session persistence.
Cons: when there are a lot of requests from an IP address at a certain time, it will lead to an imbalance in which one back-end server may be very stressed while other back-end servers are idle.
The configuration of nginx is also very simple. The code is as follows:
Upstream servers2.mydomain.com {server 192.168.2.3 server 8081; server 192.168.2.5 server 8082; ip_hash;} that's all about how to implement load balancing in Nginx. I hope the above can help you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.