Getting started with tomcat

1. Version issue
Tomcat 8 or 8.5 should be used with JDK version 7.0 or higher

Tomcat is a servelet container developed by the Jakarta project under the Apache Software Foundation. It was developed in accordance with the technical specifications provided by Sun Microsystems. Tomcat 8 supports servlet 3.1 and Javaserver page 2.3 (JSP) and provides it as a web server Some unique functions of Tomcat, such as Tomcat management and control platform, security domain management and Tomcat add-ons, etc.

2. Tomcat installation
1).

 [root@tomcat ~]# tar xf jdk-8u60-linux-x64.tar.gz
[root@tomcat ~]# mv jdk1.8.0_60/ /usr/local/java8
[root@tomcat ~]# vim /etc/profile.d/java.sh
[root@tomcat ~]# cat /etc/profile.d/java.sh
JAVA_HOME=/usr/local/java8
CLASSPATH=$JAVA_HOME/lib
PATH=$PATH:$JAVA_HOME/bin
[root@tomcat ~]# source /etc/profile
[root@tomcat ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

2).

[root@tomcat ~]# tar xf apache-tomcat-8.5.16.tar.gz
[root@tomcat ~]# mv apache-tomcat-8.5.16 /usr/local/tomcat
启动并测试
[root@tomcat ~]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

Add 8080 port when accessing ip
Insert picture description here
3.tomcat architecture

1).
Insert picture description here
One tomcat has only one server, one server contains multiple services, and one service contains two core components (connectors, containers). There can be multiple connectors and only one container.
Connector: connector handles connection-related matters, and provides conversion between Socket and Request and Response.
Container: Contaioner encapsulates and manages Servlet, and specifically processes Request requests. The
entire tomcat life cycle is controlled by the server.

2
Insert picture description here
).connector structure 3).container structure

Insert picture description here
host: site context: application wrapper: package servlet

4).container processing flow: pipeline-value pipeline processing.

4.connector operating mode

(No NIO2)----8.0----(BIO,NIO,NIO2/AIO, APR)----8.5----(No BIO)—
*
BIO: Synchronous blocking
*
NIO: Synchronous non-blocking
*
NIO2/AIO: Asynchronous and non-blocking

* 

Tomcat uses NIO by default to view through grep -i handler catalina.out (/usr/local/tomcat/log/)

Insert picture description here
It is also possible to view with three buttons in the browser.

The use of buttons requires modification of the configuration file.

vim /usr/local/tomcat/conf/tomcat-users.xml
  <role rolename="manager-gui"/> //对应第二个按钮权限
  <role rolename="admin-gui"/>   //对应第三个按钮权限
  <user username="tomcat" password="tomcat" roles="tomcat,manager-gui,admin-gui"/>

403 modification method appears in version 8.5

Add the following contents to /usr/local/tomcat/conf/Catalina/localhost/manager.xml and /usr/local/tomcat/conf/Catalina/localhost/host-manager.xml respectively, corresponding to each

<?xml version="1.0" encoding="UTF-8"?>
<Context privileged="true" antiResourceLocking="false"
         docBase="${catalina.home}/webapps/manager">
    <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

Restart service

cd /usr/local/tomcat/bin/startup.sh

5.
JVM JVM can be regarded as a virtual operating system to some extent, it has its own memory model, etc.; starting a Tomcat container is equivalent to starting a process in the JVM.

Insert picture description here
The heap is the largest piece of memory managed by the virtual machine, and it is also a memory area shared by all threads.

When the memory is insufficient to complete the instance allocation, and the push cannot be expanded at the same time, there will be OOM (out of memory) memory overflow in addition to the program counter.

Memory problems caused the home page to be missing and the next page to be missing.

Solution: modify/usr/local/tomcat/bin/catalina.shJAVA_OPTS=" -server -Xms512m -Xmx512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m"

Note:
The initial size of the Xms heap memory depends on the physical memory, usually half of the
Xmx heap memory upper limit, depending on the physical memory, usually half
XX:MetaspaceSize: initial size of non-heap memory
XX:MaxMeatespaceSize non-heap memory upper limit

6. Memory leak: unused memory is not released. Memory leak >>> garbage collection (gc) cannot be recovered >>> pid is occupied, and there are many threads >>> tomcat cannot be connected remotely (use jstack to view and solve)

7.nginx do load balancing polling tomcat configuration
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_39109226/article/details/111107273