1. 程式人生 > >tomcat中使用apr及性能調優

tomcat中使用apr及性能調優

error jdk1 rec less ken install earch als head

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及性能調優