Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS7 system deployment and installation of Tomcat services (theory + practice)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Tomcat introduction

Since the release of JSP, a variety of JSP engines have been launched. After completing the development of GNUJSP1.0, Apache Group began to consider developing a JSP server that can provide Web services directly on the basis of SUN's JSWDK. Of course, it also supports Servlet, so Tomcat was born.

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. It was selected by the editors of JavaWorld magazine as the most innovative Java product in 2001. at the same time, it is also the Servlet and JSP container officially recommended by sun, so it is more and more popular among software companies and developers. With the participation and support of Sun, the 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.

Tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs. For a beginner, it can be thought that when an Apache server is configured on a machine, it can be used to respond to requests for access to HTML (an application under the standard general markup language) pages. In fact, Tomcat is an extension of the Apache server, but at run time it runs independently, so when running Tomcat, it actually runs as a separate process from Apache.

When configured correctly, Apache serves the HTML page, while Tomcat actually runs the JSP page and Servlet. In addition, like Web servers such as IIS, Tomcat has the function of dealing with HTML pages, and it is also a Servlet and JSP container, and a separate Servlet container is the default mode of Tomcat. However, Tomcat is not as capable of handling static HTML as Apache servers.

2. Tomcat core components

Usually, after accepting the request, the Web server simply responds to static resources, such as HTML files, picture files, etc., and can not carry out certain processing operations in the back end. 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.

