Tomcat deployment and optimization

Table of contents

1.Tomcat overview

      1.1 Component composition of TomcatEdit

      1.2 Tomcat functional component structure

      1.3 Tomcat's request process

2. Deployment of Tomcat service 

2.1 Build the Tomcat operating environment

 3. Set JDK environment variables​

 3.1 Test java environment

4. Install and start Tomcat


1.Tomcat overview

Tomcat is a lightweight application server developed based on the Java language. It is widely used in small and medium-sized systems and occasions where there are not many concurrent access users. It is the first choice for developing and debugging JSP programs. Generally speaking, although Tomcat has the same function as web servers such as Apache or Nginx, it has the function of processing HTML pages. However, because its ability to process static HTML is far less than that of Apache or Nginx, Tomcat is usually used as a Servlet and JSP container. rear end.
 

1.1 Component composition of Tomcat

 (1) Web container: complete the function of the 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 codes.

 Tomcat is a Web application server and a Servlet/JSP container. As a Servlet container, Tomcat is responsible for processing client requests, sending requests to Servlets, and sending Servlet responses back to clients.

1.2 Tomcat functional component structure

There are two core functions of Tomcat, the Connector responsible for receiving and feeding back external requests , and the Container responsible for processing requests . Among them, the connector and the container complement each other and together constitute the basic web service Service. Each Tomcat server can manage multiple Services.

 Service: Web service provided externally. It mainly includes two core components,  Connector  and  Container  , as well as other functional components. Tomcat can manage multiple services, and each service is independent of each other.

●Connector: Responsible for receiving and responding to external requests. It is the communication hub between Tomcat and the outside world. The listening port receives external requests, processes the requests and passes them to the container for business processing, and finally responds to the outside world with the processed results of the container.

●Container: Responsible for internal processing of business logic. It is composed of four containers, Engine, Host, Context and Wrapper, which are used to manage and invoke Servlet-related logic. Each Service will contain a Container container. There are 4 sub-containers inside the Container, and the functions of the 4 sub-containers are:

(1) Engine : Engine, used to manage multiple virtual hosts, a Service can only have one Engine at most

(2) Host : represents a virtual host, which can also be called a site, and a site can be added by configuring the Host; 

(3) Context : represents a Web application, including multiple Servlet wrappers;

(4) Wrapper : wrapper, the bottom layer of the container. Each Wrapper encapsulates a Servlet, which is responsible for the creation, execution and destruction of object instances. 

 Engine, Host, Context, and Wrapper , these four containers belong to a progressive parent-child relationship .

1.3 Tomcat's request process

  • The user enters the URL in the browser, and the request is sent to the local port 8080, and is obtained by the Connector listening there;
  • The Connector hands over the request to the Engine (Container) of the Service where it is located, and waits for the Engine's response
  • The request is called layer by layer among the four containers of Engine, Host, Context, and Wrapper, and finally executes the corresponding business logic, data storage, etc. in the Servlet
  • After execution, the request response is returned layer by layer between the Context, Host, and Engine containers, and finally returned to the Connector, and then returned to the client through the Connector.

2. Deployment of Tomcat service 

The version installation package prepared for this deployment (version according to requirements)jdk-8u371--linux-x64.rpm (jdk environment package, which is the operating environment of tomcat)         apache-tomcat-8.5.16.tar.gz (tomcat service software Bag)

2.1 Build the Tomcat operating environment 

(1) The software package is installed in the /opt directory

 rpm -qpl jdk-8u371-linux-x64.rpm 

 rpm -ivh jdk-8u371-linux-x64.rpm

 java -version

 3. Set JDK environment variables

 

vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin:$PATH

source /etc/profile.d/java.sh
java -version
 /etc/profile

  • tips:

  • CLASSPATH: When compiling and running a Java program, JRE will search for the required class (.class) file in the path specified by this variable.
  • dt.jar: It is a class library about the running environment, mainly a visual swing package.
  • tools.jar: mainly class libraries of some jdk tools, including javac, java, javap (a decompilation tool that comes with jdk), javadoc, etc.
  • JDK: java development kit (java development tools)
  • JRE: java runtime environment (java runtime environment)
  • JVM: java virtuak machine (java virtual machine), so that java programs can run class files on multiple platforms.

 3.1 Test java environment

First, use a text tool to write the java source code, such as Hello.java;
in the command line, enter the command: javac Hello.java to compile the source code and generate a class bytecode file;
after the compilation is completed, if there is no error message, enter Command: java Hello, run the class bytecode file, the JVM interprets and runs the bytecode, and prints "Hello World".

vim Hello.java
public class Hello {			
  public static void main(String[] args){
    System.out.println("Hello world!");
  }
}

javac Hello.java
java Hello

 #Class name, interface name command: English uppercase and lowercase letters, numeric characters, $ and _, keywords and numbers cannot be used at the beginning; when
a word is named, the first letter of the first word should be capitalized; when multiple words are formed, all words Capitalize the first letter: XxxYyyZzz (Upper CamelCase)

4. Install and start Tomcat

cd /opt
tar zxvf apache-tomcat-8.5.16.tar.gz
mv apache-tomcat-8.5.16.tar.gz /usr/local/tomcat

##Start tomcat ##
#Background start

/usr/local/tomcat/bin/startup.sh 
or
/usr/local/tomcat/bin/catalina.sh start

 #Foreground start

/usr/local/tomcat/bin/catalina.sh run

 netstat -natp | grip 8080

Browser accesses Tomcat's default homepage http://192.168.80.100:8080

 

Guess you like

Origin blog.csdn.net/Sp_Tizzy/article/details/131475629