首页 > 代码库 > tomcat中使用apr及性能调优
tomcat中使用apr及性能调优
tomcat8使用apr及性能调优
本次安装的软件包括:
jdk1.7.0_79
apache-tomcat-8.0.0-RC1.tar.gz
apr-1.5.2.tar.gz
apr-iconv-1.2.1.tar.gz
apr-util-1.5.4.tar.gz
tomcat-native-1.1.33-src.tar.gz
1)安装jdk1.7
cd /usr/local/src
rpm -ivh jdk-7u79-linux-i586.rpm
ln -s jdk1.7.0_79 jdk1.7
2)安装tomcat8
wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.0-RC1/bin/apache-tomcat-8.0.0-RC1.tar.gz
tar xvf apache-tomcat-8.0.0-RC1.tar.gz -C /opt
cd /opt && ln -s apache-tomcat-8.0.0-RC1 tomcat8
3)修改etc/profile文件,增加以下内容
export TOMCAT_HOME=/opt/tomcat8
export JAVA_HOME=/usr/java/jdk1.7
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$TOMCAT_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$TOMCAT_HOME/bin
srouce /etc/profile
4)创建文件
mkdir -p /data/logs/{search,tomcat}
mkdir -p /data/search/{data,index}
5)修改tomcat8/bin下的server.xml文件 参考整理的server.xml文件
server.xml配置项的信息,请参考文档:
tomcat8优化配置之server.xml文件优化:http://www.cnblogs.com/NiceTime/p/6847991.html
tomcat性能优化参考:http://www.cnblogs.com/NiceTime/p/6665416.html
其中在使用Http11AprProtocol协议时请参考文档:
http://tomcat.apache.org/tomcat-8.0-doc/config/http.html
6)修改catalina.sh文件
jdk1.7中Java HotSpot VM中各参数信息配置,参考文档:http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms1g -Xmx1g -Xss256k
-XX:NewSize=1g -XX:MaxNewSize=1g
-XX:NewRatio=4 -XX:SurvivorRatio=8
-XX:+AggressiveOpts -XX:+UseBiasedLocking
-XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=24
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:/data/logs/tomcat/gc.log
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/data/logs/tomcat/heapdump.bin
-XX:+CMSParallelRemarkEnabled -XX:+ScavengeBeforeFullGC
-XX:CMSInitiatingOccupancyFraction=85"
CATALINA_OUT=/data/logs/tomcat/catalina.out
CATALINA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=1199"
7)修改logging.properties文件
将文件中的directory的值改为 /data/logs/tomcat
或使用命令
sed -i ‘s#${catalina.base}/logs#/data/logs/tomcat#g‘ /opt/tomcat/conf/logging.properties
8)安装apr apr-iconv apr-util tomcat-native包
a)安装apr
cd /usr/local/src
wget http://mirrors.hust.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
make && make install
b)安装apr-iconv
cd /usr/local/src
wget http://mirrors.hust.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.hust.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
cd /usr/local/src
wget http://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.1.33/source/tomcat-native-1.1.33-src.tar.gz
tar xvzf tomcat-native-1.1.33-src.tar.gz
cd tomcat-native-1.1.33-src/jni/native
./configure --prefix=/usr --with-apr=/opt/apr1.5 --with-java-home=/usr/java/jdk1.7
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
useradd tomcat -s /sbin/nologin
chown -R tomcat:tomcat /opt/tomcat8/
chown -R tomcat:tomcat /data/logs/{search,tomcat}
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.7
make
cp jsvc ../../
cd ../../
./daemon.sh start
tomcat中使用apr及性能调优