Tomcat consists of a series of components, of which there are three core components: 1) Web container: complete the function of Web server. 2) Servlet container: the name is catalina, which is used to process Servlet code. 3) JSP container: used to translate JSP dynamic web pages into Servlet code. 3. Tomcat processing request process 1. The user enters the URL localhost:8080/test/index.jsp in the browser, and the request is sent to local port 8080, which is obtained by the Coyote HTTP/1.1 Connector listening there; 2.Connector hands the request to the Engine (Container) of the Service where it is located, and waits for the response from Engine; 3.Engine gets the request localhost/test/index.jsp, which matches all virtual hosts Host The 4.Engine matches a Host named localhost (even if it doesn't match, the request is handed over to the Host for processing, because the Host is defined as the default host for the Engine), and the Host named localhost gets the request / test/index.jsp, matching all the Context it owns. The Host matches to the Context with the path / test (if there is no match, the request is handed over to the Context with the path name ""); 5. The Context with path = "/ test" gets the request / index.jsp and finds the corresponding Servlet in its mapping table. Context matches to the Servlet whose URL Pattern is * .jsp, corresponding to the JspServlet class; 6. Construct HttpServletRequest object and HttpServletResponse object, call doGet () or doPost () of JspServlet as parameters to execute business logic, data storage, etc.; 7.Context returns the HttpServletResponse object after execution to Host;8.Host, HttpServletResponse object to Engine;9.Engine, HttpServletResponse object to Connector;10.Connector, HttpServletResponse object to customer Browser. 4 、 Tomcat directory structure [root@localhost] # ll / usr/local/tomcat/ Total usage 124drwxr root-2 root root 4096 March 7 22:34 bin-rw-r- 1 root root 19203 February 5 00:32 BUILDING.txtdrwx- 3 root root 254 March 7 22:36 conf-rw-r- 1 root root 6095 February 5 00:32 CONTRIBUTING.mddrwxr-x--- 2 root root 4096 March 7 22 34 lib-rw-r- 1 root root 57092 February 5 00:32 LICENSEdrwxr-x--- 2 root root 197 March 7 22:36 logs-rw-r- 1 root root 2333 February 5 00:32 NOTICE-rw-r- 1 root root 3255 February 5 00:32 README.md-rw-r- 1 root root 6854 February 5 00:32 RELEASE-NOTES-rw-r- 1 root Root 16262 February 5 00:32 RUNNING.txtdrwxr-x--- 2 root root 30 March 7 22:34 tempdrwxr-x--- 7 root root 81 February 5 00:31 webappsdrwxr-x--- 3 root root 22 March 7 22:36 work -● bin stores script files for starting and shutting down Tomcat The more commonly used files are catalina.sh, startup.sh and shutdown.sh. ● conf stores various configuration files of the Tomcat server, and the more commonly used files are server.xml, context.xml, tomcat-users.xml and web.xml. ● lib stores the jar package of the Tomcat server and generally does not make any changes. Unless you connect to a third-party service, such as redis, you need to add the corresponding jar package ● logs to store Tomcat logs, ● temp, the directory where ● webapps stores project resources, and the ● workTomcat working directory. Generally, when clearing Tomcat cache, you will use 5. Tomcat deployment step (1) host to share the required toolkit.

(2) Mount the toolkit and install JDK

Jdk must be installed before deploying Tomcat, because jdk is a necessary environment for Tomcat to run.

[root@localhost ~] # mkdir / mnt/tools [root@localhost ~] # mount.cifs / / 192.168.100.50/tools / mnt/tools # Mount shared files to the Linux local directory Password for root@//192.168.100.50/tools: [root@localhost ~] # cd / mnt/tools/tomcat/ # enter the local directory to view [root@localhost tomcat] # ls12D18CFCD6599AFF0445766ACC4CA231C5025773.torrent apache-jmeter-5.1.zip jdk-8u201 -linux-x64.rpmapache-jmeter-5.1 apache-tomcat-9.0.16.tar.gz tomcat optimized stress test. JMX [root@localhost tomcat] # rpm-ivh jdk-8u201-linux-x64.rpm # installation JDK (3) set environment variable / etc/profile file [root@localhost tomcat] # cd / usr/java/jdk1.8.0_201-amd64/ [root@localhost jdk1.8.0 _ 201-amd64] # pwd/usr/java/jdk1.8.0_201-amd64 # confirm the directory path of the JDK installation [root@localhost jdk1.8.0_201-amd64] # vim / etc/profile# append three declaration entries export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64# declaration java working directory export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar# declaration to the last line of the file Location of the java class file export PATH=$JAVA_HOME/bin:$PATH# declares that the java environment variable [root@localhost jdk1.8.0_201-amd64] # source / etc/profile # takes effect the environment variable [root@localhost jdk1.8.0_201-amd64] # [root@localhost jdk1.8.0_201-amd64] # java-version # View version java version "1.8.0i201" 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 and start the Tomcat service [root@localhost jdk1.8.0_201-amd64] # cd / mnt/tools/tomcat/ [root@localhost tomcat] # tar zxvf apache-tomcat-9.0.16.tar.gz-C / usr/local/# extract the tomcat package to the / usr/local/ directory [root@localhost tomcat] # cd / usr/local/ [root@localhost local] # mv apache-tomcat -9.0.16 / tomcat # rename the apache-tomcat-9.0.16 file to tomcat [root@localhost local] # lsbin etc games include lib lib64 libexec sbin share src tomcat [root@localhost local] # [root@localhost local] # cd tomcat/bin/ # switch to the bin directory under the tomcat directory Here is the script to control the tomcat service [root@localhost bin] # lsbootstrap.jar ciphers.bat configtest.bat digest.sh setclasspath.sh startup.sh tool-wrapper.shcatalina.bat ciphers.sh configtest.sh makebase.bat shutdown.bat tomcat-juli.jar version.batcatalina.sh commons-daemon.jar Daemon.sh makebase.sh shutdown.sh tomcat-native.tar.gz version.shcatalina-tasks.xml commons-daemon-native.tar.gz digest.bat setclasspath.bat startup.bat tool-wrapper.bat [root@localhost bin] # ln-s / usr/local/tomcat/bin/startup.sh / usr/bin/# create the soft link of the tomcat startup script to the system directory It is convenient for the system to identify [root@localhost bin] # ln-s / usr/local/tomcat/bin/shutdown.sh / usr/bin/# to create the soft link of the tomcat shutdown script to the system directory It is convenient for the system to identify [root@localhost bin] # startup.sh # start the tomcat service Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started. [ Root@localhost bin] # systemctl stop firewalld.service # turn off firewall [root@localhost bin] # setenforce 0 # turn off enhanced security [root@localhost bin] # netstat-ntap | grep 8080 # View the status of port 8080 of tomcat service tcp6 0:: 8080: * LISTEN 52230/java [root@localhost bin] # (5) Browse the default home page of Tomcat and enter http://192.168.52.132:8080 in the browser to access the web page

(6) optimize Tomcat startup time [root@localhost bin] # cd / usr/java/jdk1.8.0_201-amd64/jre/lib/security/ [root@localhost security] # lsblacklist blacklisted.certs cacerts java.policy java.security javaws.policy policy trusted.libraries [root@localhost security] # vim java.security # modify java.security parameter securerandom.source=file:/dev/urandom# to retrieve random parameter entry and modify random to urandom To shorten startup time [root@localhost security] # startup.sh # start the service again The startup time is significantly shortened by Using CATALINA_BASE: / usr/local/tomcatUsing CATALINA_HOME: / usr/local/tomcatUsing CATALINA_TMPDIR: / usr/local/tomcat/tempUsing JRE_HOME: / usr/java/jdk1.8.0_201-amd64Using CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report