12 tomcat 配置优化

1.内存优化catalina

vi ./bin/catalina.sh
Xms 最小内存,Xmx 最大内存
JAVA_OPTS="-server -Xms2048M -Xmx2048M -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=5 -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_HOME/logs/heap.dump"

2.并发优化

vi conf/server.xml
${tomcat}/webapps/docs/config/http.html

maxConnections( 支持最大的并发连接数):The maximum number of connections that the server will accept and process at any given time
acceptCount(最大的同时接受):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

12 tomcat 配置优化

3. 其他优化

tomcat/webapps/docs/config/host.htmlautoDeployThisflagvalueindicatesifTomcatshouldcheckperiodicallyforneworupdatedwebapplicationswhileTomcatisrunning线{tomcat}/webapps/docs/config/http.html
enableLookups(DNS查询,禁用可以提高性能)false

${tomcat}/webapps/docs/config/context.html:
reloadable(catalina自动监视,如果WEB-INF/classes,和/WEB-INF/lib改变了, 线上是绝对不允许开启的,他会带来很重的负载压力)false

  • 禁用AJP
    12 tomcat 配置优化
  • 查看tomcat 日志
    tail -f ./log/catalina.out
  • iptables -nL
    12 tomcat 配置优化
-  iptables -F
可以通过/sbin/iptables -F清除所有规则来暂时停止防火墙: (警告:这只适合在没有配置防火墙的环境中,如果已经配置过默认规则为deny的环境,此步骤将使系统的所有网络访问中断)
如果想清空的话,先执行
/sbin/iptables -P INPUT ACCEPT
然后执行
/sbin/iptables -F

4. connector优化apr之安装apr

12 tomcat 配置优化

cd ~/Documents/tar/APR
sudo tar zxvf apr-1.7.0.tar.gz
cd apr-1.7.0
sudo ./configure --prefix=/usr/local/apr
sudo make  
sudo make install  
cd ..
sudo tar -zxvf apr-iconv-1.2.2.tar.gz
cd apr-iconv-1.2.2
sudo ./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr  
sudo make  
sudo make install
cd ..
apt-get install libexpat1-dev
sudo tar zxvf apr-util-1.6.1.tar.gz  
cd apr-util-1.6.1
sudo ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
sudo make  
sudo make install 


# tomcat-native.tar.gz
cd /usr/tomcat8/bin
tar zxvf tomcat-native.tar.gz
cd tomcat-native-1.2.28-src
cd native
sudo ./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/openssl --with-java-home=/usr/local/jdk1.8.0_261  CXXFLAGS=-fPIC
sudo make
sudo make install
  • 报错 Your version of OpenSSL is not compatible with this version of tcnative
    12 tomcat 配置优化
  • 解决:sudo ./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/openssl --with-java-home=/usr/local/jdk1.8.0_261
    12 tomcat 配置优化
  • 解决:
tar zxvf openssl-1.0.2u.tar.gz
cd ~/Documents/tar/APR


cd openssl-1.0.2u
sudo ./config  --prefix=/usr/local/openssl


修改原来的Makefile文件
sudo vim Makefile 
将原来的:CFLAG=     -DOPENSSL_THREADS
修改为:CFLAG= -fPIC -DOPENSSL_THREADS
也就是添加 -fPIC
执行:
如果你之前执行过sudo ./config 的话,记得这里要make clean 一下哦
sudo make
sudo make install
# 终于搞完,sudo make && make install 不行,必须要分开

12 tomcat 配置优化
12 tomcat 配置优化

5 apr优化之配置优化

  • 1 vi conf/server.xml
cd /usr/tomcat8
sudo vim conf/server.xml


<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443" />


<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />

12 tomcat 配置优化

12 tomcat 配置优化

  • 2 sudo vim bin/catalina.sh
    JAVA_OPTS="JAVAOPTSDjava.library.path=/usr/local/apr/libaprjvmnativemetaspaceJVMXX:MetaspaceSize=128mJAVAOPTS="serverXms2048MXmx2048MXX:MetaspaceSize=128MXX:+HeapDumpOnOutOfMemoryErrorXX:HeapDumpPath=CATALINA_HOME/logs/heap.dump"

12 tomcat 配置优化
ps -ef | grep tomcat
sudo kill -9 pid
sudo sh bin/startup.sh
tail -f ./logs/catalina.out
12 tomcat 配置优化

  • 压测一下
    rm -f redis_mq/miaosha_redis_mq.jtl
    ./bin/jmeter.sh -n -t ./redis_mq/miaosha_redis_mq.jmx -l ./redis_mq/miaosha_redis_mq.jtl
  • NOTE 可是,我们这里用的好像是spring-boot自带的tomcat呀,并不是我们配的tomcat,那么要是不是需要重新去打war包然后部署???呜呜呜
    12 tomcat 配置优化
上一篇:tomcat 调优-生产环境必备


下一篇:【庖丁解牛】rm: cannot remove ‘libtoolT‘: No such file or directory