tomcat中使用apr及性能调优
Posted 新美好时代
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tomcat中使用apr及性能调优相关的知识,希望对你有一定的参考价值。
内容来自参考文档,望博主同意转载:http://blog.csdn.net/xyang81/article/details/51502766
tomcat8使用apr及性能调优
本次安装的软件包括:
CentOS7.2
jdk-8u144-linux-x64.rpm或jdk-8u144-linux-x64.tar.gz
apache-tomcat-8.0.9.tar.gz
apr-1.5.2.tar.gz
apr-iconv-1.2.1.tar.gz
apr-util-1.5.4.tar.gz
tomcat-native.tar.gz
1)安装jdk1.8
cd /usr/local/src
rpm包:http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.rpm?AuthParam=1505717415_d21fd3e0679a3bd28c73fa133ee325fa
gz包:http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz?AuthParam=1505717504_e782ec8ecaffab2487bff251059fe8c5
a)安装rpm包
rpm -ivh jdk-8u144-linux-x64.rpm
ln -s jdk-8u144-linux-x64 jdk1.8
b)安装tar.gz包
tar xvf jdk-8u144-linux-x64.tar.gz -C /opt
cd /opt && ln -s jdk-8u144-linux-x64 tomcat8
2)安装tomcat8
wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.9/bin/apache-tomcat-8.0.9.tar.gz
tar xvf apache-tomcat-8.0.9.tar.gz -C /opt
cd /opt && ln -s apache-tomcat-8.0.9 tomcat8
3)修改etc/profile文件,增加以下内容,如果1台机器上安装多个tomcat,就不要指定tomcat路径
export JAVA_HOME=/usr/java/jdk1.8
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
#这里加了这个配置项,在catalina.sh中就不用加 -Djava.library.path=/opt/apr1.5/lib
export LD_LIBRARY_PATH=/opt/apr1.5/lib
srouce /etc/profile
4)创建文件(选择操作)
mkdir -p /var/log/tomcat
5)修改tomcat8/bin下的server.xml文件 参考整理的server.xml文件
a)修改server.xml配置项的信息,请参考文档
tomcat8优化配置之server.xml文件优化:http://www.cnblogs.com/NiceTime/p/6847991.html
tomcat8性能优化参考:http://www.cnblogs.com/NiceTime/p/6665416.html
其中在使用Http11AprProtocol协议时请参考文档:http://tomcat.apache.org/tomcat-8.0-doc/config/http.html
b)修改tomcat-user.xml文件,注释原有用户,新增以下用户
<role rolename="tomcat"/>
<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="manager-status" />
<role rolename="manager-jmx"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-status,manager-jmx" />
6)修改catalina.sh文件
jdk1.7中Java HotSpot VM中各参数信息配置,参考文档:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
jdk1.8中Java HotSpot VM中各参数信息配置,参考文档:http://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
#下面是应用在jdk8的配置
JAVA_OPTS="-server -d64 -Djava.awt.headless=true -Duser.timezone=Asia/Shanghai"
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/opt/apr1.5/lib -Djava.security.egd=file:/dev/./urandom"
JAVA_OPTS="$JAVA_OPTS -Xms1g -Xmx1g -Xmn512m -Xss256k -XX:MetaspaceSize=9.6m -XX:MaxMetaspaceSize=115.2m -XX:SurvivorRatio=6"
JAVA_OPTS="$JAVA_OPTS -XX:TargetSurvivorRatio=80 -XX:CICompilerCount=4 -XX:MaxTenuringThreshold=6"
JAVA_OPTS="$JAVA_OPTS -XX:InitialCodeCacheSize=32k -XX:ReservedCodeCacheSize=256m"
JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:-UseAdaptiveSizePolicy"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/tomcat_admin/logs/java_pid%p.hprof"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/usr/local/tomcat_admin/logs/gc.log"
JAVA_OPTS="$JAVA_OPTS -Xnoclassgc -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:MaxGCPauseMillis=300 -XX:LargePageSizeInBytes=0"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=80"
JAVA_OPTS="$JAVA_OPTS -XX:+UseGCOverheadLimit -XX:AllocatePrefetchDistance=256 -XX:AllocatePrefetchStyle=1"
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=119.23.34.67
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=9017"
在使用jmc工具时,如需要打开飞行记录,需要配置以下3个参数,不用时可以先不配置:
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true
7)修改logging.properties文件(选择操作)
将文件中的directory的值改为 /var/log/tomcat8
或使用命令(选择操作)
sed -i \'s#${catalina.base}/log#/var/log/tomcat8#g\' /opt/tomcat8/conf/logging.properties
安装apr的地址:https://apr.apache.org/
8)安装apr apr-iconv apr-util tomcat-native包
a)安装apr
cd /usr/local/src
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.gz
tar xvzf apr-1.5.2.tar.gz
cd apr-1.5.2
./configure --prefix=/opt/apr1.5
#安装libtool
yum -y install libtool
#如果提示有报错
rm: cannot remove \'libtoolT\': No such file or directory
#需修改configure文件,在29605行中,修改RM=\'{$RM -f}\'
make && make install
b)安装apr-iconv
cd /usr/local/src
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-iconv-1.2.1.tar.gz
tar xvzf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/opt/apriconv1.2 --with-apr=/opt/apr1.5
make && make install
c)安装apr-util
cd /usr/local/src
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
tar xvzf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/opt/aprutil1.5 --with-apr=/opt/apr1.5 --with-apr-iconv=/opt/apriconv1.2/bin/apriconv
make && make install
d)安装tomcat-native(直接从安装的tomcat目录中复制即可,在bin目录下。)
cd /usr/local/src
wget 对应版本文件:http://archive.apache.org/dist/tomcat/tomcat-connectors/native/
tar xvzf tomcat-native.tar.gz
cd tomcat-native-1.1.30-src/jni/native
./configure --prefix=/usr --with-apr=/opt/apr1.5 --with-java-home=/usr/java/jdk1.8
make && make install
9)其他的处理(选择项,可以不用按如下操作)
a)隐藏tomcat版本信息
cd /opt/tomcat8/lib
mkdir -p org/apache/catalina/util
vim org/apache/catalina/util/ServerInfo.properties
server.info=hidden tomcat version
b)删除tomcat管理员页面
rm -rf /opt/tomcat8/webapps/*
c)以普通用户运行tomcat
看情况是否决定以普通用户启动tomcat
以root用户运行
#新建用户
su root
useradd -r tomcat
groupadd tomcat
或
useradd tomcat -s /sbin/nologin
chown -R tomcat:tomcat /opt/tomcat8/
chown -R tomcat:tomcat /var/log/tomcat8
d)安装daemon
cd /opt/tomcat/bin
tar xvzf commons-daemon-native.tar.gz
cd commons-daemon-1.0.15-native-src/unix
./configure --with-java=/usr/java/jdk1.8
make
cp jsvc ../../
cd ../../
#进入目录并授予权限
cd /opt
chown -R tomcat:tomcat /opt/tomcat8
e)启动tomcat
./daemon.sh start
#查看启动日志
tail -fn 150 ../logs/catalina-daemon.out
以上是关于tomcat中使用apr及性能调优的主要内容,如果未能解决你的问题,请参考以下文章