CentOS 6.5 optimizes Tomcat 7
Everyone has heard that Apache Tomcat 6 supports the Java language NIO (New I/O), no matter whether you are familiar with NIO technology, but you can imagine NIO is a good thing. Indeed, using NIO can provide better performance on the server side and enhance the performance of concurrent processing on the server side. Note: Sorry, the NIO function is not enabled in the default configuration option of Tomcat 6. So many friends who are using Tomcat 6 thought they could use NIO happily.
Cd/usr/local/tomcat1/conf
Vi server. xml
1. Set the Tomcat Connector pool.
Yellow Sea added the following configuration in the configuration file:
<Executor name = "tomcatThreadPool" namePrefix = "catalina-exec-" maxThreads = "1000" minSpareThreads = "350"/>
Ii. Modify JVM memory size in Linux
To add it to catalina. sh in the bin of tomcat, before the position cygwin = false. Note that the quotation marks must be placed, and the red ones are newly added.
# OS specific support. $ var _ must _ be set to either true or false.
JAVA_OPTS = "-server-Xms512M-Xmx512M-Xss256K-Djava. awt. headless = true-Dfile. encoding = UTF-8-XX: PermSize = 64 M-XX: MaxPermSize = 128 m"
Cygwin = false
3. view the default values of open files in the current system:
Ulimit-
It's 1024.
Maximum number of files that can be opened in the file system: cat/proc/sys/fs/file-max
My machine is 396399
Modify the maximum number of opened files in the file system: echo 396399>/proc/sys/fs/file-max
This value can only be smaller than the limit value.
1. In the vi/etc/security/limits. conf file, set the maximum number of opened files to add:
* Soft nofile 65535
* Hard nofile 65535
Finally, restart ulimit-a to view the value of open files again. If it is changed, the value will take effect.
4. install Tomcat's Apr to improve performance
It is found that Tomcat can use Apache Portable Runtime to provide better performance and improve the processing capability of Web static pages. Dedicated Web servers are no longer needed to process static pages. Apr and tomcat-native provide better scalability, performance, and integration to local server technologies.
If the apr technology is not available, the following prompt is displayed when tomcat is started:
Information: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java. library. path:/usr/java/jdk1.6.0 _ 06/jre/lib/i386/client:/usr/java/jdk1.6.0 _ 06/jre/lib/i386: /usr/java/jdk1.6.0 _ 06/
Jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
According to official instructions:
APR library
OpenSSL libraries
Openssl is available
Yum install-y openssl-devel
Download *. gz to install apr.
(1) install apr
Mkdir/root/software
Cd/root/software
Wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
Tar zxvf apr-1.4.6.tar.gz
Cd apr-1.4.6
./Configure -- prefix =/usr/local/apr
Make
Make install
When installing apr
./Configure -- prefix =/usr/local/apr
Rm: cannot remove 'libtoolt': No such file or directory
Solution:
Vim configure
Add # comment out before line 1 # $ RM "$ comment file"
In re-./configure
(2) install apr-iconv
Cd/root/software
Wget http://mirror.bit.edu.cn/apache/apr/apr-iconv-1.2.1.tar.gz
Tar-zxvf apr-iconv-1.2.1.tar.gz
Cd apr-iconv-1.2.1
./Configure -- prefix =/usr/local/apr-iconv -- with-apr =/usr/local/apr
Make
Make install
(3) install apr-util
Cd/root/software
Wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
Tar zxvf apr-util-1.4.1.tar.gz
Cd apr-util-1.4.1
. /Configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr -- with-apr-iconv =/usr/local/apr-iconv/ bin/consumer Conv
Make
Make install
PS: I have experienced two different apr installations. For the first time, my CentOS has not been upgraded. After one upgrade, there will be some errors before the upgrade, you just need to update yum. It is recommended that you install it after upgrade. It will be a little bit more normal ~~
(4) install tomcat-native
// Tomcat-native-1.1.27-src.tar.gz I installed tomcat inside with his own, in the bin directory, if you do not find, go to the next online on the line .. I don't know where to find out.
Cd/usr/local/tomcat1/bin
Tar zxvf tomcat-native.tar.gz
Cd tomcat-native-1.1.27-src/jni/native
./Configure -- with-apr =/usr/local/apr
Make
Make install
(5) set apr Environment Variables
Cd/usr/local/tomcat1/bin
Vi catalina. sh
In the file #! Add the following content under/bin/sh:
#! /Bin/sh
LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/apr/lib
Export LD_LIBRARY_PATH
In this case, we just added the tomcat apr and did not destroy the configuration information of other TOMCAT servers.
After tomcat is started, check the log:
Bin/startup. sh
Head logs/catalina. out
You can see the following results:
Okay, you can run it, but you have not tested the performance improvement.
High concurrency will significantly improve the performance. After the installation is complete, restart the system to take effect. For example, if the default protocal is apr, it is better to change protocol to org. apache. coyote. http11.Http11AprProtocol to be clearer.
Cd/usr/local/tomcat1/conf
Vi server. xml
Replace ctor with the following content:
<Connection port = "8080"
Protocol = "org. apache. coyote. http11.Http11AprProtocol"
Executor = "tomcatThreadPool"
Compression = "on"
CompressionMinSize = "2048"
MaxThreads = "30000"
MinSpareThreads = "512"
MaxSpareThreads = "2048"
EnableLookups = "false"
RedirectPort = "8443"
AcceptCount = "35000"
Debug = "0"
ConnectionTimeout = "40000"
DisableUploadTimeout = "true" URIEncoding = "UTF-8" useBodyEncodingForURI = "true"/>
Next we will start to test the pressure of the two Protocols:
Install AB on centos
Yum install httpd-tools
After preparation, we can test it.
AB-kc 1000-n 10000 http: // localhost: 8080/
This command uses 1000 concurrent connections for 10000 times. The result is as follows:
The fastest NIO:
The fastest time for APR:
The gap is about 50%. We strongly recommend that you use the APR protocol !!! Do not use NIO protocol + APR library support behavior !!!!!!!!
If you cannot install APR or you cannot enable it, use the following alternative solution:
<Connection port = "8080"
Protocol = "org. apache. coyote. http11.Http11NioProtocol"
Executor = "tomcatThreadPool"
Compression = "on"
CompressionMinSize = "2048"
MaxThreads = "30000"
MinSpareThreads = "512"
MaxSpareThreads = "2048"
EnableLookups = "false"
RedirectPort = "8443"
AcceptCount = "35000"
Debug = "0"
ConnectionTimeout = "40000"
DisableUploadTimeout = "true" URIEncoding = "UTF-8" useBodyEncodingForURI = "true"/>
You can specify the JDK location when installing tomcat-native.
./Configure -- with-apr = $ HOME/APR \
-- With-java-home = $ JAVA_HOME \
For more Tomcat tutorials, see the following:
Install and configure the Tomcat environment in CentOS 6.6
Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects
Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)
Tomcat Security Configuration and Performance Optimization
How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux
Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure
Install Tomcat in CentOS 6.5
Tomcat details: click here
Tomcat: click here
This article permanently updates the link address: