Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS 7.7 Tomcat 8.5 turns on APR operation mode

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Three operation modes of Tomcat:

(1) the blocking BIO:Blocking O operation means that Tomcat uses the traditional Java ID O operation (that is, the java.io package and its subpackages). Each request needs to be processed by creating a thread, which is the default operation mode of Tomcat 7 and previous versions, with the worst performance without any optimization.

(2) A new NIO:Non-Blocking NIO:Non-Blocking O operation (i.e. java.nio packets and its subpackages) provided by Java nio 1.4 and later versions, which can handle a large number of requests through a small number of threads, is the default operation mode of Tomcat 8. Java nio is a buffer-based Java API that can provide non-blocking Ithanso operations. It makes it have better concurrency performance than the traditional Ihammer O operation mode.

(3) APR:Apache Portable Runtime,Apache portable runtime, which is the core of Apache HTTP Server2.x. Tomcat calls the core dynamic link library of the Apache HTTP server in the form of JNI (Java Native Interface,Java Local Interface) to handle file reading or network transfer operations, thus greatly improving the performance of Tomcat in dealing with static files and solving the asynchronous Icano problem from the operating system level. Using APR can provide better scalability and higher performance, and better integration with the underlying services. APR mode is the preferred mode for running highly concurrent applications in Tomcat production environment.

2. Install JDK:

# tar-xf jdk-8u241-linux-x64.tar.gz-C / usr/local

# cd / usr/local

# mv jdk1.8.0_241/ jdk

3. Configure JDK environment variables:

# vim / etc/profile.d/jdk.sh

Export JAVA_HOME=/usr/local/jdk

Export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

Export PATH=$JAVA_HOME/bin:$PATH

#. / etc/profile.d/jdk.sh

# echo $JAVA_HOME

# java-version

4. Install related software packages by yum: # yum-y install gcc make openssl openssl-devel expat-devel

5. Compile and install apr:

# tar-xf apr-1.7.0.tar.gz-C / usr/src

# cd / usr/src/apr-1.7.0

# vim configure-- > comment $RM "$cfgfile" on line 31880 with the # sign

#. / configure-prefix=/usr/local/apr-enable-profile-enable-threads-with-sendfile

# make & & make install

# vim / etc/profile.d/apr.sh

Export LD_LIBRARY_PATH=/usr/local/apr/lib:$LD_LIBRARY_PATH

#. / etc/profile.d/apr.sh

6. Compile and install apr-iconv:

# tar-xf apr-iconv-1.2.2.tar.gz-C / usr/src

# cd / usr/src/apr-iconv-1.2.2

#. / configure-prefix=/usr/local/apr-iconv-with-apr=/usr/local/apr

# make & & make install

7. Compile and install apr-util:

# tar-xf apr-util-1.6.1.tar.gz-C / usr/src

# cd / usr/src/apr-util-1.6.1

#. / configure-prefix=/usr/local/apr-util-with-apr=/usr/local/apr-with-apr-iconv=/usr/local/apr-iconv/bin/apriconv

# make & & make install

8. Decompress Tomcat:

# tar-xf apache-tomcat-8.5.50.tar.gz-C / usr/local

# cd / usr/local

# mv apache-tomcat-8.5.50/ tomcat

9. Compile and install tomcat-native:

# cd / usr/local/tomcat/bin

# tar-xf tomcat-native.tar.gz

# cd tomcat-native-1.2.23-src/native

#. / configure-with-apr=/usr/local/apr-with-java-home=/usr/local/jdk

# make & & make install

10. Configure Tomcat environment variables:

# vim / etc/profile.d/tomcat.sh

Export CATALINA_HOME=/usr/local/tomcat

Export PATH=$CATALINA_HOME/bin:$PATH

Export JAVA_HOME=/usr/local/jdk

Export JRE_HOME=$JAVA_HOME/jre

#. / etc/profile.d/tomcat.sh

# echo $CATALINA_HOME

# catalina.sh version

11. View the default operation mode of Tomcat 8.5:

# configtest.sh

12. Modify server.xml configuration file:

# cd / usr/local/tomcat/conf

# cp server.xml {, .bak}

# vim server.xml

Before modification (NIO mode)

Modified (APR mode)

Note:

(1) two kinds of connectors for Tomcat, HTTP and AJP

(2) AJP:Apache JServ Protocol, a packet-oriented TCP/IP-based protocol that transmits readable text using binary format

13. Modify catalina.sh script file:

# vim / usr/local/tomcat/bin/catalina.sh, add the following code under the first line #! / bin/sh:

CATALINA_OPTS= "$CATALINA_OPTS-server-Xms512m-Xmx512m-Djava.library.path=/usr/local/apr/lib"

14. View the running mode after configuration:

# catalina.sh configtest

15. Start Tomcat:

# useradd tomcat

# chown-R tomcat.tomcat / usr/local/tomcat

# su-tomcat-c "startup.sh"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report