In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Tomcat deployment part I. Preface
's previous article is about the two major server software in web: Apache and Nginx. Here, let's make a brief summary of this.
Characteristics and performance of 1.Apache and Nginx
Apache supports many modules with stable performance. Apache itself is static parsing, suitable for static HTML, pictures, etc., but it can support dynamic pages by extending scripts, modules, and so on. However, its configuration is relatively complex and does not support dynamic pages.
Nginx, a lightweight HTTP server, is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. It is characterized by less memory, strong concurrency, easy development and convenient deployment. Nginx supports multilingual universal servers. However, Nginx is only suitable for static and reverse proxies. Its advantage lies in supporting: load balancing, reverse proxy, dealing with static files. Nginx processes static requests faster than Apache (more than 3 times).
The difference between 2.Apache and Nginx
Apache is a synchronous multi-process model, where one connection corresponds to one process, while nginx is asynchronous, and multiple connections (ten thousand levels) can correspond to one process.
Nginx lightweight, anti-concurrency, good handling of static files
Apache is super stable, and it is relatively simple to support PHP. Nginx needs to be used with other backends, so it has advantages to deal with dynamic requests. It is recommended to use front-end nginx for anti-concurrency and back-end apache clusters for better cooperation.
2. What is the concept of Tomcat 1.Tomcat?
Tomcat is a core project of the Jakarta project of the Apache Software Foundation (Apache Software Foundation), which is jointly developed by Apache, Sun and other companies and individuals. Tomcat server is a free and open source Web application server, which is a lightweight application server.
Tomcat is an application (Java) server, it is just a Servlet (JSP is also translated into Servlet) container, can be thought of as an extension of Apache, but can be run independently of Apache.
two。 Why do I need Tomcat?
should be familiar with Tomcat for those who have studied or are learning Java.
's latest Servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because of its advanced technology, stable performance and free, Tomcat is deeply loved by Java enthusiasts and recognized by some software developers, and has become a popular Web application server.
The advantage of is that it is a dynamic parsing container, handles dynamic requests, and is a container for compiling JSP/Servlet. Its disadvantage is also very obvious, it can only be a Java server, and there is a limit in the amount of concurrency.
As for the deeper reasons for , we need to have some architectural ideas in order to deeply understand and summarize the differences and relations among Apache, Nginx and Tomcat. The core of this article is for beginners, mainly explain the deployment process of Tomcat, so we will not repeat the deeper reasons here, but we must know that "no matter what, what exists is reasonable, and all we have to do is to see the essence through the phenomenon!"
Third, the core components of Tomcat
Tomcat is a sub-project under Apache, which has all the functions of Web server. It can not only listen to accept requests and respond to static resources, but also run Java code Servlet of specific specifications in the back end, and write the results back to the client in the form of HTML code.
Three core components of Tomcat: Web container, Servlet container and JSP container
Web container: complete the function of Web server; Servlet container: the name is catalina, which is used to process Servlet code; JSP container: used to translate JSP dynamic web pages into Servlet code. 4. Tomcat processing request process
1) the request is sent to local port 8080 and is obtained by the Coyote HTTP/11.1 Connector (connector) listening there.
2) Connector hands the request to the Engine (engine) of the Service where it is located and waits for a response from Engine.
3) Engine gets the request localhost/yy/index.JSP, which matches all the virtual host Host it owns
The Engine matches to a Host named localhost. The request is handed over to the Host for processing even if there is no match, because the Host is defined as the default host for the Engine.
4) localhost Host gets the request / yy/index.JSP, which matches all the Context it owns
The Host matches to the Context with the path / yy. If there is no match, the request is handed over to the Context with the path name "" for processing.
5) the Context of path= "/ yy" gets the request / index.JSP and looks for the corresponding Servlet in its mapping table.
The Context matches to the Servlet whose URL PATTERN is * .JSP, corresponding to the JSPServlet class.
6) construct the HttpServletRequest object and the HttpServletResponse object, and call the doGet () or doPost () method of JSPServlet as parameters.
7) Context returns the HttpServletResponse object after execution to Host.
8) Host returns the HttpServletResponse object to Engine.
9) Engine returns the HttpServletResponse object to Connector.
10) Connector returns the HttpServletResponse object to the customer browser.
Perhaps after reading the above process, I feel that it is too complicated. Here is a specific flow chart, which you can logically understand according to the flow chart:
Connector connectors and container containers
Connector is used to receive the request and encapsulate it into Request and Response for specific processing. (the bottom layer uses Socket to connect) where Request and Response are encapsulated according to HTTP protocol, so Connector implements both TCP/IP protocol and HTTP protocol. Request and Response are encapsulated and handed over to Container for processing. Container is the container of Servlet, and Container is returned to Connector after processing. Finally, Connector uses Socket to return the processing result to the client. In this way, the entire request is processed, and the specific request process is shown in the figure above.
and Container is the interface of the container in Tomcat, and the commonly used Servlet is encapsulated in its subinterface Wrapper. (Container has a total of four subinterfaces Engine, Host, Context, Wrapper and a default implementation class ContainerBase, each of which is a container, each of which has a corresponding StandardXXX implementation class, and these implementation classes all inherit the ContainerBase class. In addition, Container also inherits the Lifecycle interface, and ContainerBase inherits LifecycleBase indirectly, so the four sub-containers Engine, Host, Context, and Wrapper all conform to the Tomcat lifecycle management model mentioned earlier. )
5. Operation flow of Tomcat deployment
Required environment:
System version: Centos7Tomcat version: 9.0.8jdk version: 1.8.0x201 server ip address: 192.168.68.145
Specific steps for deployment:
1. First of all, you need the following two packages
[root@localhost tomcat] # ls
Apache-tomcat-9.0.16.tar.gz jdk-8u201-linux-x64.rpm
Package link: https://pan.baidu.com/s/1q9igHqlkIVJtqRS8zbuibQ
Extraction code: xzaj
two。 Install JDK [root @ localhost tomcat] # rpm-ivh jdk-8u201-linux-x64.rpm warning: jdk-8u201-linux-x64.rpm: header V3 RSA/SHA256 Signature Key ID ec551f03: NOKEY preparation. # # [100%] upgrading / installing... 1:jdk1.8-2000:1.8.0_201-fcs # # [100%] Unpacking JAR files... Tools.jar... Plugin.jar... Javaws.jar... Deploy.jar... Rt.jar... Jsse.jar... Charsets.jar... Localedata.jar... [root@localhost tomcat] # cd / usr/java/ [root@localhost java] # lsdefault jdk1.8.0_201-amd64 latest [root@localhost java] # cd jdk1.8.0_201-amd64/ [root@localhost jdk1.8.0_201-amd64] # lsbin lib src.zipCOPYRIGHT LICENSE THIRDPARTYLICENSEREADME-JAVAFX.txtinclude man THIRDPARTYLICENSEREADME.txtjavafx-src.zip README.htmljre release
Bin/: command file storage directory
Virtual machine storage location of jre/:jvm
Lib/: function library directory
Src.zip/: source code compressed package directory
3. Set the environment variable (system environment variable / etc/profile) 3.1 View the current path Check out the jdk original [root@localhost jdk1.8.0_201-amd64] # pwd/usr/java/jdk1.8.0_201-amd64 [root@localhost jdk1.8.0_201-amd64] # java-version # simplified version of jdk is originally integrated in Centos7 openjdk version "1.8.0mm 131" OpenJDK Runtime Environment (build 1.8.0_131-b12) OpenJDK 64-Bit Server VM (build 25.131-b12) Mixed mode) [root@localhost jdk1.8.0_201-amd64] # 3.2 set the environment variable [root@localhost jdk1.8.0_201-amd64] # vim / etc/profile [root@localhost jdk1.8.0_201-amd64] # source / etc/profile [root@localhost jdk1.8.0_201-amd64] # tail-3 / etc/profile # added content export JAVA_NAME=/usr/java/jdk1.8.0_201-amd64 # work path export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar # location of class files export PATH=$JAVA_NAME/bin:$PATH # command file [root@localhost jdk1.8.0_201-amd64] # java # proves that source is successful java javafxpackager javapackager javaws.itwebjavac javah java-rmi.cgi javadoc javap Javaws [root@localhost jdk1.8.0_201-amd64] # java-versionjava version "1.8.0mm 201" Java (TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot (TM) 64-Bit Server VM (build 25.201-b09 Mixed mode) [root@localhost jdk1.8.0_201-amd64] # 4. Install Tomcat [root @ localhost tomcat] # lsapache-tomcat-9.0.16.tar.gz jdk-8u201-linux-x64.rpm [root@localhost tomcat] # tar zxf apache-tomcat-9.0.16.tar.gz-C / opt [root@localhost tomcat] # cd / opt/ [root@localhost opt] # lsapache-tomcat-9.0.16 rh [root@localhost opt] # mv apache-tomcat-9.0.16/ tomcat [root@localhost opt] # lsrh tomcat [root@localhost opt] # cd tomcat/ [root@localhost tomcat] # lsbin CONTRIBUTING.md logs RELEASE-NOTES webappsBUILDING.txt lib NOTICE RUNNING.txt workconf LICENSE README.md temp
Where webapps is the site
5. Optimize the startup and shutdown script Turn on and off operation [root@localhost tomcat] # cd bin/ [root@localhost bin] # lsbootstrap.jar makebase.shcatalina.bat setclasspath.batcatalina.sh setclasspath.shcatalina-tasks.xml shutdown.batciphers.bat shutdown.shciphers.sh startup.batcommons-daemon.jar startup.shcommons-daemon-native .tar.gz tomcat-juli.jarconfigtest.bat tomcat-native.tar.gzconfigtest.sh tool-wrapper.batdaemon.sh tool-wrapper.shdigest.bat version.batdigest.sh version.shmakebase.bat [root@localhost bin] # ln-s / opt/tomcat/bin/startup.sh / usr/bin [root@localhost bin] # ln -s / opt/tomcat/bin/shutdown.sh / usr/bin [root@localhost bin] # systemctl stop firewalld.service [root@localhost bin] # setenforce 0 [root@localhost bin] # startup.sh # enable the service Using CATALINA_BASE: / opt/tomcatUsing CATALINA_HOME: / opt/tomcatUsing CATALINA_TMPDIR: / opt/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / opt/tomcat/bin/ Bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jarTomcat started. [root@localhost bin] # netstat-antp | grep 8080tcp6 0: 8080: * LISTEN 47064/java [root@localhost bin] # shutdown.sh Using CATALINA_BASE: / opt/tomcatUsing CATALINA_HOME: / opt/tomcatUsing CATALINA_TMPDIR: / opt/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar [root@localhost bin] # netstat-antp | grep 8080tcp6 0 0:: 1 antp 39678:: 1 netstat 8080 TIME_WAIT-6. Test verification
When we open the Tomcat service, we can use "IP address: 8080" in the browser to access it, as shown in the following figure
VI. Summary
this article mainly combines the previous Apache and Nginx, a simple comparison between the two, summed up, which leads to the Tomcat application server, describes its concept, its own characteristics and three core components: three containers (Web, JSP, Servlet), then uses a simple flow chart to describe in detail the Tomcat request processing process, and finally gives how to install, deploy, test Tomcat server, thank you for reading!
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.