一、tomcat各种连接器比较
Java Blocking Connector Java Non Blocking Connector APR/native Connector
BIO NIO APR
Classname Http11Protocol Http11NioProtocol Http11AprProtocol
Tomcat Version 3.x onwards 6.x onwards 5.5.x onwards
Support Polling NO YES YES
Polling Size N/A maxConnections maxConnections
Read Request Headers Blocking Non Blocking Blocking
Read Request Body Blocking Blocking Blocking
Write Response Blocking Blocking Blocking
Wait for next Request Blocking Non Blocking Non Blocking
SSL Support Java SSL Java SSL OpenSSL
SSL Handshake Blocking Non blocking Blocking
Max Connections maxConnections maxConnections maxConnection
二 、编译打包apr tc native
1、需要的lib
APR library
OpenSSL libraries
Java SE Development Kit (JDK)
安装各种lib
apt-get install libapr1.0-dev libssl-dev #debian
或
yum install apr-devel openssl-devel #rhel
2、下载 tcnative
wget http://mirrors.noc.im/apache/tomcat/tomcat-connectors/native/1.2.7/source/tomcat-native-1.2.7-src.tar.gz
rhel安装要注意 1.2.7 目前支持的openssl版本最高为 OpenSSL version to 1.0.2h , 如有需要用到ssl,请先自行升级openssl,不过目前rhel官方库并没有这个版本。
如果是centos 那就自己随意搞了,呵呵。
如果是debian/ubuntu 就无视了
3、安装编译
下面是官方做法:
./configure --help
./configure --with-apr=$HOME/APR \
--with-java-home=$JAVA_HOME \
--with-ssl=$HOME/OPENSSL \
--prefix=$CATALINA_HOME
$HOME/APR is something like /usr/bin/apr-1-config or the path where apr is installed.
$JAVA_HOME is something /home/jfclere/JAVA/jdk1.5.0_09 path to a JDK installation. Any JDK should work but it is advisable to use the same JVM version the JVM you use with Tomcat.
$HOME/OPENSSL is the path where OpenSSL is installed.
$CATALINA_HOME is the path where the produced libraries will be installed. Something like $HOME/apache-tomcat-6.0.16/
按照官方文档说明,可指定各个组件的位置, 其实不写明也能自己找到。
如:
./configure --with-apr=/usr/bin/apr-1-config \
--with-java-home=/home/jfclere/JAVA/jdk1.5.0_09/ \
--with-ssl=yes \
--prefix=$CATALINA_HOME
make && make install
最后就会安装到 $CATALINA_HOME/lib中。
=======================================================================
下面是我的做法:
我这里配置环境不太一样,由于前方有设备统一卸载SSL负载,所以这里也不需要SSL, 因此不编译SSL。 步骤如下:
以下是步骤
tar -xvf tomcat-native-1.2.7-src.tar.gz
cd tomcat-native-1.2.7-src/native/
./configure --disable-openssl --prefix=/tmp/tcnative
make
make install
cd /tmp/tcnative
tar -czvf tcnative1.2.7_nossl.tgz lib/lib*
4、 推到内网下载服务器,编译打包就完成了
省略
三、 客户端配置
1\
从内网软件库下下来
cd /home/tomcat
wget http://web01/tomcat/tcnative1.2.7_nossl.tgz
tar -xvf tcnative1.2.7_nossl.tgz && rm -f tcnative1.2.7_nossl.tgz
2\
在setenv.sh 加入
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tomcat/lib
export LD_LIBRARY_PATH
3\
在 conf/server.xml 找到
这里的SSLEngine改为off 因为不需要
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
增加连接设置
<Service name="Catalina">
<Connector port="28080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="28443" />
<Connector port="28443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="200" SSLEnabled="false" />
4\
启动tomcat
startup.sh
检查tcnative是否ok
grep APR catalina.out
发现
INFO: Loaded APR based Apache Tomcat Native library 1.2.7 using APR version 1.4.8.
lsof 看一下
lsof -p PID
发现:
java 28799 app02 mem REG 253,4 763798 50359083 /home/tomcat/lib/libtcnative-1.so.0.2.7
好了配置完毕
如果需要SSL 请查阅tomcat官方文档配置, 同时tcnative编译时按照官方文档做法编译即可。这里不BB了。