SoFunction
Updated on 2025-03-08

How to use Apr for Tomcat8.0.44 configuration under Linux

I heard that Apr can improve tomcat's performance a lot, and the configuration is as follows

1. Install apr 1.5.2

[root@ecs-3c46 ]# cd /usr/local/src
[root@ecs-3c46 src]# wget //apr/apr-1.5.
[root@ecs-3c46 src]# tar -xzvf apr-1.5.
[root@ecs-3c46 src]# cd apr-1.5.2
[root@ecs-3c46 apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@ecs-3c46 apr-1.5.2]# make
[root@ecs-3c46 apr-1.5.2]# make install

2. Install apr-util-1.5.4

[root@ecs-3c46 ]# cd /usr/local/src
[root@ecs-3c46 src]# wget /apache//apr/apr-util-1.5.
[root@ecs-3c46 src]# tar -xzvf apr-util-1.5.
[root@ecs-3c46 src]# cd apr-util-1.5.4
[root@ecs-3c46 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr
[root@ecs-3c46 apr-util-1.5.4]# make
[root@ecs-3c46 apr-util-1.5.4]# make install

3. If you do not have openssl installed, please install openssl. If you have installed it, continue to the next step.

4. Install the tomcat-native component and found that there are already relevant files under the bin directory of tomcat8.0.44

After decompression, get the tomcat-native-1.2.12-src folder

[root@ecs-3c46 bin]# tar -xzvf 
[root@ecs-3c46 bin]# cd tomcat-native-1.2.12-src/native
[root@ecs-3c46 native]# ./configure --with-apr=/usr/local/apr --with-java-home=/usr/local/java/jdk1.7.0_80 --with-ssl=/usr/local/openssl --prefix=/usr/local/tomcat/apache-tomcat-8.0.44
[root@ecs-3c46 native]# make
[root@ecs-3c46 native]# make install

Configuration, default tomcat8.0.44 is enabled Apr, and configuration is performed in Listener node.

<Listener SSLEngine="on" className=""/>

A problem occurred after restarting the tomcat service, indicating that Apr has not been successfully used

27-Jul-2017 15:50:13.488 INFO [main]  The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the : /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

Solution:

Create a link to /usr/local/apr/lib/.0.2.12 under /usr/java/packages/lib/amd64 directory

[root@ecs-3c46 native]# cd /usr/java/
[root@ecs-3c46 java]# mkdir packages/
[root@ecs-3c46 java]# cd packages/
[root@ecs-3c46 packages]# mkdir lib
[root@ecs-3c46 packages]# cd lib
[root@ecs-3c46 lib]# mkdir amd64
[root@ecs-3c46 lib]# cd amd64
[root@ecs-3c46 amd64]# ln -s /usr/local/apr/lib/.0.2.12 
[root@ecs-3c46 amd64]# ln -s /usr/local/apr/lib/.0.2.12 .0

6. Restart tomcat. If the following information is displayed, it means that the configuration has been successfully configured.

27-Jul-2017 16:16:29.479 INFO [main]  Loaded APR based Apache Tomcat Native library 1.2.12 using APR version 1.5.2.
27-Jul-2017 16:16:29.479 INFO [main]  APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
27-Jul-2017 16:16:29.491 INFO [main]  OpenSSL successfully initialized (OpenSSL 1.0.2l 25 May 2017)

The above method of using Apr for Tomcat8.0.44 configuration under Linux is all the content I share with you. I hope you can give you a reference and I hope you can support me more.