Detailed explanation of Tomcat server configuration in Linux Environment

Detailed explanation of Tomcat server configuration in Linux Environment

Tomcat server is a free open source Web application server. Tomcat runtime occupies small system resources, has good scalability, supports load balancing, mail service and other functions commonly used in developing application systems. Tomcat is a small lightweight application server. Like IIS, Apache and other Web servers, Tomcat has the function of processing HTML pages. In addition, it is also a Servlet and JSP container. The independent Servlet container is the default mode of Tomcat. Tomcat's ability to handle static html is not as good as Apache server.

1, Install JDK

The Tomcat server needs JDK support to run. Before installing tomcat, install Java JDk as follows:

1. Put jdk-8u162-linux-x64 tar. GZ upload to / usr/local directory

[root@test soft]# cd /usr/local
[root@test local]# ll
 Total consumption 185408
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 bin
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 etc
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 games
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 include
-rw-r--r--  1 root root 189815615 1 May 23, 2022 jdk-8u162-linux-x64.tar.gz
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 lib
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 lib64
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 libexec
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 sbin
drwxr-xr-x. 5 root root      4096 6 September 27-21:23 share
drwxr-xr-x. 2 root root      4096 9 May 23, 2011 src

2. Unzip file

[root@test local]# tar zxvf jdk-8u162-linux-x64.tar.gz 

[root@test local]# mv jdk1.8.0_162 jdk1.8
[root@test local]# rm -rf jdk-8u162-linux-x64.tar.gz 
[root@test local]# ll
 Total consumption 44
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 bin
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 etc
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 games
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 include
drwxr-xr-x  8 uucp  143 4096 12 May 20, 2017 jdk1.8
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 lib
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 lib64
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 libexec
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 sbin
drwxr-xr-x. 5 root root 4096 6 September 27-21:23 share
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 src

3. Configure environment variables

Modify the configuration file / etc/profile and add the following content at the end of the file:

[root@test local]# vi /etc/profile

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
..........

## Add the following at the end of the document:
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

4. Make environment variable configuration effective

[root@test local]# source /etc/profile

5. Testing

[root@test tomcat8.5.75]# java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

[root@test local]# javac
 usage: javac <options> <source files>
among, Possible options include:
  -g                         Generate all debugging information
  -g:none                    No debug information is generated
  -g:{lines,vars,source}     Only some debugging information is generated
  -nowarn                    No warnings are generated
  -verbose                   Outputs a message about what the compiler is doing
  -deprecation               Output using obsolete API Source location of
  -classpath <route>            Specifies where to find user class files and comment handlers
  -cp <route>                   Specifies where to find user class files and comment handlers
  -sourcepath <route>           Specifies where to find the input source file
  -bootclasspath <route>        Overwrite the location of the boot class file
  -extdirs <catalogue>              Overwrite the location of installed extensions
  -endorseddirs <catalogue>         The location of the standard path that overrides the signature
  -proc:{none,only}          Controls whether annotation processing and/Or compile.
  -processor <class1>[,<class2>,<class3>...] The name of the annotation handler to run; Bypass the default search process
  -processorpath <route>        Specifies where to find the comment handler
  -parameters                Generate metadata for reflection of method parameters
  -d <catalogue>                    Specify where to place the generated class file
  -s <catalogue>                    Specify where to place the generated source file
  -h <catalogue>                    Specifies where to place the generated native header file
  -implicit:{none,class}     Specifies whether to generate class files for implicitly referenced files
  -encoding <code>             Specifies the character encoding used by the source file
  -source <Distribution>              Provides source compatibility with the specified distribution
  -target <Distribution>              Generate specific VM Version of class file
  -profile <configuration file>            Make sure you use API Available in the specified profile
  -version                   Version information
  -help                      Output a feed of standard options
  -A keyword[=value]                  Options passed to comment handler
  -X                         Output a feed of nonstandard options
  -J<sign>                     Directly <sign> Pass to runtime system
  -Werror                    Terminate compilation on warning
  @<file name>                     Read options and filename from file

2, Install Tomcat server

1. Put apache-tomcat-8.5.75 tar. GZ upload to / usr/local /

[root@test local]# pwd
/usr/local
[root@test local]# rz
[root@test local]# ll
 Total consumption 10392
-rw-r--r--  1 root root 10595855 1 May 23, 2022 apache-tomcat-8.5.75.tar.gz
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 bin
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 etc
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 games
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 include
drwxr-xr-x  8 uucp  143     4096 12 May 20, 2017 jdk1.8
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 lib
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 lib64
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 libexec
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 sbin
drwxr-xr-x. 5 root root     4096 6 September 27-21:23 share
drwxr-xr-x. 2 root root     4096 9 May 23, 2011 src

