tomcat APR模式配置

一、环境

操作系统:Ubutnu 14

ubuntu@ubuntu:~$ uname -a
Linux ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

JDK 1.8

ubuntu@ubuntu:~$ java -version
java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)
ubuntu@ubuntu:~$ whereis java
java: /usr/local/java /usr/share/java

Tomcat 8.5.35

root@ubuntu:~# /var/www/demo/bin/version.sh
Using CATALINA_BASE: /var/www/demo
Using CATALINA_HOME: /var/www/demo
Using CATALINA_TMPDIR: /var/www/demo/temp
Using JRE_HOME: /usr/local/java/jre
Using CLASSPATH: /var/www/demo/bin/bootstrap.jar:/var/www/demo/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.35
Server built: Nov 3 2018 17:39:20 UTC
Server number: 8.5.35.0
OS Name: Linux
OS Version: 4.4.0-31-generic
Architecture: amd64
JVM Version: 1.8.0_141-b15
JVM Vendor: Oracle Corporation

二、安装

1. 安装编译需要的环境

$ sudo apt install gcc make

2. 安装 native 编译所需要的依赖包

# apache apr
$ sudo apt install libapr1-dev
# openssl,自带的 openssl版本较低,需要编译安装
$ wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
$ sudo mkdir /usr/local/openssl
$ tar zxf openssl-1.1.1a.tar.gz
$ ./config --prefix=/usr/local/openssl
$ make
$ sudo make install

3.下载安装native

$ wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-connectors/native/1.2.19/source/tomcat-native-1.2.19-src.tar.gz
$ cd tomcat-native-1.2.19-src/native/
$ ./configure --with-ssl=/usr/local/openssl
$ make
$ sudo make install

三、配置Tomcat

root@ubuntu:/var/www/demo# cat bin/setenv.sh
export JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib"

<Connector port="8080"
protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443" />
...
<!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->

四、启动Tomcat

root@ubuntu:/var/www/demo# bin/catalina.sh run
.....
28-Jan-2019 15:55:09.140 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/var/www/demo/webapps/docs] has finished in [13] ms
28-Jan-2019 15:55:09.153 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
28-Jan-2019 15:55:09.172 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 803 ms

附:编译方式安装apr

1. 安装编译需要的环境

$ sudo apt install -y gcc make  libtool  libexpat1-dev

2. 安装Apache Portable Runtime (apr)

官方地址:https://apr.apache.org/compiling_unix.html

编译安装apr

wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.5.tar.gz
tar zxf apr-1.6.5.tar.gz
cd apr-1.6.5/
./configure --prefix=/usr/local/apache-apr
make
sudo make install

编译安装apr-iconv

wget http://mirrors.shu.edu.cn/apache//apr/apr-iconv-1.2.2.tar.gz
tar zxf apr-iconv-1.2.2.tar.gz
cd apr-iconv-1.2.2/
./configure --prefix=/usr/local/apache-apr-iconv --with-apr=/usr/local/apache-apr
make
sudo make install

编译安装apr-util

wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
ubuntu@ubuntu:~/apr-util-1.6.1$ ./configure --prefix=/usr/local/apache-apr-util --with-apr=/usr/local/apache-apr --with-apr-iconv=/usr/local/apache-apr-iconv/bin/apriconv
tar zxf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1/
make
sudo make install

3. 编译安装openssl

wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
$ sudo mkdir /usr/local/openssl
$ tar zxf openssl-1.1.1a.tar.gz
$ ./config --prefix=/usr/local/openssl
cd openssl-1.1.1a
$ make
$ sudo make install

4. 编译安装native

wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-connectors/native/1.2.19/source/tomcat-native-1.2.19-src.tar.gz
tar zxf tomcat-native-1.2.19-src.tar.gz
$ cd tomcat-native-1.2.19-src/native/
$ ./configure --prefix=/usr/local/native --with-ssl=/usr/local/openssl --with-apr=/usr/local/apache-apr/bin/apr-1-config
$ make
$ sudo make install
05-12 06:53