Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tomcat optimizes jvm parameters

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Tomcat

1. Introduction to Tomcat Tomcat is a core project of the Jakarta project of the Apache Software Foundation (Apache Software Foundation), which is supported by

Developed by Apache, Sun and other companies and individuals.

Tomcat server is a free and open source Web application server, which is a lightweight application server. Currently, the latest version of Tomcat is 9.0. Java containers also include resin, weblogic, and so on.

Tomcat official website: http://tomcat.apache.org

2. Tomcat is a good helper-JDK

JDK is a software development kit of Java language, which is mainly used for java applications on mobile devices and embedded devices. JDK is the core of the whole java development, which includes the running environment of JAVA (JVM+Java system class library) and JAVA tools. Http://www.oracle.com/technetwork/java/javase/downloads/index.html

Port: the port served by tomcat itself: 8005

Port for tomcat to communicate with other applications: 8009 tomcat for client browsers to access pages: 8080

JVM Foundation

First, the general knowledge of JVM virtual machine as the beginning of understanding JVM virtual machine. It is necessary for us to understand the following two questions.

1. What is a JAVA virtual machine

The so-called virtual machine is a virtual computer. It is a piece of software that executes a series of virtual computer instructions. In general, virtual

Virtual machine can be divided into system virtual machine and program virtual machine. The famous VisualBox and VMware belong to the system virtual machine. They are complete simulations of physical computers. Provides a software platform that can run a complete operating system.

A typical example of a program virtual machine is the Java virtual machine, which is specially designed to execute a single computer program and executes in the Java virtual machine.

We call it the Java bytecode instruction. Whether it is a system virtual machine or a program virtual machine, the software running on it is limited to the resources provided by the virtual machine.

How to achieve Cross-platform in 2.JAVA

The same JAVA program (collection of JAVA bytecodes) runs on major operating system platforms such as Windows, CentOS, Ubuntu and so on through the JAVA virtual machine (JVM). The program uses a virtual machine as an intermediary to achieve cross-platform.

1/14

3. The basic structure of virtual machine we need to have a perceptual understanding of the structure of JVM virtual machine. After all, we are not programmers, and our awareness is not that deep.

1), class loading subsystem

It is responsible for loading Class information from the file system or network, and the loaded class information is stored in a memory space called the method area. In addition to class information, run-time pool information, including literal strings and numbers, may also be stored in the method area.

2/14

2), Java heap

Established when the virtual machine starts, it is the main memory working area of the Java program. Almost all Java object instances are placed in the Java heap. Heap space is shared by all threads, which is a memory interval that is closely related to Java applications.

3), NIO library of Java (direct memory)

Allow Java programs to use direct memory. Direct memory is the memory range outside the Java heap and requested directly from the system. Access to direct memory is usually faster than the Java heap. Therefore, for performance reasons, direct memory may be considered in situations where reads and writes are frequent. Due to direct memory

Outside the Java heap, so its size is not limited to the maximum heap size specified by Xmx. However, the system memory is limited, and the sum of Java heap and direct memory is still limited by the maximum memory that the operating system can give.

4), garbage collection system

The garbage collection system is an important part of the Java virtual machine. The garbage collector can return to the normal area, Java heap and direct memory.

Take it.

5), Java stack

Each Java virtual machine thread has a private Java stack. A thread's Java stack is created when the thread is created. Java stores frame information, local variables and method parameters are stored in Java stack, and it is closely related to the call and return of Java method.

4. Virtual machine heap memory structure

The heap space in JVM can be divided into three regions, the young generation, the old generation and the permanent generation (method zone).

Cenozoic: Cenozoic area

Classes are generated and applied here, and are finally garbage collected. All classes are new out in the Eden area. When the Eden area is full, GC destroys the objects that are not used in the area, and the rest of the useful ones go to the survival area.

Old age: the elderly area is used to store objects with a long generation cycle.

3/14

Permanent generation: the permanent zone stores the class,interface that comes with JDK.

Practical troubleshooting tool for JVM operation and maintenance

Jps

1 、 jps

Used to view the specific status of Java processes, including process ID, process startup path and startup parameters, and so on, similar to ps on unix, except that jps is used to display java processes, jps can be understood as a subset of ps.

The common parameters are as follows:

-Q: ignore the output class name, Jar name and parameters passed to the main method, and output only pid-m: output the parameters passed to the main method, if it is an embedded JVM, output to null-l: output the full package name, the application main class name, the full path name of the jar-v: output the parameters passed to the jvm

Note: the running account when using jps should be the same as the account started by the JVM virtual machine. If the account to start the JVM virtual machine is www, the www user should also be used to specify it when using the jps instruction. Sudo-u www jps

Example:

/ / View the actual startup parameters of the JVM process that is already running

[root@java-tomcat1] # jps-v

58154 Jps-Denv.class.path=.:/usr/local/java/lib:/usr/local/java/jre/lib:/usr/local/java/lib/tools.jar-Dapplication.home=/usr/local/java-Xms8m