2. Unzip file

[root@test local]# tar zxvf apache-tomcat-8.5.75.tar.gz 

[root@test local]# mv apache-tomcat-8.5.75 tomcat8.5.75
[root@test local]# rm apache-tomcat-8.5.75.tar.gz -rf
[root@test local]# ll
 Total dosage 48
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 bin
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 etc
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 games
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 include
drwxr-xr-x  8 uucp  143 4096 12 May 20, 2017 jdk1.8
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 lib
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 lib64
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 libexec
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 sbin
drwxr-xr-x. 5 root root 4096 6 September 27-21:23 share
drwxr-xr-x. 2 root root 4096 9 May 23, 2011 src
drwxr-xr-x  9 root root 4096 11 June 17-23:38 tomcat8.5.75

3. Configure environment variables

Modify the configuration file / etc/profile and add the following content at the end of the file:

[root@test local]# vi /etc/profile

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
..........
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
.........
## Add the following at the end of the document:
export CATALINA_HOME=/usr/local/tomcat8.5.75

4. Make environment variable configuration effective

[root@test local]# source /etc/profile

5. The directory structure of Tomcat server is as follows

[root@test tomcat8.5.75]# pwd
/usr/local/tomcat8.5.75
[root@test tomcat8.5.75]# ll
 Total dosage 148
drwxr-x--- 2 root root  4096 11 June 17-23:38 bin
-rw-r----- 1 root root 19481 1 August 18, 2022 BUILDING.txt
drwx------ 2 root root  4096 1 August 18, 2022 conf
-rw-r----- 1 root root  6210 1 August 18, 2022 CONTRIBUTING.md
drwxr-x--- 2 root root  4096 11 June 17-23:38 lib
-rw-r----- 1 root root 57011 1 August 18, 2022 LICENSE
drwxr-x--- 2 root root  4096 1 August 18, 2022 logs
-rw-r----- 1 root root  1726 1 August 18, 2022 NOTICE
-rw-r----- 1 root root  3378 1 August 18, 2022 README.md
-rw-r----- 1 root root  7136 1 August 18, 2022 RELEASE-NOTES
-rw-r----- 1 root root 16507 1 August 18, 2022 RUNNING.txt
drwxr-x--- 2 root root  4096 11 June 17-23:38 temp
drwxr-x--- 7 root root  4096 1 August 18, 2022 webapps
drwxr-x--- 2 root root  4096 1 August 18, 2022 work

6. Start Tomcat server

Enter the bin directory and execute startup SH script:

[root@test tomcat8.5.75]# cd bin
[root@test bin]# ll
 Total consumption 876
-rw-r----- 1 root root  36431 1 August 18, 2022 bootstrap.jar
-rw-r----- 1 root root  16840 1 August 18, 2022 catalina.bat
-rwxr-x--- 1 root root  25294 1 August 18, 2022 catalina.sh
-rw-r----- 1 root root   1664 1 August 18, 2022 catalina-tasks.xml
-rw-r----- 1 root root   2123 1 August 18, 2022 ciphers.bat
-rwxr-x--- 1 root root   1997 1 August 18, 2022 ciphers.sh
-rw-r----- 1 root root  25357 1 August 18, 2022 commons-daemon.jar
-rw-r----- 1 root root 207420 1 August 18, 2022 commons-daemon-native.tar.gz
-rw-r----- 1 root root   2040 1 August 18, 2022 configtest.bat
-rwxr-x--- 1 root root   1922 1 August 18, 2022 configtest.sh
-rwxr-x--- 1 root root   9100 1 August 18, 2022 daemon.sh
-rw-r----- 1 root root   2091 1 August 18, 2022 digest.bat
-rwxr-x--- 1 root root   1965 1 August 18, 2022 digest.sh
-rw-r----- 1 root root   3460 1 August 18, 2022 setclasspath.bat
-rwxr-x--- 1 root root   3708 1 August 18, 2022 setclasspath.sh
-rw-r----- 1 root root   2020 1 August 18, 2022 shutdown.bat
-rwxr-x--- 1 root root   1902 1 August 18, 2022 shutdown.sh
-rw-r----- 1 root root   2022 1 August 18, 2022 startup.bat
-rwxr-x--- 1 root root   1904 1 August 18, 2022 startup.sh
-rw-r----- 1 root root  51708 1 August 18, 2022 tomcat-juli.jar
-rw-r----- 1 root root 428057 1 August 18, 2022 tomcat-native.tar.gz
-rw-r----- 1 root root   4574 1 August 18, 2022 tool-wrapper.bat
-rwxr-x--- 1 root root   5540 1 August 18, 2022 tool-wrapper.sh
-rw-r----- 1 root root   2026 1 August 18, 2022 version.bat
-rwxr-x--- 1 root root   1908 1 August 18, 2022 version.sh

