In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to configure cluster load balancing in Nginx. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. What is Nginx2 and why Nginx is used
Background:
Today, with the rapid development of the Internet, large number of users and high concurrency have become the main body of the Internet. How can a website be visited continuously by tens of thousands or hundreds of thousands of users? This is an urgent problem for some small and medium-sized websites. The website built with stand-alone tomcat can withstand about 150 to 200 concurrent visits in an ideal state. Based on 5% to 10% of the total number of concurrent visitors, the number of users of a single point of tomcat site is about 1500 to 4000. It is obviously not enough for a website that provides services nationwide. In order to solve this problem, a load balancing method is introduced. Load balancing is a problem that can not be solved by a web server, which can be solved by sharing the pressure equally among multiple web servers, and the requests sent are equally distributed to multiple backend web servers to deal with, so that the pressure is broken down.
Load balancing servers are divided into two types: one is the load balancing server implemented by hardware, referred to as hard load for example: f5. The other is load balancing realized by software, or soft load for short: for example, apache and nginx. Compared with the soft load, the hard load can act on the data link layer of the socket interface to forward the requests in packets, but the price cost is more expensive, while the soft load can forward the http requests in packets above the http protocol layer and the cost is almost zero because it is open source, and e-commerce websites such as Alibaba and JD.com all use Nginx servers.
3. Use Nginx to complete load balancing
To complete Nginx load balancing, we need to first introduce the installation and configuration of Tomcat. We must first configure Tomcat to complete the configuration of the cluster.
Because we don't have multiple servers running Tomcat. Then we can simulate running multiple Tomcat programs on one server.
1. Use Tomcat to configure Tomcat cluster
Step 1:
Download Tomcat
Step 2:
Install and configure Tomcat:
Extract the downloaded Tomcat directly to the local disk: unzip the two named tomcat1 and tomcat2.
Configure Tomcat environment variables
Complete the following configuration: (you need to change the port number of the tomcat to a different port.) Open the server.xml under the conf of two tomcat respectively
Tomcat1/conf/server.xml
Tomcat2/conf/server.xml
Installation and deployment of Nginx
Installation:
Unpack the nginx-1.8.0.zip and run it under a drive letter: the directory structure is as follows:
It means that the installation is successful!
To turn off nginx, use:
It is equivalent to finding the nginx process kill.
Nginx-s stop
Reload the configuration file:
Nginx-s reload
You can update the configuration file without closing nginx.
Configuration of load balancer for Nginx:
Open the file C:\ nginx-1.8.0\ conf\ nginx.conf:
Modify: C:\ Windows\ System32\ drivers\ etc\ hosts file:
* through the above configuration, we have been able to share the server-side pressure by accessing www.taoge.com and accessing different tomcat. Session information cannot be lost during the request load. Then session needs to be shared in multiple tomcat.
* there are three solutions for configuring session sharing of Tomcat:
The first is the session sharing strategy provided by the load balancing server itself, the configuration of each service period is different and the nginx itself is not available.
The second is to configure sharing using the session sharing policy of the web container itself. For weblogic, this approach still depends on the general. However, there are great defects in this way of tomcat, mainly because the session replication is achieved by broadcasting, which will waste a lot of bandwidth and lead to the slow response of the whole network. The official website also recommends that this method should not exceed 4 tomcat. For details, please refer to / webapps/docs/cluster-howto.html for detailed instructions. The following is the specific configuration process
The third is the Session sharing configuration method of Tomcat cluster + redis.
Here we take the second way as an example:
Configure the sharing of session in Tomcat:
Step 1: modify the server.xml file. For the simplest cluster configuration, you only need to uncomment the following sentence that is commented out in the node:
Xml Code:
Clusters configured in this way will synchronize Session to all instances with cluster attributes configured on their network segment (here the network segment may be inaccurate and is distinguished by Membership's address and port. An instance of a tomcat cluster is assigned to the same cluster if the tomcat with the same address and port values in the Membership configuration. Their session is shared with each other, and a cluster with the same session is called a cluster. Multiple cluster can be configured, but the session between cluster and cluster is not shared. That is to say, if all Tomcat instances under this broadcast address share Session, then if there are several unrelated clusters, it may cause waste of Session replication, so you need to set more settings for nodes to avoid waste, as follows:
Xml Code:
[html] view plain copy
Add a Channel with a Membership in it. We should focus on the port property and address property of membership. Different clusters set different port or address values, which are basically isolated from current use.
Step 2: modify the web.xml file of the project:
The modification to the web.xml file is simple: you just need to add this node to the node.
OK, with these two steps, the cluster of Tomcat and the sharing of Session are realized.
This is the end of how to configure cluster load balancer in Nginx. I hope the above content can be helpful to 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.