58015 Bootstrap-Djava.util.logging.config.file=/data/application/tomcat/conf/logging.properties-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager-Djdk.tls.ephemeralDHKeySize=2048-Djava.protocol.handler.pkgs=org.apache.catalina.webresources-Dorg.apache.catalina.security.SecurityListener.UMASK=0027-Dignore.endorsed.dirs=-Dcatalina.base=/data/ application/tomcat-Dcatalina.home=/data/application/tomcat-Djava.io.tmpdir=/data/application/tomcat/temp

Deploy Tomcat

Tomcat,Resin,JBOSS,WebSphere,Weblogic belongs to oracle

1. Tomcat Http Server 1. Install JDK and tomcat

# tar xf apache-tomcat-7.0.34.tar.gz-C / usr/local/

# tar xf jdk-8u91-linux-x64.tar.gz-C / usr/local

# ln-s / usr/local/jdk1.8.0_91 / usr/local/java made a connection, or renamed it. Or mv directly.

# ln-s / usr/local/apache-tomcat-7.0.34 / usr/local/tomcat

two。 Modify environment variabl

Vim / etc/profile JAVA_HOME=/usr/local/java

4/14

PATH=$JAVA_HOME/bin:$PATH / / use the JAVA command export JAVA_HOME PATH under JAVA_HOME

CATALINA_HOME=/usr/local/tomcat / / Tomcat installation directory export CATALINA_HOME

Let the environment variable take effect

# source / etc/profile 3. Detection

# java-version

Java version "1.8.0,91"

Java (TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot (TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

4. Start Tomcat

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

Using CATALINA_BASE: / usr/local/tomcat

Using CATALINA_HOME: / usr/local/tomcat

Using CATALINA_TMPDIR: / usr/local/tomcat/temp

Using JRE_HOME: / usr/java/jdk1.7.0_11

Using CLASSPATH: / usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Netstat-tnlp | grep java

Tcp 00:: ffff:127.0.0.1:8005: LISTEN 6191/java

Tcp 00: 8009: LISTEN 6191/java

Tcp 0 0: 8080: * LISTEN 6191/java

/ usr/local/tomcat/bin/shutdown.sh / / close tomcat about the tomcat port:

The Tomcat server establishes a connection with the client program through the Connector connector component, and the Connector component is responsible for receiving customer requests.

Request, and send the response result of the Tomcat server to the customer. By default, Tomcat configures two connectors in server.xml:

The first connector listens on port 8080 and is responsible for establishing a HTTP connection. This connector is used when accessing the Web application of the Tomcat server through a browser.

The second connector listens on port 8009 and is responsible for establishing connections with other HTTP servers. This connector is needed when integrating Tomcat with other HTTP servers.

8005 is the port of tomcat itself

test

Http://192.168.2.251:8080/ II, install MySQL (abbreviated) use mysql (abbreviated) 1. Use mariadb

Yum-y install mariadb mariadb-server systemctl start mariadb

Mysqladmin-u root password '123'

Create the database and specify the character set create database jspgou default charset=utf8; flush privileges

3. Deploy jspgou

Ls / usr/local/tomcat/webapps/ the base directory of the default website base

Docs examples host-manager manager ROOT

Ls / usr/local/tomcat/webapps/ROOT / / the home directory of the default website

# unzip jsp... .zip

# cp-r ROOT/ / usr/usr/local/tomcat/webapps/

Change the database link

The name of the database created by jdbc.url=jdbc:mysql://127.0.0.1:3306/ is about line 20 of the file vim / usr/local/tomcat/webapps/ROOT\ WEB-INF\ config\ jdbc.properties in the package? characterEncoding=UTF-8 jdbc.username=root

Jdbc.password=123

3. Import data:

Mysql-u root-P123-D jspgou < jspgou.sql

5. Testing

System management backend login: http://localhost:8080/jeeadmin/jspgou/index.do

User name: admin

5/14

Secret code: 123456

Tomcat Foundation

1. Tomcat home directory introduction [root@java-tomcat1 tomcat] # tree-L 1

.

├── bin # stores management scripts for tomcat

├── BUILDING.txt

Configuration file for ├── conf # tomcat

├── CONTRIBUTING.md

Storage path of jar package called by ├── lib # web application

├── LICENSE

├── logs # tomcat log storage directory

├── NOTICE

├── README.md

├── RELEASE-NOTES

├── RUNNING.txt

├── temp # stores temporary files

├── webapps # default website publishing directory

└── work # stores compiled .java and .class files

2.webapps directory introduction [root@java-tomcat1 webapps] # tree-L 1

.

Help documentation for ├── docs # tomcat ├── examples # web Application example ├── host-manager # Host Management ├── manager # Management └── ROOT # default site Root

Introduction to the 3.Tomcat profile directory (conf) [root@java-tomcat1 conf] # tree-L 1

.

├── Catalina ├── catalina.policy

├── catalina.properties ├── context.xml

├── logging.properties

├── logs

├── server.xml # tomcat main configuration file

├── server.xml.bak

├── server.xml.bak2

├── tomcat-users.xml # tomcat manage user profile

├── tomcat-users.xsd

└── web.xml

Management of 4.Tomcat

Startup program # / data/application/tomcat/bin/startup.sh shutdown program # / data/application/tomcat/bin/shutdown.sh

5.Tomcat log description

[root@java-tomcat1 bin] # tail-f / data/application/tomcat/logs/catalina.out

Org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/ data/application/tomcat/webapps/host-manager] has finished in [21] ms

04-Jul-2019 22:40:00.026 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/ data/ application/tomcat/webapps/manager]

