Tomcat server of Centos 7 system

Keywords: Linux Tomcat xml Java JDK

I. The Origin of tomcat

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

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 concurrent users in many occasions, and is the first choice for developing and testing JSP programs. Generally speaking, Tomcat, like apache or Nginx web servers, has the ability to process HTML pages, but its ability to process static pages is far less than that of apache or Nginx, so Tomcat is generally used as a servlet and JSP container, running on the back-end alone.

2. Dependent software required by Tomcat

Before installing Tomcat, you must install JDK, which is a free Java language software development kit provided by sun company, including Java virtual machine (JVM). The compiled Java source program can form Java bytecode. As long as JDK is installed, the JVM can be used to interpret these code files, so as to ensure the cross platform of Java.

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

1) check whether 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) install JDK in Centos 6.0

[root@centos02 ~]# Mount / dev / CDROM / MNT / <! -- mount Linux CD -- >
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_ / / usr / SRC / Java <! -- install JDK -- >
[root@centos02 ~]# VIM / etc / profile.d/java.sh <! -- configure jdk running environment variable -- >
export  JAVA_HOME=/usr/local/java
export  PATH=$PATH:$JAVA_HOME/bin
[root@centos02 ~]# Chmod + X / etc / profile. D / Java. Sh <! -- variable add execution permission -- >
[root@centos02 ~]# Source / etc / profile.d/java.sh <! -- run JDK -- >

II. Configuration of Tomcat

1. Tomcat's main directory

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 3019:48 bin
drwxr-xr-x 3 root root   174 11 Month 3020:03 conf
drwxr-xr-x 2 root root  4096 11 Month 3019:48 lib
-rw-r--r-- 1 root root 56812 5 Month 202014 LICENSE
drwxr-xr-x 2 root root   197 11 Month 3019:51 logs
-rw-r--r-- 1 root root  1192 5 Month 202014 NOTICE
-rw-r--r-- 1 root root  8974 5 Month 202014 RELEASE-NOTES
-rw-r--r-- 1 root root 16204 5 Month 202014 RUNNING.txt
drwxr-xr-x 2 root root    30 11 Month 3019:48 temp
drwxr-xr-x 7 root root    81 5 Month 202014 webapps
drwxr-xr-x 3 root root    22 11 Month 3019:51 work

The main contents are as follows:

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

2. Profile description

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

The profile description is as follows:

  • catalina.policy: permission control configuration file;
  • catalina.properties: Tomcat property configuration file;
  • context.xml: context configuration file;
  • logging.properties: log related configuration files;
  • server.xml: main configuration file;
  • Tomcat users. XML: Manager GUI management user profile (after Tomcat installation, a manager GUI management interface is provided, which can be accessed through configuration);
  • web.xml: Tomcat's servlet, servlet mapping, filter, MIME and other related configurations;

3. Tomcat main configuration file description

server.xml is the main configuration file of Tomcat. By configuring this file, you can modify Tomcat's start port, website directory, virtual host, enable 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 content of the default installation server.xml file, where the content in <! --- > is annotated. //The number begins with my own comment:

[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 closes the port, which is only open to the local address by default, and can be accessed locally through telnet 127.0.0.1 8005,
//Shut down Tomcat
............                               //Some contents are omitted here
 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
//The default port number of Tomcat startup is 8080, which can be changed as required.
............                             //Some contents are omitted here
 <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
//The default port number when Tomcat starts AJP 1.3 connector, which can be changed as needed
............                                 //Some contents are omitted here
//The following is the configuration and log configuration when Tomcat defines a 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

A Service is a collection of one or more connectors, as well as an Engine (responsible for handling all customer requests received by connectors).

3)Connector

A Connector listens for customer requests on a specified port, hands the obtained requests to the Engine for processing, gets the response from the Engine and returns it to the customer.

  • Tomcat has two typical connectors, one directly listens for http requests from the browser, and the other listens for requests from other web servers.

  • The coyote http / 1.1 connector listens on port 8080 for HTTP requests from the customer browser.

  • Coyote JK2 connector listens on port 8009 for servlet/jsp proxy requests from other text server s (Apache).

4)Engine

Under Engine, you can configure multiple virtual host s, each of which has a domain name.
When the Engine gets a request, it matches the request to a host, and then hands the request over to the host for processing.
Engine has a default virtual host. When the request cannot be matched to any host, it will be handed over to the default host for processing.

5)Host

Host represents a virtual Host, that is, a virtual Host. Each virtual Host matches a network Domain Name domain name.
One or more web apps can be deployed under each virtual host. Each web app corresponds to a Context and has a Context path.

  • When the host obtains a request, it will match the request to a Context, and then submit the request to the Context for processing. The matching method is "longest match", so a Context with path = = "" will become the default Context of the host.

All requests that cannot match the pathnames of other contexts will eventually match the default Context.

6)Context

A Context corresponds to a web application. A web application consists of one or more servlet s.

——————Thank you for reading——————

Posted by qartis on Mon, 02 Dec 2019 22:30:28 -0800