How to build Apr module for tomcat performance optimization

How to build Apr module for tomcat performance optimization

Preface

Tomcat is a widely used Java web container with countless tuning options. Since Tomcat mainly runs dynamic pages such as jsp, its design is mainly optimized for dynamic pages, but its processing efficiency for static files is not high.

Many times, engineers prefer to use nginx or apache servers to assist tomcat in processing static files to improve server operation efficiency. But in fact, tomcat itself can call apache methods to process static files, greatly improving processing efficiency.

The three modes of the tomcat server are bio (message blocking mode), nio (non-blocking mode), and apr (using the apache static file processing library to process static files)

How to deploy tomcat's apr module on a brand new linux?

For machines that have been in stable use, you can go directly to step 3

1. If the yum source is found to be inappropriate before installation

CentOS 5 Modify yum source method

wget -O /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-5.repo

or

curl -o /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-5.repo

CentOS 6 Modify yum source method

wget -O /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-6.repo

or

curl -o /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7 Modify yum source method

wget -O /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-7.repo

or

curl -o /etc/yum.repos.d/CentOS-Base.repo

http://mirrors.aliyun.com/repo/Centos-7.repo

2. If the URL is parsed incorrectly curl: (6) Could not resolve host

The steps to configure dns are as follows

vim /etc/resolv.conf

#Usually it is an empty file, add these two DNS configurations in the file

nameserver 114.114.114.114
nameserver 8.8.8.8

3. Install tomcat openssl and apr components

Currently, Tomcat 8.x runs in nio mode by default, and the essence of apr is to use jni technology to call the underlying IO interface of the operating system, so you need to install the required dependencies in advance. First, you need to install openssl and apr

yum -y install openssl-devel
yum -y install apr-devel

4. Install native, apr, apr-util components

First, go to the official website of tomcat to download native, apr, apr-util components. Native can be regarded as the intermediate link between tomcat and apr. The download address is:

http://tomcat.apache.org/download-native.cgi ,

The apr address is http://apache.fayea.com//apr. You can check it with your browser because apache is updated from time to time. It may not be possible to download it with wget in the future, so it is not fixed here, everyone can download it by themselves

Unzip and install again

 tar -xvzf apr-1.6.5.tar.gz
 cd apr-1.6.5
 ./configure --prefix=/usr/local/apr
 make && make install

 tar -zxvf apr-util-1.6.1.tar.gz
 cd apr-util-1.6.1
 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

#Then make may have problems here because there is a missing compilation library expat-devel
You can use yum install expat-devel -y to install it (if this doesn't work, you can only find it from the system installation CD), then

make && make install

Install the native module again

 tar -xvzf tomcat-native-1.2.10-src.tar.gz
 cd tomcat-native-1.2.10-src/native/
 ./configure

The installation may fail at this time because the openssl version is lower. Go to the official website to check the latest version address, https://www.openssl.org/source/ and then wget it

tar -xvzf openssl-1.1.0e.tar.gz
cd openssl-1.1.0e/
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install

Wait for a while and the installation will be successful. Now enter the directory where native was just compiled and re-execute the following command to install:

./configure --with-ssl=/usr/local/openssl
make && make installefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install

5. Modify the tomcat configuration file

Enter your tomcat server directory and edit the configuration file: conf/server.xml

Change the default protocol="HTTP/1.1" to

protocol="org.apache.coyote.http11.Http11AprProtocol"

Save and exit after modification is completed

6. Configure environment variables (two ways)

Enter the tomcat installation directory

Open the bin/catalina.sh file

Just append the corresponding configuration after the original variable JAVA_OPTS, just add a new line:

JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib"

Then save and exit to complete the installation

Restart your tomcat server and see the log at the end of catalina.out

tomcat startup log

This indicates that tomcat Apr has been configured successfully.

or

Add the apr directory to the environment variables so that tomcat can search for it using system variables.

Edit /etc/profile and add the following two lines at the end:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib
export LD_RUN_PATH=$LD_RUN_PATH:/usr/local/apr/lib

After saving, execute source /etc/profile to make the configuration take effect

Then restart your tomcat server and see the log at the end of catalina.out

This indicates that tomcat Apr has been configured successfully.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Tomcat security configuration and performance optimization
  • Tomcat performance optimization (performance overview)
  • How to build a high-performance load balancing cluster with Nginx+Tomcat
  • JVM Tomcat Performance Practice (Recommended)
  • Simple summary of tomcat performance optimization methods

<<:  MySQL 8.0.11 compressed version installation and configuration method graphic tutorial

>>:  Ubuntu 18.04 MySQL 8.0 installation and configuration method graphic tutorial

Recommend

Detailed explanation of Vue development Sort component code

Table of contents <template> <ul class=&...

Vue+Router+Element to implement a simple navigation bar

This project shares the specific code of Vue+Rout...

MySQL table addition, deletion, modification and query basic tutorial

1. Create insert into [table name] (field1, field...

Do you know the meaning of special symbols in URL?

1.# # represents a location in a web page. The ch...

JavaScript Html to implement the mobile red envelope rain function page

This article example shares the specific code of ...

In-depth understanding of mathematical expressions in CSS calc()

The mathematical expression calc() is a function ...

How to use the concat function in mysql

As shown below: //Query the year and month of the...

How to enable slow query log in MySQL

1.1 Introduction By enabling the slow query log, ...

Analysis of Linux configuration to achieve key-free login process

1.ssh command In Linux, you can log in to another...

How to install MySQL 5.7 on Ubuntu and configure the data storage path

1. Install MySQL This article is installed via AP...

Tips to prevent others from saving as my web page and copying my site

Nowadays, copying websites is very common on the I...

Detailed explanation of Tomcat's Server Options

1. Configuration By default, the first two are no...