Tomcat9.x configuration specification

1.  Tomcat9.X use

tomcat There are two versions, Compact and install version

Compact: simple and convenient, the official website after extracting downloaded directly after use. To start the command to start.

Installation version: to be installed, the installation will be automatically registered for the service, you can set the boot from the start in the service.

2.  Tomcat directory structure

 

(1) bin: mainly used to store commands, .bat is the next windows, .sh is under Linux

( 2) conf: mainly used to store configuration files of tomcat

(3) lib: store some of the jar package dependent tomcat

( 4) logs: tomcat store log files generated during operation

( 5) the TEMP: temporary files are stored runtime

(6) webapps: storage applications

( 7) Work: store the compiled files tomcat runtime, such as the JSP file compiled

3.  Tomcat three deployment mode

The first: simply copy the web project files to tomcat's webapps directory.

The second: In the local tomcat's conf directory, the new Catalina / localhost directory (Here we note that the case file names), then create a new xml file in the directory, the name can not be free to take to the path and name the same, I should be here jstore.xml file, its specific content:

<Context docBase="C:\work\jstore\web" path="/jstore" reloadable="true"/>

Third: server.xml file under the tomcat conf directory, add a context in <Host /> node, specifically:

 

4.  Tomcat configuration and optimization

4.1. Connector connector , is mainly responsible for Tomcat to communicate with the client ,  in /conf/server.xml file

Connector default configuration , FIG.

 

Connector parameters and optimization instructions

 

. 4.2 Protocol threads protocol configuration:

HTTP / 1.1: default protocol used with the version of Tomcat. In Tomcat9, by default automatically selected using the NIO or APR (APR native libraries if needed to find, use the APR, or use NIO)

org.apache.coyote.http11.Http11Protocol:BIO

org.apache.coyote.http11.Http11NioProtocol:NIO

org.apache.coyote.http11.Http11Nio2Protocol:NIO2

org.apache.coyote.http11.Http11AprProtocol:APR

Performance Comparison In most cases , apr> NiO> Bio

Configuration, FIG.

 

. 4.3 Connector thread pool configuration:

 

 

 

 

 

Executor's main attributes include:

name: Mark the thread pool

maxThreads: The maximum number of active threads in the thread pool, the default value of 200 (Tomcat7 and 8 are)

minSpareThreads: minimum number of threads in the thread pool to maintain, minimum is 25

maxIdleTime: The maximum idle time for a thread, the thread closed when idle for more than the value (unless the number of threads less than minSpareThreads), units of ms, whereas the default value of 60000 (1 minute)

daemon: whether the background thread, the default value true

threadPriority: thread priority, the default value of 5

namePrefix: Prefix the name of the thread, the thread pool thread named: namePrefix + thread number

4.4. Jvm parameters 

Windows:

Modify the file: bin / catalina.bat, setting parameters (written in the first line)

set JAVA_OPTS=-Xms2048m -Xmx2048m -Xss1024K -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m

 

View Server Status

 

Linux:

Modify bin / catalina.sh file parameters (written in the first line)

JAVA_OPTS=-Xms2048m -Xmx2048m -Xss1024K -XX:MetaspaceSize=512m

-XX:MaxMetaspaceSize=512m

Parameter Description:

1, file.encoding default file encoding

2, -Xmx1024m   provided JVM maximum available memory to 1024MB

3, -Xms1024m   provided JVM minimum memory is 1024m

4, -XX: NewSize   set the size of the young generation

5, XX: MaxNewSize set the maximum size of the young generation

6, -XX: PermSize permanent set size substituting

7, -XX: MaxPermSize set the maximum size of the permanent generation of

8, -XX: NewRatio = 4: Set the young generation (including Eden and two Survivor areas) life ratio generation (generation of permanent removal). Is set to 4, then the young generation and the generation of lifelong share ratio of 1: 4, the young generation accounts for 1/5 of the entire stack

9, -XX: + DisableExplicitGC will ignore this code manually calling GC makes System.gc () calls will become a air conditioning, it will not trigger any GC

4.5. Tomcat in web.xml configuration

The final will be loaded when the application runs conf / web.xml web.xml and application of collection

Each web application was eventually released to the Tomcat webappes directory, Tomcat is their operating environment. Can be understood as the Tomcat web.xml file is a web application web.xml each parent file, Tomcat will be common configuration for each application to extract the conf directory in web.xml, each application configuration of personality put in their own web.xml file

1. Specify the welcome page in the application web.xml if no <welcome-file-list> is covered, then the default home page is index.html, index.html, index.jsp .

 

2. Set the session survival time, the default is 30 minutes

 

3.  Set filters, filter all resources

 

4. Define the name of WEB applications

 

The  return specific HTTP state code, or a particular type of exception is thrown, to be able to develop the page display

 

6. The configuration servlet initialization parameters

 

servlet 配置Servlet

servlet-name defined Servlet name

servlet-class designated achieve this servlet class

Initialization parameters and their values ​​defined in the Servlet init-param, may have a plurality of init-param

load-on-startup specified when the Web application starts, the order of loading the Servlet, when the value is positive or zero, Servlet container servlet to load a small value, other values ​​and then successively load a large servlet

 

 

4.6. Logs directory default log file

There are five categories tomcat log: catalina, localhost, manager, admin, host-manager

1.catalina.out

That standard output and standard error, all output to two locations will enter catalina.out, contained herein tomcat run logs and application logs in to the console output of its own output. The default log file is no automatic cut, we need to use other tools to cut (note: catalina.out impact if the file over the General Assembly)

2. catalina.{yyyy-MM-dd}.log

This is the main message of the record start time tomcat, similar to the information in the eclipse when we start the service in the console to see. Inside you can see the start of JVM parameters and operating system log information. Error messages and print statements, etc. If you do not use log4j logging mechanism, this system is also recorded in the log file. (All of the log under linux in the catalina.out)

3.host-manager. Date .log

Tomcat put the log information that comes with the project manager

4. localhost.{yyyy-MM-dd}.log

Mainly used to initialize the log (listener, filter, servlet) unhandled exception tomcat finally captured and output, it also contains a running log of when to start and pause tomcat, but it does not log catalina.2018-09-19.log all. It's just part of the log records

5.localhost_access_log. Date .txt

Is requesting access to all the addresses stored in the tomcat and the path request time, request the return code and protocol information (important)

6.manager.YYYY-MM-DD.log

Is tomcat manager project-specific log files

Guess you like

Origin www.cnblogs.com/gaohw33/p/11498712.html