04-Jul-2019 22:40:00.042 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/ data/ application/tomcat/webapps/manager] has finished in [16] ms

6/14

04-Jul-2019 22 main 40 ajp-nio-8009 00.048 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"] 04-Jul-2019 22 14 40 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 04-Jul-2019 22 40 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 479 ms

It is found that the start-up time is long, and the start-up time of one item accounts for the vast majority.

24-Nov-2017 15:09:50.629 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive / application/ apache-tomcat-8.0.27/webapps/memtest.war has finished in 58892 ms

It is found that the time is here: it is caused by the random number problem caused by session. The Session ID of Tocmat is calculated by SHA1 algorithm.

You must have a key when calculating Session ID. To improve security, Tomcat starts by randomly generating a key.

The main reason for the slow startup of Tomcat is that Tomcat is stuck when generating random numbers, resulting in the failure of tomcat startup.

Whether there is enough entropy to generate random numbers can be seen with the following command

[root@java-tomcat1 ~] # cat / proc/sys/kernel/random/entropy_avail 1065

In order to speed up the speed of random numbers provided by / dev/random, you can operate the peripherals of the device to cause a large number of interruptions, transmit data over the network, press buttons, move the mouse, and type several different commands on the command line, commonly known as Juqi.

Method 1:

Vim $TOMCAT_HOME/bin/catalina.sh-add the following content if [["$JAVA_OPTS"! =-Djava.security.egd=]]; then

JAVA_OPTS= "$JAVA_OPTS-Djava.security.egd=file:/dev/urandom"

Fi

This system property egd represents the entropy collection daemon (entropy gathering daemon)

Method 2:

Yum install rng-tools # install rngd Service (Entropy Service, Entropy Pool) systemctl start rngd # start Service

Tomcat main profile details

Configuration file for Tomcat:

The configuration files of Tomcat are stored in the / usr/local/tomcat/conf directory by default, and there are mainly the following

Server.xml: the main configuration file of Tomcat, which contains configuration information about the main components of Service, Connector, Engine, Realm, Valve, and Hosts

Web.xml: a configuration file that conforms to the Servlet specification and is used to configure servlet and provides default configuration information, including MIME mapping, for all Web applications

Relevant roles, users, passwords and other information used in tomcat-user.xml:Realm authentication; manager default situation included with Tomcat

This file will be used in this case; adding / deleting users in Tomcat, assigning roles to users, etc., will be achieved by editing this file; catalina.policy:Java-related security policy configuration files provide access control at the system resource level; definition and access-related control of package within catalina.properties:Tomcat, including access control for

Control of capacity; Tomcat6 will read the relevant settings of this file in advance when starting

Logging.properties: Tomcat6 records operation-related logs through its own internal JAVA logger. This file is the configuration information related to the logger and can be used to define the component level of logging and the location of log files.

Context.xml: default configuration information for all host

1. Server components:

Port: the port that receives shutdown instructions. By default, only local access is allowed. Default is 8005.

Shutdown: the command string sent to this Server to close the tomcat instance. The default is SHUTDOWN.

2. Service components:

7/14

Service is mainly used to associate an engine and the connectors associated with this engine, each of which connects to the inbound station through a specific port and protocol.

The request is forwarded to the associated engine for processing. For this reason, the Service should contain an engine and one or more connectors. As defined in the example above:

This defines a Service called Catalina, which is also recorded in the log file when relevant log information is generated.

Service-related attributes:

ClassName: the name of the class used to implement service, which is usually org.apache.catalina.core.StandardService. Name: the name of this service. Default is Catalina.

3. Connector components:

Requests to enter Tomcat can be divided into the following two categories according to the working mode of Tomcat:

Tomcat as the application server: the request comes from the front-end web server, which may be Apache, IIS, Nginx, etc.; Tomcat as a stand-alone server: the request comes from the web browser

Tomcat should consider the working situation and define the required connectors for the requests in the corresponding situation in order to receive the requests from the client correctly. An engine can have one or more connectors to accommodate multiple request modes.

A variety of properties can be used to define a connector, and some properties apply only to a specific connector type. Generally speaking, there are four types of connectors that are common in server.xml:

1) HTTP Connector 2) SSL Connector 3) AJP 1.3 Connector 4) proxy Connector such as the HTTP connector defined in the example server.xml above:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report