An in depth Analysis of Tomcat Server of Centos 7 System

  • 2021-07-18 09:17:50
  • OfStack

Directory 1. Origin of tomcat 1. Application Scenario of Tomcat 2. Dependent software required by Tomcat 2. Configuration related description of Tomcat 1. Main directory of Tomcat 2. Configuration file description 3. Main configuration file description of Tomcat

1. The origin of tomcat

Name origin: tomcat was originally developed by James Duncan Davidson, software architect of Sun. He later helped turn it into an open source project, which Sun contributed to the Apache Software Foundation. Since most open source projects O 'Reilly will produce a related book and design its cover as a sketch of an animal, he hopes to name this project after an animal. Because he wanted the animal to take care of itself, he eventually named it tomcat (male cat).

1. Tomcat application scenario

Tomcat server is a free open source web application server, which belongs to lightweight application server. It is widely used in small and medium-sized systems and occasions where there are not many concurrent users, and is the first choice for developing and testing JSP programs. Generally speaking, although Tomcat, like web servers like apache or Nginx, has the function of processing HTML pages, its ability of processing static pages is far less than that of apache or Nginx, so Tomcat1 runs separately at the back end as a container of servlet and JSP.

2. Dependent software required by Tomcat

You must install JDK before installing Tomcat. JDK is a free software development kit in Java language provided by sun, which includes Java virtual machine (JVM). The Java source program can be compiled to form Java bytecode, so long as JDK is installed, these bytecode files can be interpreted by JVM, thus ensuring the cross-platform of Java.

In terms of platform compatibility, JDK, as an Java virtual machine that interprets bytecode files and calls API of the operating system to realize corresponding functions, is closely related to the type of operating system and the number of platform bits, so there are different types of versions, and Tomcat also has these characteristics. (Centos 7.0 has been installed by default, but Centos 6.0 needs to be installed by itself).

1) Check to see if JDK is installed


[root@centos02 ~]# java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

2) Centos 6.0 Installing JDK


[root@centos02 ~]# mount /dev/cdrom /mnt/ <!-- Mount Linux CD-ROM -->
mount: /dev/sr0  Write-protected, will be mounted read-only 
[root@centos02 ~]# tar zxvf /mnt/jdk-7u65-linux-x64.gz -C /usr/src/ 
  <!-- Decompression jdk Software package -->
[root@centos02 src]# ls
debug jdk1.7.0_65 kernels
[root@centos02 src]# mv jdk1.7.0_65/ /usr/src/java <!-- Installation JDK-->
[root@centos02 ~]# vim /etc/profile.d/java.sh<!-- Configure jdk Runtime environment variable -->
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
[root@centos02 ~]# chmod +x /etc/profile.d/java.sh<!-- Variable to add execution permission -->
[root@centos02 ~]# source /etc/profile.d/java.sh <!-- Run JDK-->

2. Description of Tomcat configuration

1. The main directory of Tomcat

The main directory of tomcat is/usr/local/tomcat8/.


[root@centos02 ~]# cd /usr/local/tomcat/
[root@centos02 tomcat]# ll
 Total dosage  96
drwxr-xr-x 2 root root 4096 11 Month  30 19:48 bin
drwxr-xr-x 3 root root 174 11 Month  30 20:03 conf
drwxr-xr-x 2 root root 4096 11 Month  30 19:48 lib
-rw-r--r-- 1 root root 56812 5 Month  20 2014 LICENSE
drwxr-xr-x 2 root root 197 11 Month  30 19:51 logs
-rw-r--r-- 1 root root 1192 5 Month  20 2014 NOTICE
-rw-r--r-- 1 root root 8974 5 Month  20 2014 RELEASE-NOTES
-rw-r--r-- 1 root root 16204 5 Month  20 2014 RUNNING.txt
drwxr-xr-x 2 root root 30 11 Month  30 19:48 temp
drwxr-xr-x 7 root root 81 5 Month  20 2014 webapps
drwxr-xr-x 3 root root 22 11 Month  30 19:51 work

The main catalogues are described as follows:

--bin/: Script files for starting and closing Tomcat on Windows or Linux platforms;
--conf/: Hosts various global configuration files for the Tomcat server, the most important of which are server. xml and web. xml;
--lib/: Store the library files needed for Tomcat operation;
--logs/: Store LOG file when Tomcat is executed;
--webapps: Tomcat's main web publishing directory (including application samples);
--work: store class file generated after JSP compilation;

2. Description of configuration file


[root@centos02 tomcat]# ll conf/
 Total dosage  200
