一、说明
Tomcat8.0起已经默认nio模式,不需要做修改,8.5及9.0官方文档这样写Tomcat 8.5 and 9.0 have completely dropped the BIO connector.
二、简述及配置
2.1 bio
没经过任何优化和处理,几百并发性能极低下。配置server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
2.2 nio
利用java的异步io护理技术,no blocking IO技术。配置server.xml
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
2.3 apr模式
安装最困难,操作系统级别的控制,但也是在Tomcat上运行高并发应用的首选模式。配置server.xml
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
配置apr模式之后还需要安装 apr 、 apr-utils 、tomcat-native包
apr 安装
# tar zxf apr-1.5.2.tar.gz -C /usr/local/src/
# cd /usr/local/src/apr-1.5.2/
# ./configure --prefix=/usr/local/apr && make && make install
apr-utils 安装
# tar zxf apr-util-1.5.4.tar.gz -C /usr/local/src/
# cd /usr/local/src/apr-util-1.5.4/
# ./configure --with-apr=/usr/local/apr/ --prefix=/usr/local/apr-utils && make && make install
tomcat-native安装
# cd /usr/local/apache-tomcat-7.0.65/bin/
# tar zxf tomcat-native.tar.gz
# cd tomcat-native-1.1.33-src/jni/native
# ./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/java/ && make && make install
配置APR环境变量
# vim /etc/profile
新增配置以下配置
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
使配置生效
# source /etc/profile