In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to build a web cluster environment for Nginx and Tomcat". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I have always been very familiar with web server and tomcat, but I am still a little strange to nginx. When I see the configuration of nginx, there is an inexplicable repulsion. This is the fear of strangers. Let's play an interesting one today. I never know nginx, and it takes less than an hour to set up clusters with nginx and tomcat.
Look at the results of my study for one hour. It can't be said to be helpful to you.
First of all, nginx is a lightweight web server from Russia, open source free, and minimalist.
Its website is this: http://nginx.org/en/download.html
There are currently three types of downloaded versions, which are easy to understand, one is the current development version (Mainline version), and the second is the stable latest version, such as the latest version 1.12.2, active code package and windows version. The third category is nostalgic and stable version, not necessarily the online environment is up-to-date, but also taking into account the compatibility, it is more intimate.
One reason why nginx is so simple is that the installation package is really small enough, the compressed version is less than 1m, and the unzipped version is about 7m.
[root@localhost nginx] # ll
Total 960
-rw-r--r--. 1 root root 981687 Oct 18 13:14 nginx-1.12.2.tar.gz
It is relatively easy to install nginx, configure,make, make install, it is important to note that the installation requires several dependent packages, such as zlib,PCRE libraries, you can check in advance.
# rpm-qa | grep zlib
Zlib-1.2.3-29.el6.x86_64
Zlib-devel-1.2.3-29.el6.x86_64
The library of PCRE requires pcre-devel, which can be done by configuring the yum source using yum-y install pcre-devel.
# rpm-qa | grep pcre
Pcre-devel-7.8-7.el6.x86_64
Pcre-7.8-7.el6.x86_64
Summarize the three steps of installation:
. / configure-- prefix=/usr/local/nginx
Make
Make install
Add an extra option if you need to edit ssl.
The startup of nginx is really simple, you can start it directly with the nginx command, the default is to use port 80, and you will soon see a welcome page.
Of course, we can check port 80 through fuser, or check whether port 80 is occupied:
# fuser-n tcp 80
80/tcp: 21412 21413
Or:
# netstat-pan | grep-w 80
Tcp 0 0 0.0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0 of the LISTEN 21412/nginx.
Tcp 0 0127.0.0.1 TIME_WAIT-80 127.0.0.1 TIME_WAIT-
Tcp 0 0 192.168.253.219:57492 23.32.3.248:80 ESTABLISHED 21590/clock-applet
Tcp 0 192.168.253.219 TIME_WAIT 51678 60.221.218.180
Tcp 10:: ffff:192.168.253.21:39646:: ffff:104.25.106.17:80 CLOSE_WAIT 12329/java
Tcp 10:: ffff:192.168.253.21:37445:: ffff:104.25.107.17:80 CLOSE_WAIT 12329/java
If you look at nginx-related processes, you will find that there is a master, there is a worker process.
# ps-ef | grep nginx
Root 21412 1 0 22:39? 00:00:00 nginx: master process. / nginx
Nobody 21413 21412 0 22:39? 00:00:00 nginx: worker process
Root 21719 15134 0 22:43 pts/3 00:00:00 grep nginx
How to understand this part can be easily understood through the configuration file of nginx. In the nginx.conf file, you start with the following two lines. You can clearly see that there is one worker process with nobody configured, so the owner of the worker process you see is nobody
# user nobody
Worker_processes 1
This is the architecture of nginx. He uses epoll.
Nginx commands hardly require you to relearn, just use-h to get help commands. So it's easy to find that. / nginx-s stop is a stop command, enabling the configuration file to use the-c option.
In the sbin directory where nginx is located, a complete startup command is:
. / nginx-c / usr/local/nginx/conf/nginx.conf
Then let's see how to combine with tomcat, nginx is often used as http server, reverse proxy, mail server and so on. It is also a natural way to do load balancing. Let's do a simple simulation.
For example, the current backend server is tomcat. If you want to achieve load balancing, it is natural to forward it through nginx. If there is a problem with one of the tomcat, it can also easily meet the fault tolerance.
To do this, we need to configure several tomcat services to simulate, for example, we use three tomcat.
Drwxr-xr-x. 9 root root 4096 Jan 3 23:14 tomcat1
Drwxr-xr-x. 9 root root 4096 Jan 3 23:14 tomcat2
Drwxr-xr-x. 9 root root 4096 Jan 3 23:14 tomcat3
The default port is 8080, which is simply packaged. The ports of the three tomcat are:
18080
28080
38080
To modify the configuration file server.xml of tomcat, you need to pay attention to the following port settings, which are:
Tomcat1:
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.