記錄tomcat優化之為tomcat安裝APR
(1)安裝apr
這裏我用的是tomcat9,需要較新版本的apr,所以我這裏采用源碼的安裝方式
進入http://apr.apache.org/download.cgi 下載需要的apr 與apr-util
wget -c http://mirror-hk.koddos.net/apache//apr/apr-1.6.5.tar.gz
wget -c http://mirror-hk.koddos.net/apache//apr/apr-util-1.6.1.tar.gz
wget -c http://mirror-hk.koddos.net/apache//apr/apr-iconv-1.2.2.tar.gz
mkdir -p /usr/local/apr-1.6.5
mkdir -p /usr/local/apr-iconv-1.2.2
mkdir -p /usr/local/apr-util-1.6.1
tar -zxvf apr-1.6.5.tar.gz
這個版本的apr可能需要修改一下configure,大概在43167行那裏註釋掉$RM "$cfgfile"
vi configure# $RM "$cfgfile"
./configure --prefix=/usr/local/apr-1.6.5
make
make install
tar -zxvf apr-iconv-1.2.2.tar.gz
./configure --prefix=/usr/local/apr-iconv-1.2.2 --with-apr=/usr/local/apr-1.6.5
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr-1.6.5 --with-apr-iconv=../apr-iconv-1.2.2
make
make install
先配置幾個環境變量
向/etc/profile添加下面幾行
export CATALINA_HOME=/home/tomcat
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH:/usr/local/apr-1.6.5/bin:/usr/local/apr-util-1.6.1/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib:/usr/local/apr-1.6.5/lib/:/usr/local/apr-util-1.6.1/lib
然後source /etc/profile 註意JAVA_HOME一定要配置成自己的,你可以先通過ls -al /usr/lib/jvm/ 來查看找到路徑配入
(2)安裝tomcat-native
先安裝較新的openssl
mkdir -p /usr/local/openssl-1.1.2
wget -c https://github.com/openssl/openssl/archive/master.zip
unzip master.zip
cd openssl-master
./config --prefix=/usr/local/openssl-1.1.2
make
make install
在tomcat的安裝目錄下就有bin/tomcat-native.tar.gz,進入tomcat的安裝目錄
tar -zxvf tomcat-native.tar.gz
cd tomcat-native-1.2.17-src/native
然後就可以編譯安裝了
./configure --with-apr=/usr/local/apr-1.6.5 --with-ssl=/usr/local/openssl-1.1.2
(3)配置tomcat引入apr
向conf/server.xml添加
<Listener className="org.apache.catalina.core.AprLifecycleListener" useAprConnector="true" SSLEngine="on" />
如果要看上面參數的意思可以參考APR Lifecycle Listener說明
ln -s /usr/local/apr/lib/libtcnative-1.so /usr/lib64/libtcnative-1.so
再修改/etc/profile
export PATH=$JAVA_HOME/bin:$PATH:/usr/local/apr-1.6.5/bin:/usr/local/apr-util-1.6.1/bin:/usr/local/apr/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib:/usr/local/apr-1.6.5/lib/:/usr/local/apr-util-1.6.1/lib:/usr/local/apr/lib
然後source /etc/profile
最後再重啟tomcat
sudo -u tomcat service tomcat start -security
再進入tomcat安裝目錄下的/logs目錄下
cat catalina.2018-10-21.log
如果有出現
org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.5].
org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.2-dev xx XXX xxxx]
...
org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
...
org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
就說明安裝成功了,完畢!
記錄tomcat優化之為tomcat安裝APR