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

How to install and optimize Tomcat in Linux

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article will explain in detail how to install and optimize Tomcat in Linux. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Now more and more people learn linux, but some knowledge points do not know much, in view of such a situation, ape circle Linux lecturer summed up some linux knowledge points will be shared with you every day, today to share is Tomcat installation and optimization details, I hope to help you.

First of all, Tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs. For a beginner, it can be thought that when an Apache server is configured on a machine, it can be used to respond to requests for access to HTML (an application under the standard general markup language) pages. Tomcat is actually an extension of the Apache server, but at run time it runs independently, so when you run tomcat, it actually runs as a separate process from Apache.

I. introduction to Tomcat

Tomcat server is a free and open source Web application server, which is a lightweight application server. It is widely used in small and medium-sized systems and not many concurrent access users. It is the first choice for developing and debugging JSP programs. For a beginner, it can be thought that when an Apache server is configured on a machine, it can be used to respond to requests for access to HTML (an application under the standard general markup language) pages. Tomcat is actually an extension of the Apache server, but at run time it runs independently, so when you run tomcat, it actually runs as a separate process from Apache.

The trick is that when configured correctly, Apache serves the HTML page, while Tomcat actually runs the JSP page and Servlet. In addition, like Web servers such as IIS, Tomcat has the function of dealing with HTML pages, and it is also a Servlet and JSP container, and a separate Servlet container is the default mode of Tomcat. However, Tomcat is not as capable of handling static HTML as Apache servers.

II. Tomcat installation

Prepare before installation:

Before installing Tomcat, you must install JDK,JDK, whose full name is JavaDevelopmentKit, which is a java language software development kit provided by SUN company free of charge, which includes Java virtual machine (JVM). The written java source program can be compiled to produce java bytecode. As long as JDK is installed, you can use JVM to interpret these bytecode files, thus ensuring the cross-platform of Java.

In terms of platform compatibility, JDK, as a java virtual machine that interprets the bytecode file and calls the API of the operating system to achieve the corresponding function, is closely related to the number of bits of the operating system, so there are different types of versions, and Tomcat also has the above characteristics, so you need to download JDK and Tomcat in advance.

Download address of JDK:

Http://www.oracle.com/technetwork/java/javase/downloads/

Tomcat download address: http://tomcat.apache.org

1. Uninstall openjdk that comes with the system and install jdk

[root@tomcat1 ~] # rm-rf $(which java)

[root@tomcat1 ~] # tar xf jdk-7u80-linux-x64.tar

[root@tomcat1 ~] # mv jdk1.7.0_80/ / usr/local/java

two。 Extract and install Tomcat

[root@tomcat1 ~] # tar xf apache-tomcat-8.5.20.tar.gz

[root@tomcat1 ~] # mv apache-tomcat-8.5.20 / usr/local/tomcat8

3. Set the JAVA environment variable

[root@tomcat1 ~] # vim / etc/profile.d/java.sh

Export JAVA_HOME= "/ usr/local/java" # # set the java root directory

Export PATH=$PATH:$JAVA_HOME/bin:/usr/local/tomcat8/bin # add the bin subdirectory of java and directory to the PATH environment variable

[root@tomcat1] #. / etc/profile # Import the java.sh script into the environment variable to make it effective

4. Run the java-version or javac-version command to view the java version

[root@tomcat1 ~] # java-version

Java version "1.7.0,65"

Java (TM) SE Runtime Environment (build 1.7.0_65-b17)

Java HotSpot (TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

5. Start Tomcat

[root@tomcat1 ~] # / usr/local/tomcat7/bin/startup.sh

Using CATALINA_BASE: / usr/local/tomcat7

Using CATALINA_HOME: / usr/local/tomcat7

Using CATALINA_TMPDIR: / usr/local/tomcat7/temp

Using JRE_HOME: / usr/local/java

Using CLASSPATH: / usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar

Tomcat started.

Tomcat runs on port 8080 by default

[root@tomcat1 ~] # netstat-anpt | grep: 8080

Tcp 0 0: 8080: * LISTEN 3318/java

6. Close Tomcat

[root@tomcat1 ~] # / usr/local/tomcat7/bin/shutdown.sh

Browser access test http://IP: port

7. Modify port number

[root@tomcat1 ~] # vim / usr/local/tomcat8/conf/server.xml

Modify the port:

8080-9528

8005-9529

8009-9530

[root@tomcat1 ~] # / usr/local/tomcat8/bin/startup.sh

[root@tomcat1 ~] # netstat-anpt | grep java

Tcp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 15. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0

Tcp 0 0127.0.0.1 9529 0.0.0.0 * LISTEN 5625/java

Tcp 0 0 0.0.0. 0. 0. 0. 0. 0. 0. 0. 0. 15. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0

Note: disable the firewall and selinux security mechanism. If it is an Ali CVM, the console security group needs to release port 8080 of TCP protocol.

Systemctl disable firewalld permanently shuts down the firewall

Systemctl stop firewalld temporarily shuts down the firewall

Setenforce 0 shuts down Selinux

Instructions for 8.Tomcat configuration

/ usr/local/tomcat home directory (installation directory)

Bin stores script files for Tomcat started or shut down on windows or linux platforms

Conf stores various global configuration files of Tomcat, the most important of which are server.xml and web.xml

Lib stores the library files needed for Tomcat operation (JARS)

Logs stores LOG files when Tomcat executes

Webapps Tomcat's main Web release directory (including application cases) htdocs (html php)

Work stores the class files generated by jsp compilation

[root@tomcat1 ~] # ls / usr/local/tomcat/conf/

Catalina.policy Rights Control Profil

Catalina.properties Tomcat property profile

Context.xml context profile (selinux)

Logging.properties log log related configuration file

Server.xml main configuration file

Tomcat-users.xml manager-gui management user profile (administrative interface generated after Tomcat installation, which can be accessed)

Servlet,servlet-mapping,filter,MIME and other related configurations of web.xml Tomcat

Server.xml main configuration file, can modify the startup port, set the website root directory, virtual host, open https and other functions.

III. Tomcat optimization

1. Disable AJP protocol for tomcat

[root@tomcat1 conf] # vim server.xml

Note:

two。 Modify communication mode BIO to NIO to improve concurrent processing capability

# remove comments

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