1、tomcat各類鏈接器比較java
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 nativeweb
一、須要的lib
APR library
OpenSSL libraries
Java SE Development Kit (JDK)apache
安裝各類libubuntu
apt-get install libapr1.0-dev libssl-dev #debian 或 yum install apr-devel openssl-devel #rhel
二、下載 tcnativecentos
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官方庫並無這個版本。tomcat
若是是centos 那就本身隨意搞了,呵呵。
若是是debian/ubuntu 就無視了bash
三、安裝編譯服務器
下面是官方作法:app
./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中。code
=======================================================================
下面是個人作法:
我這裏配置環境不太同樣,因爲前方有設備統一卸載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*
四、 推到內網下載服務器,編譯打包就完成了
省略
3、 客戶端配置
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了。