[root@test bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

7. Test Tomcat server

The default port of Tomcat server is 8080. Enter the address in the browser: http://192.168.1.13:8080/ You can see the following operation interface:

8. Stop server

Can be used/ shutdown. Use the SH command to stop the Tomcat server:

[root@test bin]# ./shutdown.sh
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8/jre
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:   

3, Configure Tomcat server

1. Set Tomcat server to start automatically

(1) Add bin / Catalina SH copy to / etc / init D directory and rename it tomcat

[root@test tomcat8.5.75]# cp -p /usr/local/tomcat8.5.75/bin/catalina.sh /etc/init.d/tomcat

[root@test tomcat8.5.75]# ll /etc/init.d/tomcat
-rwxr-x--- 1 root root 25294 1 August 18, 2022 /etc/init.d/tomcat

(2) Edit the tomcat file and add the following

#Add the following in the second line:
[root@test bin]# vi /etc/init.d/tomcat

#!/bin/sh
# chkconfig: 112 63 37
# description: tomcat serverinit script
# Source Function Library
./etc/init.d/functions
JAVA_HOME=/usr/local/jdk1.8
CATALINA_HOME=/usr/local/tomcat8.5.75

(3) Give new permissions to tomcat files

[root@test bin]# ll /etc/init.d/tomcat
-rwxr-x--- 1 root root 25384 11 July 19:43 /etc/init.d/tomcat
[root@test bin]# chmod 755 /etc/init.d/tomcat
[root@test bin]# ll /etc/init.d/tomcat
-rwxr-xr-x 1 root root 25384 11 July 19:43 /etc/init.d/tomcat

(4) Set Tomcat server to start automatically

[root@test bin]# chkconfig --add tomcat
[root@test bin]# chkconfig tomcat on

(5) Starting and shutting down Tomcat

# Start tomcat
[root@test bin]# service tomcat start
/etc/init.d/tomcat: line 7: ./etc/init.d/functions: Permission denied
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

# Close tomcat
[root@test bin]# service tomcat stop
/etc/init.d/tomcat: line 7: ./etc/init.d/functions: Permission denied
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:  

2. Configure the access port of tomcat service

The default access port of Tomcat is 8080. If you need to modify it, you need to modify the server XML file:

[root@test conf]# pwd
/usr/local/tomcat8.5.75/conf
[root@test conf]# ll
 Total consumption 228
drwxr-x--- 3 root root   4096 11 June 17-23:54 Catalina
-rw------- 1 root root  12954 1 August 18, 2022 catalina.policy
-rw------- 1 root root   7675 1 August 18, 2022 catalina.properties
-rw------- 1 root root   1338 1 August 18, 2022 context.xml
-rw------- 1 root root   1149 1 August 18, 2022 jaspic-providers.xml
-rw------- 1 root root   2313 1 August 18, 2022 jaspic-providers.xsd
-rw------- 1 root root   3916 1 August 18, 2022 logging.properties
-rw------- 1 root root   7580 1 August 18, 2022 server.xml
-rw------- 1 root root   2756 1 August 18, 2022 tomcat-users.xml
-rw------- 1 root root   2558 1 August 18, 2022 tomcat-users.xsd
-rw------- 1 root root 171879 1 August 18, 2022 web.xml

(1) Open file: server xml

Put:
<Connector port="8080" protocol="HTTP/1.1"
Change to:
<Connector port="80" protocol="HTTP/1.1"

(2) Restart tomcat

[root@test conf]# service tomcat stop
/etc/init.d/tomcat: line 7: ./etc/init.d/functions: Permission denied
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
[root@test conf]# service tomcat start
/etc/init.d/tomcat: line 7: ./etc/init.d/functions: Permission denied
Using CATALINA_BASE:   /usr/local/tomcat8.5.75
Using CATALINA_HOME:   /usr/local/tomcat8.5.75
Using CATALINA_TMPDIR: /usr/local/tomcat8.5.75/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat8.5.75/bin/bootstrap.jar:/usr/local/tomcat8.5.75/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.

(3) Testing

Enter in the browser: http://192.168.1.13 , the results are as follows:

Keywords: Linux Tomcat server

Added by snaack on Thu, 27 Jan 2022 23:12:30 +0200