Installation and optimization of the Linux platform _tomcat

One. Tomcat Introduction

Tomcat server is a free open source Web application server, are lightweight application server, it is not widely used in many occasions small and medium systems and concurrent user access is the preferred development and debugging JSP program. For a beginner, it can be considered that when the Apache server configured on a single machine, it responds to the access request can use HTML (under application of a Standard Generalized Markup Language) pages. Apache Tomcat server is actually an extension, but when it is run independently run, so when you run tomcat, it is in fact as a separate process with Apache running alone.

The trick is, when configured correctly, Apache serves HTML pages, but actually running Tomcat JSP pages and Servlet. In addition, as Tomcat and IIS Web servers, etc., it has a function to handle HTML pages, while it is a Servlet and JSP container, independent of Tomcat Servlet container is the default mode. However, Tomcat ability to deal with static HTML is not as Apache server.

two. Tomcat installation

Installation preparation:

Before you install Tomcat must be installed JDK, JDK stands for Java Development Kit, SUN is provided free java language software development kit, which contains the Java Virtual Machine (JVM), write good java source code compiled to produce java byte code, as long as the JDK installation, you can use the JVM interprets the bytecode files, thus ensuring the cross-platform nature of Java.

Platform compatibility, as the JDK bytecode interpretation based on this file and calls the operating system API implementation java virtual machine corresponding to the function, the operating system is closely related to the number of bits, so there are different kinds of versions, Tomcat also has the above characteristics, it is necessary to pre-download the JDK and Tomcat

JDK Download:

1. openjdk and unloading system comes installed jdk
[root@tomcat1 ~]# rm -rf $(which java)

[root@tomcat1 ~]# tar xf jdk-7u80-linux-x64.tar

[root@tomcat1 ~]# mv jdk1.7.0_80/ /usr/local/java
2. Extract the Tomcat installation
[root@tomcat1 ~]# tar xf apache-tomcat-8.5.20.tar.gz

[root@tomcat1 ~]# mv apache-tomcat-8.5.20 /usr/local/tomcat8
3. Set the environment variables JAVA
[tomcat1 the root @ ~] # Vim /etc/profile.d/java.sh Export the JAVA_HOME = "/ usr / local / java" java root ## disposed export PATH = $ PATH: $ JAVA_HOME / bin: / usr / local / tomcat8 / bin # PATH environment variable to add java with bin subdirectory [root @ tomcat1 ~] #. / etc / profile # java.sh script into the environment variable to take effect





4. Run java -version java or javac -version command to view the version
[root@tomcat1 ~]# java -version

java version "1.7.0_65"

Java(TM) SE Runtime Environment (build 1.7.0_65-b17)

Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
5. Start Tomcat
[root@tomcat1 ~]# /usr/local/tomcat7/bin/startup.sh

Using CATALINA_BASE: /usr/local/tomcat7

Using CATALINA_HOME: /usr/local/tomcat7

Using CATALINA_TMPDIR: /usr/local/tomcat7/temp

Using JRE_HOME: /usr/local/java

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

Tomcat started.

Tomcat 默认运行在8080端口

[root@tomcat1 ~]# netstat -anpt |grep :8080

tcp 0 0 :::8080 :::* LISTEN 3318/java
6. Close the Tomcat
[root @ tomcat1 ~] # /usr/local/tomcat7/bin/shutdown.sh browser to access the test http: // IP: port

7. Modify the port number
[root @ tomcat1 ~] # vim /usr/local/tomcat8/conf/server.xml Review Port: 8080 - 9528 8005 - 9529 8009 - 9530 [tomcat1 the root @ ~] # / usr / local / tomcat8 /bin/startup.sh [root @ tomcat1 ~] # netstat -anpt | grep the Java tcp 0 0 0.0.0.0:9528 0.0.0.0:* LISTEN 5625 / the Java tcp 0 0 127.0.0.1:9529 0.0.0.0 : * LISTEN 5625 / the Java tcp 0 0 0.0.0.0:9530 0.0.0.0:* LISTEN 5625 / the Java Note: turn off the firewall and selinux security mechanism, if Ali cloud server, console security group requires the release of TCP port 8080 . systemctl disable firewalld permanently turn off the firewall systemctl stop firewalld temporarily turn off the firewall setenforce 0 Close Selinux

























8.Tomcat configuration instructions
/ usr / local / tomcat home directory (installation directory) bin storage activate or deactivate the windows or linux platform Tomcat script file conf store a variety of global Tomcat configuration file, server.xml is the most important and web. xml lib Tomcat storage required for the operation of the library (JARS) logs store the LOG file when executed Tomcat webapps major Web Tomcat distribution directory (including application examples) htdocs (HTML PHP) class Work produced after compiling jsp store file [tomcat1 the root @ ~] # LS / usr / local / Tomcat / the conf / the catalina.policy access control profile catalina.properties Tomcat profile attributes context.xml context configuration files (SELinux) the logging.properties log configuration log file server.xml main configuration file tomcat-users.xml manager-gui manage user profile (generated after Tomcat installation management interface, which can be opened to access the file)



























web.xml Tomcat's servlet, servlet-mapping, filter, MIME , and other related configuration server.xml main configuration file, you can modify the startup port, set the root of the site, web hosting, open https and other functions.

three. Tomcat optimization

1. Disable the tomcat AJP protocol
[root@tomcat1 conf]# vim server.xml

注释:

<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
2. Modify the communication mode BIO modified to improve NIO concurrent processing capability
# Uncomment <Connector port = "8080" protocol = "org.apache.coyote.http11.Http11NioProtocol"

3. Enable External Connection Pooling
Note # remove and modify the maxThreads: <-! <The Executor name = "tomcatThreadPool" namePrefix = "Catalina-Exec-" the maxThreads = "300" = minSpareThreads ". 4" /> -> # uncomment and modify Protocol: <Connector Executor = "tomcatThreadPool" Port = "8080" Protocol = "org.apache.coyote.http11.Http11NioProtocol" connectionTimeout = "20000" redirectPort = "8443" /> # delete two parameters: <Executor name = "tomcatThreadPool" namePrefix = "catalina-exec -" /> ( this is after deletion) # <Connector Executor = "tomcatThreadPool"Add the following: Port = "8080" Protocol = "org.apache.coyote.http11.Http11NioProtocol"



























maxThreads="1000"

minSpareThreads="100"

maxSpareThreads="200"

acceptCount="1000"

disableUploadTimeout="true"

connectionTimeout="20000"

URIEncoding="UTF-8"

enableLookups="false"

compression="on"

compressionMinSize="2048"

compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,image/gif,image/jpg,image/png"

redirectPort="8443" />
Tuning Allocation 4.JVM
Edit Profile catalina.sh [tomcat1 the root @ ~] Vim /usr/local/tomcat8/bin/catalina.sh # # Support the OS specific. $ Var _must_ BE SET to either to true or to false. Add the following JAVA_OPTS = " -XX -Xms1024m -Xmx2048m -server: PermSize -XX = 512M: 512M MaxPermSize = -XX: + UseConcMarkSweepGC -XX: + = UseParallelGCThreads -XX. 8: CMSInitiatingOccupancyFraction -XX = 80: + UseCMSCompactAtFullCollection -XX: CMSFullGCsBeforeCompaction -XX = 0: -PrintGC -XX: -PrintGCDetails -XX: -PrintGCTimeStamps -Xloggc : ../ logs / gc.log " parameter description -Xms heap size of the initial unit m, G -Xmx heap maximum allowable size , generally not larger than physical memory% 80 -XX: PermSize






















Initial non-memory heap size, the general application initialization settings 200m, 1024m maximum enough -XX: MaxPermSize non-heap memory maximum allowable size -XX: + UseParallelGCThreads = 8 threads parallel collector, while the number of threads garbage, is generally equal to the number of CPU -XX: + UseParallelOldGC specified senile behalf parallel collector -XX: + UseConcMarkSweepGC the CMS collector (concurrent collector) -XX: + UseCMSCompactAtFullCollection open compression and memory consolidation, prevent excessive memory fragmentation



















Example 5. Production Configuration
#server.xml配置文件下:

[root@tomcat1 ~]# vim /usr/local/tomcat8/conf/server.xml

# <Connector executor="tomcatThreadPool"下面添加:

port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"

maxThreads="1000"

minSpareThreads="100"

maxSpareThreads="200"

acceptCount="1000"

disableUploadTimeout="true"

connectionTimeout="20000"

URIEncoding="UTF-8"

enableLookups="false"

compression="on"

compressionMinSize="2048"

= compressableMimeType "text / HTML, text / XML, text / JavaScript, text / CSS, text / Plain, Image / GIF, Image / JPG, Image / PNG" the redirectPort = "8443" /> # Parameters: ORG .apache.coyote.http11.Http11NioProtocol: adjustment mode Nio maxThreads: maximum number of threads, the default 150. Avoid excessive increase the value of the request queue, resulting in slow response. minSpareThreads: Minimum number of idle threads. maxSpareThreads: Maximum number of idle threads, if more than this value, will close useless thread. acceptCount: When the processing request exceeds this value, then the request will be queued up waiting. disableUploadTimeout: Timeout Disable Upload connectionTimeout: connection timeout, in milliseconds, 0 to not limit URIEncoding: URI address. 8-encoded using UTF enableLookups: Close dns resolution, to improve the response time of compression: compression enabled

























compressionMinSize: minimum compression size in Byte compressableMimeType: compressed file types

Guess you like

Origin www.cnblogs.com/jiaxiaozia/p/12199110.html