drwxr-xr-x 3 root root 23 11 Month  30 19:51 Catalina
-rw------- 1 root root 12257 5 Month  20 2014 catalina.policy
-rw------- 1 root root 6294 5 Month  20 2014 catalina.properties
-rw------- 1 root root 1394 5 Month  20 2014 context.xml
-rw------- 1 root root 3288 5 Month  20 2014 logging.properties
-rw------- 1 root root 6610 11 Month  30 20:03 server.xml
-rw------- 1 root root 1530 5 Month  20 2014 tomcat-users.xml
-rw------- 1 root root 163385 5 Month  20 2014 web.xml

The configuration file is described as follows:

catalina. policy: Permission control configuration file;
catalina. properties: Tomcat property profile;
context. xml: Context configuration file;
logging. properties: Log log related configuration files;
server. xml: Master configuration file;
tomcat-users. xml: manager-gui management user profile (Tomcatt provides a management interface of manager-gui after installation, and access can be opened by configuring this file);
web. xml: servlet, servlet-mapping, filter, MIME and other related configurations of Tomcat;

3. Description of Tomcat main configuration file

server. xml is the main configuration file of Tomcat. By configuring this file, you can modify the startup port, website directory, virtual host of Tomcat, and open https and other important functions.

The whole server. xml consists of the following structures: < Server > , < Service > , < Connector / > < Engine > , < Host > , < Context > , < /Context > < /Host > < /Engine > < /Service > And < /Server > .

The following is part of the default installation of the server. xml file, where < !-- -- > Comment information when the contents within. The//begins with my own annotation:


[root@Centos01 tomcat8]# vim conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
............     // Omit part of the content 
<Server port="8005" shutdown="SHUTDOWN">  
//Tomcat Close the port, which is only open to the local address by default, and can pass through the local address Telnet 127.0.0.1 8005 Visit, 
// Right Tomcat Perform a shutdown operation 
............    // Some contents are omitted here 
 <Connector port="8080" protocol="HTTP/1.1"
  connectionTimeout="20000"
  redirectPort="8443" />
//Tomcat Default port number for startup 8080 Which can be changed as needed. 
............    // Some contents are omitted here 
 <!-- Define an AJP 1.3 Connector on port 8009 -->
 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
//Tomcat Start AJP 1.3 The default port number for connector, which can be changed as needed 
............     // Some contents are omitted here 
// The following are Tomcat Configuration and log configuration when defining virtual host 
<Host name="localhost" appBase="webapps"
  unpackWARs="true" autoDeploy="true">

 <!-- SingleSignOn valve, share authentication between web applications
  Documentation at: /docs/config/valve.html -->
 <!--
 <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
 -->

 <!-- Access log processes all example.
  Documentation at: /docs/config/valve.html
  Note: The pattern used is equivalent to using pattern="common" -->
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  prefix="localhost_access_log" suffix=".txt"
  pattern="%h %l %u %t "%r" %s %b" />

 </Host>
 </Engine>
 </Service>
</Server>

4. Description of components of Tomcat server

1) Server

The server element represents the servlet container for the entire CatAlina.

2) Service

An Service is a collection consisting of one or more Connector and one Engine (which handles all customer requests obtained by Connector).

3) Connector

An Connector listens for customer requests on a specified port, passes the obtained requests to Engine for processing, obtains a response from Engine and returns them to the customer.

Tomcat has two typical Connector, one listening directly for http requests from browser and one listening for requests from other webserver.

Coyote HTTP/1. 1 Connector listens for http requests from customer browser (browse) at port 8080.

Coyote JK2 Connector listens for servlet/jsp proxy requests from other text server (Apache) at port 8009.

4) Engine

Under Engine, you can configure multiple virtual hosts virtual host, and each virtual host has one domain name.
When an Engine gets a request, it matches the request to an Host and then passes the request to the host for processing.
The Engine has a default virtual host, and requests that cannot be matched to any of the 1 host are handed over to that default host for processing.

5) Host

Host stands for one virtual Host, that is, virtual hosts, and each virtual host matches a network domain name Domain Name.
One or more web app can be deployed under each virtual host, and each web app corresponds to one Context and one Context path.

When host gets a request, it will match the request to an Context, and then hand the request to the Context for processing. The matching method is "longest match", so an Context with path== "" will become the default Context of the Host.
All requests that do not match the pathnames of other Context will eventually match the default Context.

6) Context

One Context corresponds to one web application, and one web application consists of one or more servlet.

Summarize


Related articles: