In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The following brings you which mechanisms are supported by nginx load balancing, hoping to give you some help in practical application. Load balancing involves more things, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.
Nginx supports the following load balancing mechanisms:
Round-robin: polling. Assign requests to different CVMs by polling
Least-connected: minimum number of connections. Assign the next request to the server with the least number of connections
Ip-hash: based on the client's IP address. The hash function is used to determine which server the next request is assigned to.
Default configuration of load balancer
The simplest configuration of nginx load balancer is as follows:
Http {
Upstream myapp1 {
Server srv1.example.com
Server srv2.example.com
Server srv3.example.com
}
Server {
Listen 80
Location / {proxy_pass http://myapp1;}
}
}
In the above example, srv1,srv2,srv3 is running the same application. If there is no special specified load balancing method, the default is polling. All requests are delegated to the service group myapp1, and then the nginx load balancer distributes the requests.
The nginx reverse proxy implementation includes the following load balancers HTTP, HTTPS, FastCGI, uwsgi,SCGI, and memcached.
To configure load balancing for HTTPS, simply use the protocol that starts with "https".
When you want to set up FastCGI,uwsgi,SCGI, or load balancing for memcached, use the fastcgi_pass,uwsgi_pass,scgi_pass and memcached_pass instructions, respectively.
Least connection load balancer
In some applications that require a longer time to complete, the least connection can more fairly control the load of the application instance. With minimal connection load balancing, nginx does not distribute requests to servers with heavy loads, but to servers with low loads.
The configuration is as follows:
Upstream myapp1 {
Least_conn
Server srv1.example.com
Server srv2.example.com
Server srv3.example.com
} session persistence
With polling or least connection load balancing algorithm, the requests of each subsequent client can be potentially assigned to different servers, and there is no guarantee that the same client requests will always be directed to the same server.
This can be problematic in application scenarios with session information. The general practice is to share session information, such as using memcache to store session.
It is also possible to "stick" the client's session or always try to select a specific server. The ip-hash mechanism of load balancing can be implemented.
The configuration is as follows:
Upstream myapp1 {
Ip_hash
Server srv1.example.com
Server srv2.example.com
Server srv3.example.com
}
Weighted load balancing
Weights can be used to further control the impact on the nginx load balancing algorithm.
In the above example, no weights are configured, which means that all specified servers are considered the same.
When the weight parameter of the specified server is specified, the weight ratio is part of the load balancing decision. A heavy load is a heavy load.
The configuration is as follows:
Upstream myapp1 {
Server srv1.example.com weight=3
Server srv2.example.com
Server srv3.example.com
}
In this case, every 5 new requests will be distributed as follows: 3 requests will be directed to SRV1, one request will go to SRV2, and another request will go to srv3.
After reading the above about which mechanisms are supported by nginx's load balancing, if there is anything else you need to know, you can find out what you are interested in in the industry information or find our professional and technical engineers for answers. Technical engineers have more than ten years of experience in the industry. Official website link www.yisu.com
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.