码迷,mamicode.com
首页 > 其他好文 > 详细

记录tomcat优化之为tomcat安装APR

时间:2018-10-22 01:14:16      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:local   ipv6   配置   filters   hub   环境变量   random   str   prefix   

APR(Apache Portable Runtime)实现操作系统级别控制,大大提高并发处理能力;但需要安装apr和tomcat-native库;

(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
cd apr-iconv-1.2.2
./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 JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk.x86_64/
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

标签:local   ipv6   配置   filters   hub   环境变量   random   str   prefix   

原文地址:http://blog.51cto.com/quietnight/2307119

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!