服务器优化----Tomcat优化

Tomcat优化,配置优化

1.内存优化
JAVA_OPTS="-server -Xms2048M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_HOME/logs/heap.dump"
2.并发优化
${tomcat}/webapps/docs/config/http.html
maxConnections:最大并发连接数,NIO和NIO2默认10000,APR/native模式是8192,The maximum number of connections that the server will accept and process at any given time 

acceptCount: 队列最大排队数,默认值是100,The maximum queue length for incoming connection requests when all possible request processing threads are in use.

maxThreads:最大工作线程数,The maximum number of request processing threads to be created by this Connector

minSpareThreads:最小空闲的工作线程。The minimum number of threads always kept running
服务器优化----Tomcat优化_第1张图片
3.其他优化,
${tomcat}/webapps/docs/config/host.html
autoDeploy:This flag value indicates if Tomcat should check periodically for new or updated web applications while Tomcat is running

${tomcat}/webapps/docs/config/http.html
enableLookups:false

${tomcat}/webapps/docs/config/context.html:
reloadable:默认false,开发阶段可以设置true,负载很重
4. connector:apr
http://apr.apache.org/
依赖:
APR 1.2+ development headers (libapr1-dev package)
OpenSSL 1.0.2+ development headers (libssl-dev package)
JNI headers from Java compatible JDK 1.4+
GNU development environment (gcc, make)
 
yum install apr* openssl-devel gcc make

tar zxvf apr-1.4.5.tar  
cd apr-1.4.5  
./configure --prefix=/usr/local/apr  
make  
make install  

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

yum install expat-devel

tar zxvf apr-util-1.3.12.tar.gz  
cd apr-util-1.3.12  
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make  
make install 

安装openssl 1.0.2
./config  --prefix=/usr/local/openssl
修改Makefile:
vi Makefile
将原来的:CFLAG=     -DOPENSSL_THREADS
修改为:  CFLAG= -fPIC -DOPENSSL_THREADS
也就是添加-fPIC
执行执行:
make && make install

cd bin
tar -zxvf tomcat-native.tar.gz
cd tomcat-native-1.2.12-src
cd native
./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/openssl 
make
make install

catalina.sh:
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib
注意:开启了apr之后,jvm用到的native内存会增大,因此要适当调大Metaspace空间,添加JVM选项:-XX:MetaspaceSize=128m
JAVA_OPTS="-server -Xms2048M -Xmx2048M -XX:MetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_HOME/logs/heap.dump"
服务器优化----Tomcat优化_第2张图片
server.xml:



LVS四层负载均衡

LVS + Keepalived高可用

你可能感兴趣的:(服务器优化----Tomcat优化)