Tomcat 8 Installation Tomcat 8 Installation Official website: Http://tomcat.apache.org/Tomcat 8 website Download: http://tomcat.apache.org/download-80.cgi at this time (20160207) Tomcat 8 Latest Version: apache-tomcat-8.0.32.tar.gz My personal habits /opt directory to create a directory setups to store a variety of software installation packages; Directory to create a program to store a variety of unpacked software packages, the following explanation is based on this habit I personally have used a Third-party source: Epel, Repoforge, if you appear yum install XXXXX Installation is not successful, it is likely that you do not have related sources, please check my source settings for the article Tomcat 8 download: wget http://apache.fayea.com/tomcat/tomcat-8/v8.0.32/bin/ APACHE-TOMCAT-8.0.32.TAR.GZ Compression Package Decompression: TAR-ZXVF Apache-tomcat-8.0.32.tar.gz moved to the Unpacked folder to/usr: MV apache-tomcat-8.0.32/ usr/program/for convenience, modify the name of the extracted directory: mv/usr/program/apache-tomcat-8.0.32//usr/program/tomcat8/set the Iptables rule (this step must be set): One way: Turn off the iptables first, prevent the interception problem and test: Service iptables Stop One way: Add the Allow rule in iptables (Tomcat default port is 8080): Add rule: iptables-i INPUT- P tcp-m TCP--dport 8080-j ACCEPT Save rule: Service iptables save reboot Iptables:service iptables the test installed Tomcat: Start Tom cat:sh/usr/program/tomcat8/bin/startup.sh; tail-200f/usr/program/tomcat8/Logs/catalina.out access: http://server IP address: 8080/stop tomcat:sh/usr/program/tomcat8/bin/shutdown.sh If you start the report: Java.net.UnknownHostException or localhost. This prevents creation of a GUID solution: Modify the configuration file: Vim/etc/sysconfig/network, change the HOSTNAME inside to a name you set yourself, such as my side instead: Youmeek Modify configuration text Item: vim/etc/hosts, delete the first line of 127.0.0.1, and then add this sentence to the last line: 127.0.0.1 localhost Youmeek, where the last Youmeek is the hostname and then reboot the computer: reboot
Tomcat 8 ConfigurationSet up Tomcat-related variables: vim/usr/program/tomcat8/bin/catalina.sh at the top of the editable content of the configuration file (starting with line 98), plus the following (specific parameters are modified according to your server):
java_home=/usr/program/jdk1.8.0_72
catalina_home=/usr/program/tomcat8
catalina_opts= "-Dfile.encoding= UTF-8-server-xms2048m-xmx2048m-xmn1024m-xx:permsize=256m-xx:maxpermsize=512m-xx:survivorratio=10-xx: MAXTENURINGTHRESHOLD=15-XX:NEWRATIO=2-XX:+DISABLEEXPLICITGC "
catalina_pid= $CATALINA _home/catalina.pid
If you cannot stop Tomcat using shutdown.sh, you can modify its configuration: vim/usr/program/tomcat8/bin/shutdown.sh the tail of this line: Exec "$PRGDIR"/"$EXECUTABLE" Stop "$@" instead: Exec "$PRGDIR"/"$EXECUTABLE" Stop 10-force
Tomcat 8 OptimizationTomcat 6/7/8 optimization parameters are a little different, it is best to look at the official website This document is still maintained this parameter to start Tomcat, access to this address, the following to explain some of the configuration information, under the document are described: Documents: http:// 127.0.0.1:8080/docs/config You can also look directly at the network version: Tomcat 6 Documentation: Https://tomcat.apache.org/tomcat-6.0-doc/config Tomcat 7 Documentation: HTTPS ://tomcat.apache.org/tomcat-7.0-doc/config/tomcat 8 Documents: https://tomcat.apache.org/tomcat-8.0-doc/config/If you need to see Tomcat's running status can be configured with the Tomcat administrator account, then log in to the Tomcat background to view the edit/opt/tomcat7/bin/conf/tomcat-users.xml file, adding the following information inside:
<role rolename= "manager"/>
<role rolename= "Manager-gui"/> <role rolename=
"admin"/>
<role rolename= "Admin-gui"/> <user username= "Tomcat" password= "Tomcat" roles= "
admin-gui,admin, Manager-gui,manager "/>
Edit configuration file: Vim/usr/program/tomcat7/conf/server.xml Open the default annotated connection pool configuration: Default value:
<!--
<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-" maxthreads= "" Minsparethreads
= "4"/>
-->
Modified to:
<executor
name= "Tomcatthreadpool"
nameprefix= "catalina-exec-"
maxthreads=
" minsparethreads= "Maxidletime=" "
60000"
prestartminsparethreads = "true"
maxqueuesize = "M"
/ >
Key parameter explanation: MaxThreads, maximum concurrency number, default setting 200, generally recommended in 500 ~ 800, according to hardware facilities and business to determine the number of threads created by Minsparethreads,tomcat initialization, default settings 25 Prestartminsparethreads, the Minsparethreads parameter value is initialized when Tomcat initializes, and if it does not equal true,minsparethreads value, it will have no effect maxqueuesize, The maximum number of waiting queues, exceeding the request MaxIdleTime, if the current thread is larger than the initialization thread, the idle thread survives, in milliseconds, by default 60000=60 seconds = 1 minutes. To modify the default link parameter configuration: Default value:
<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000"
redirectport= "8443"
/>
Modified to:
<connector executor= "Tomcatthreadpool port=" 8080 "protocol=" Org.apache.coyote.http11.Http11Nio2Protoco L "connectiontimeout=" 20000 "maxconnections=" 10000 "redirectport=" 8443 "enablelookups=" false "Acceptco
Unt= "maxpostsize=" "10485760" maxhttpheadersize= "8192" compression= "on" disableuploadtimeout= "true" Compressionminsize= "2048" acceptorthreadcount= "2" compressablemimetype= "text/html,text/xml,text/plain,text/css,t Ext/javascript,application/javascript "uriencoding=" Utf-8/>
Key parameter explanation: Protocol,tomcat 8 set Nio2 better: Org.apache.coyote.http11.Http11Nio2Protocol (if this is not used, use the following) Protocol,tomcat 6, 7 Better to set NiO: Org.apache.coyote.http11.Http11NioProtocol enablelookups, disable DNS query Acceptcount, and specify that when the number of threads that can be used to process requests is used, The number of requests that can be placed in the processing queue, the requests exceeding this number will not be processed, the default setting of Maxpostsize, the POST submission by Form URL parameter, the maximum size to be submitted, the default is 2097152 (2 trillion), and the unit used is bytes. 10485760 is 10M. If you want to disable the limit, you can set to-1. Acceptorthreadcount, the number of threads used to receive the connection, the default value is 1. Generally this refers to the need to change the time is because the server is a multi-core CPU, if the Multi-Core CPU is generally configured to 2. The maximum amount of Maxhttpheadersize,http request header information is not processed in excess of this length. General 8K. Disable AJP (if your server does not use Apache) to comment out the following line, the default Tomcat is turned on.
<!--<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>-->
JVM Optimization Model data Source: http://xmuzyq.iteye.com/blog/599750 matching data: HTTP://WWW.JIANSHU.COM/P/D45E12241AF4 Java memory model is divided into: young, younger generation (easy to be GC). The young district is divided into three parts, the Eden area and the two Survivor areas of the same size, of which only one of the Survivor intervals is used, and the other is a copy object for garbage collection, minor GC Will move the surviving object to the idle Survivor interval, and after several garbage collections, the object that survives the Survivor will be moved to the tenured interval, depending on the JVM's strategy. tenured, lifelong generation. Tenured the main preservation life cycle of the object, generally some old objects, when some objects in young replication transfer a certain number of times, the object will be transferred to the tenured area, generally if the system with the application level of caching, Objects in the cache are often moved to this interval. Perm, permanent generation. Mainly save the Class,method,filed object, this department of space generally will not overflow, unless a lot of classes loaded at a time, but when it comes to hot deployment of the application server, sometimes encountered Java.lang.OutOfMemoryError:PermGen Space error, the cause of this error is likely to be redeployed every time, but after redeployment, class classes have not been unloaded, which caused a large number of class objects saved in the perm, in this case, the general restart the application server can solve the problem. Linux modifies the/usr/program/tomcat7/bin/catalina.sh file and adds the following information to the first line of the file. If the server is running only one Tomcat memory if it is 4g:catalina_opts= "-dfile.encoding=utf-8-server-xms2048m-xmx2048m-xmn1024m-xx:permsize= 256M-XX:MAXPERMSIZE=512M-XX:SURVIVORRATIO=10-XX:MAXTENURINGTHRESHOLD=15-XX:NEWRATIO=2-XX:+DISABLEEXPLICITGC " If the memory is 8G:catalina_opts= "-dfile.encoding=utf-8-server-xms4096m-xmx4096m-xmn2048m-xx:permsize=256m-xx:maxpermsize=512m-xx : SURVIVORRATIO=10-XX:MAXTENURINGTHRESHOLD=15-XX:NEWRATIO=2-XX:+DISABLEEXPLICITGC "Machine memory if it is 16g:catalina_opts="- Dfile.encoding=utf-8-server-xms8192m-xmx8192m-xmn4096m-xx:permsize=256m-xx:maxpermsize=512m-xx:survivorratio= 10-XX:MAXTENURINGTHRESHOLD=15-XX:NEWRATIO=2-XX:+DISABLEEXPLICITGC "Machine memory if it is 32g:catalina_opts="-Dfile.encoding= UTF-8-server-xms16384m-xmx16384m-xmn8192m-xx:permsize=256m-xx:maxpermsize=512m-xx:survivorratio=10-xx: MAXTENURINGTHRESHOLD=15-XX:NEWRATIO=2-XX:+DISABLEEXPLICITGC "If it is a 8G development machine-XMS2048M-XMX2048M-XX:NEWSIZE=512M-XX: maxnewsize=1024m-xx:permsize=256m-xx:maxpermsize=512m if it is a 16G development machine-XMS4096M-XMX4096M-XX:NEWSIZE=1024M-XX: maxnewsize=2048m-xx:permsize=256m-xx:maxpermsize=512m parameter Description:
-dfile.encoding: Default file Encoding-server: Indicates that this is a configuration applied to the server, and that there will be special processing within the JVM-xmx1024m: Set JVM maximum available memory to 1024MB- xms1024m: Set the JVM minimum memory to 1024m.
This value can be set to be the same as-xmx to avoid the JVM reallocating memory after each garbage collection completes. -xmn1024m: Sets the JVM Cenozoic size (after JDK1.4 version). General-xmn size is about 1/2 of the-XMS, do not set too large or too small, too large to lead to a small age, frequent full GC, too small lead to minor GC frequent. If you do not set-XMN, you can set it with-xx:newratio=2, which is the same effect-xx:newsize: Set the Cenozoic size-xx:maxnewsize: Set the maximum Cenozoic size-xx:permsize: Set the permanent generation size-XX: MaxPermSize: Set maximum permanent generation size-xx:newratio=4: Set the ratio of young generation (including Eden and two Survivor districts) to Lifetime generation (excluding permanent generation). Set to 4, the young generation and lifetime generation accounted for the ratio of 1:4, young generation of the entire stack of 1/5-xx:maxtenuringthreshold=10: Set the maximum age of garbage, the default is: 15. If set to 0, then the younger generation objects do not go through the Survivor area, directly into the old generation. More applications for older generations can improve efficiency. If this value is set to a larger value, the young generation object will replicate multiple times in the Survivor area, which can increase the lifetime of the object in the younger generation and increase the introduction of the recovery in the younger generation. It is important to note that setting the-xx:maxtenuringthreshold does not mean that the object must survive in the younger generation 15 times before being promoted into the old age, it is only a maximum value, in fact, there is a dynamic computing mechanism to calculate the threshold of each Jin into the old generation,
The threshold value and the smaller one in the maxtenuringthreshold are whichever. -XX:+DISABLEEXPLICITGC: This ignores the code that calls the GC manually so that the call to System.GC () becomes an air conditioner and does not trigger any GC
Windows modifies the/tomcat7/bin/catalina.bat file, finds this line: Echo Using catalina_base: "%catalina_base%", and adds the following to it, which is only for the uncompressed version of the Tomcat has effect, for the installation version of the need to click on the installed taskbar after the Tomcat icon, open the configuration has a Java Tab to edit.
Set java_opts=%java_opts%-dfile.encoding= "UTF-8"-dsun.jnu.encoding= "UTF8"-ddefault.client.encoding= "UTF-8"- Duser.language=zh
set java_opts=%java_opts%-server-xms4096m-xmx4096m-xmn2048m-xx:permsize=256m-xx: Maxpermsize=512m-xx:survivorratio=10-xx:maxtenuringthreshold=15-xx:newratio=2-xx:+disableexplicitgc
Log Segmentation of Tomcat 8Modify the premise: I for Tomcat8.5, installation directory for:/USR/PROGRAM/TOMCAT8 Network on the official website address can not open now: http://cronolog.org/download/index.html Aliyun CentOS have Epel source so you can download directly: Yum install Cronolog, at this time: 2017-02, the latest version is: 1.6.2-10.el6 after installation, look at the installation of the directory location: which cronolog, my side of the results are:/usr/ Sbin/cronolog, write down this result and use it later. Modify the contents of the catalina.sh: vim/usr/program/tomcat8/bin/catalina.sh find this code (expected before and after 416 lines):
shift Touch "$CATALINA _out" if ["$" = "-security"]; then if [$have _tty-eq 1]; then echo "Using security Mana Ger "fi shift eval $_nohup" \ $_runjava\ "" \ "$LOGGING _config\" "$LOGGING _manager $JAVA _opts $CATALINA _opts \-classpath "\" $CLASSPATH \ "" \-djava.security.manager \-djava.security.policy== "\" $CATALINA _base/conf/catalina.policy\ "" \ D Catalina.base= "\" $CATALINA _base\ "\-dcatalina.home=" \ "$CATALINA _home\" "\-djava.io.tmpdir=" \ "$CATALINA _tmpdir\" "\ Org.apache.catalina.startup.Bootstrap" $@ "Start \ >>" $CATALINA _out "2>&1" & "Else eval $_nohup "\" $_runjava\ "" \ "$LOGGING _config\" "$LOGGING _manager $JAVA _opts $CATALINA _opts \-classpath" \ $CLASSPATH \ "" \-DCA
Talina.base= "\" $CATALINA _base\ "\-dcatalina.home=" \ "$CATALINA _home\" "\-djava.io.tmpdir=" \ "$CATALINA _tmpdir\" "\ Org.apache.catalina.startup.Bootstrap "$@