Introduction, configuration and use of tomcat
1. Introduction to tomcat
Official introduction document https://tomcat.apache.org/tomcat-10.1-doc/introduction.html
Apache Tomcat (often shortened to Tomcat) is an open source Java Servlet container, a project of the Apache Software Foundation. It provides a running environment that implements Java EE specifications such as Java Servlet and JavaServer Pages (JSP), allowing Java applications to run on Web servers.
Here are some key features and information about Tomcat:
Servlet container: Tomcat is mainly used to execute Java Servlet, which is a server-side Java program used to process client requests and generate dynamic web content. Servlets are part of the Java EE platform and they run through the environment provided by Tomcat.
JSP support: Tomcat supports JavaServer Pages (JSP), a technology that embeds HTML in Java code, making it easier for developers to create dynamic Web pages. Tomcat is responsible for interpreting and executing JSP pages.
Open source: Tomcat is an open source project and follows the Apache License. This means that it is freely available and users are free to view, modify, and distribute the source code.
Lightweight: Tomcat is designed as a lightweight Servlet container, and its core focus is to provide a simple and efficient Java Web application running environment. It focuses on performance and resource efficiency.
Modularity: Tomcat is modular, allowing users to add or remove specific functionality as needed. Users can selectively enable or disable different components based on the needs of the application.
Cross-platform: Tomcat is cross-platform and can run on various operating systems, including Windows, Linux, macOS, etc.
Easy to deploy: Tomcat provides a simple and effective deployment mechanism that can easily deploy applications by placing the WAR (Web Application Archive) file of the web application in the specified directory.
Management Tools: Tomcat includes some useful tools for managing and monitoring the server. This includes web application management, connection pool management, log viewing, etc.
Extensibility: Tomcat is extensible and supports various extensions and plug-ins. Users can extend Tomcat's functionality by adding third-party components or plug-ins.
Overall, Tomcat is an open source Servlet container widely used for hosting Java web applications. Its simplicity, lightweight, and scalability make it one of the preferred web servers for Java developers.
2. tomcat installation, configuration, file directory
Official installation document https://tomcat.apache.org/tomcat-10.1-doc/setup.html
2.1. Download tomcat
Select the tomcat version as needed
In this example, download tomcat 9.0.84
download link: https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.84/bin/apache-tomcat-9.0.84.tar.gz
文件名:apache-tomcat-9.0.84.tar.gz
sha512:85a42ab5e7e4cb1923888e96a78a0f277a870d06e76147a95457878c124001c9a317eade4ad69c249a460ffe2cbefe89 4022b84389cdf33038bc456e3699c8e3
2.2. Set environment variables
Use centos 7.6 to install apache-tomcat-9.0.84.tar.gz
and upload apache-tomcat-9.0.84.tar.gz to the /root/package/tomcat directory
cd /root/package/tomcat
tar -xzvf apache-tomcat-9.0.84.tar.gz -C /usr/local
cd /usr/local
ln -s apache-tomcat-9.0.84/ tomcat
Set java environment variables
and add 2 lines at the end of /etc/profile (/usr/local/jdk1.8.0_202 is the JDK root directory)
JAVA_HOME=/usr/local/jdk1.8.0_202
PATH=$JAVA_HOME/bin:$PATH
Set the CATALINA_HOME environment variable
and add a line at the end of /etc/profile
CATALINA_HOME=/usr/local/tomcat
source /etc/profile
2.3. Compile and install jsvc binary (a necessary library for tomcat running on Linux)
Compile and install jsvc binary (a necessary library for tomcat running on Linux)
cd $CATALINA_HOME/bin
tar xvfz commons-daemon-native.tar.gz
cd commons-daemon-1.3.4-native-src/unix
./configure
make
cp jsvc ../..
cd ../..
Command records for compiling and installing jsvc binary
[root@centos bin]# cd $CATALINA_HOME/bin
[root@centos bin]#
[root@centos bin]# tar xvfz commons-daemon-native.tar.gz
commons-daemon-1.3.4-native-src/LICENSE.txt
commons-daemon-1.3.4-native-src/NOTICE.txt
commons-daemon-1.3.4-native-src/RELEASE-NOTES.txt
commons-daemon-1.3.4-native-src/unix/
commons-daemon-1.3.4-native-src/unix/man/
commons-daemon-1.3.4-native-src/unix/native/
commons-daemon-1.3.4-native-src/unix/support/
commons-daemon-1.3.4-native-src/unix/INSTALL.txt
commons-daemon-1.3.4-native-src/unix/Makedefs.in
commons-daemon-1.3.4-native-src/unix/Makefile.in
commons-daemon-1.3.4-native-src/unix/configure.in
commons-daemon-1.3.4-native-src/unix/man/README.txt
commons-daemon-1.3.4-native-src/unix/man/jsvc.1.xml
commons-daemon-1.3.4-native-src/unix/native/.indent.pro
commons-daemon-1.3.4-native-src/unix/native/Makefile.in
commons-daemon-1.3.4-native-src/unix/native/arguments.c
commons-daemon-1.3.4-native-src/unix/native/arguments.h
commons-daemon-1.3.4-native-src/unix/native/debug.c
commons-daemon-1.3.4-native-src/unix/native/debug.h
commons-daemon-1.3.4-native-src/unix/native/dso-dlfcn.c
commons-daemon-1.3.4-native-src/unix/native/dso-dyld.c
commons-daemon-1.3.4-native-src/unix/native/dso.h
commons-daemon-1.3.4-native-src/unix/native/help.c
commons-daemon-1.3.4-native-src/unix/native/help.h
commons-daemon-1.3.4-native-src/unix/native/home.c
commons-daemon-1.3.4-native-src/unix/native/home.h
commons-daemon-1.3.4-native-src/unix/native/java.c
commons-daemon-1.3.4-native-src/unix/native/java.h
commons-daemon-1.3.4-native-src/unix/native/jsvc-unix.c
commons-daemon-1.3.4-native-src/unix/native/jsvc.h
commons-daemon-1.3.4-native-src/unix/native/location.c
commons-daemon-1.3.4-native-src/unix/native/location.h
commons-daemon-1.3.4-native-src/unix/native/locks.c
commons-daemon-1.3.4-native-src/unix/native/locks.h
commons-daemon-1.3.4-native-src/unix/native/replace.c
commons-daemon-1.3.4-native-src/unix/native/replace.h
commons-daemon-1.3.4-native-src/unix/native/signals.c
commons-daemon-1.3.4-native-src/unix/native/signals.h
commons-daemon-1.3.4-native-src/unix/native/version.h
commons-daemon-1.3.4-native-src/unix/support/apfunctions.m4
commons-daemon-1.3.4-native-src/unix/support/apjava.m4
commons-daemon-1.3.4-native-src/unix/support/apsupport.m4
commons-daemon-1.3.4-native-src/unix/support/config.guess
commons-daemon-1.3.4-native-src/unix/support/config.sub
commons-daemon-1.3.4-native-src/unix/configure
commons-daemon-1.3.4-native-src/unix/man/fetch.sh
commons-daemon-1.3.4-native-src/unix/support/buildconf.sh
commons-daemon-1.3.4-native-src/unix/support/install.sh
commons-daemon-1.3.4-native-src/windows/
commons-daemon-1.3.4-native-src/windows/apps/
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/
commons-daemon-1.3.4-native-src/windows/include/
commons-daemon-1.3.4-native-src/windows/resources/
commons-daemon-1.3.4-native-src/windows/src/
commons-daemon-1.3.4-native-src/windows/xdocs/
commons-daemon-1.3.4-native-src/windows/README.txt
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/Makefile
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/prunmgr.c
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/prunmgr.h
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/prunmgr.manifest
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/Makefile
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/prunsrv.c
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/prunsrv.h
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/prunsrv.manifest
commons-daemon-1.3.4-native-src/windows/include/Makefile.inc
commons-daemon-1.3.4-native-src/windows/include/apxwin.h
commons-daemon-1.3.4-native-src/windows/include/cmdline.h
commons-daemon-1.3.4-native-src/windows/include/console.h
commons-daemon-1.3.4-native-src/windows/include/gui.h
commons-daemon-1.3.4-native-src/windows/include/handles.h
commons-daemon-1.3.4-native-src/windows/include/javajni.h
commons-daemon-1.3.4-native-src/windows/include/log.h
commons-daemon-1.3.4-native-src/windows/include/registry.h
commons-daemon-1.3.4-native-src/windows/include/rprocess.h
commons-daemon-1.3.4-native-src/windows/include/security.h
commons-daemon-1.3.4-native-src/windows/include/service.h
commons-daemon-1.3.4-native-src/windows/resources/license.rtf
commons-daemon-1.3.4-native-src/windows/src/cmdline.c
commons-daemon-1.3.4-native-src/windows/src/console.c
commons-daemon-1.3.4-native-src/windows/src/gui.c
commons-daemon-1.3.4-native-src/windows/src/handles.c
commons-daemon-1.3.4-native-src/windows/src/javajni.c
commons-daemon-1.3.4-native-src/windows/src/log.c
commons-daemon-1.3.4-native-src/windows/src/mclib.c
commons-daemon-1.3.4-native-src/windows/src/mclib.h
commons-daemon-1.3.4-native-src/windows/src/private.h
commons-daemon-1.3.4-native-src/windows/src/registry.c
commons-daemon-1.3.4-native-src/windows/src/rprocess.c
commons-daemon-1.3.4-native-src/windows/src/security.c
commons-daemon-1.3.4-native-src/windows/src/service.c
commons-daemon-1.3.4-native-src/windows/src/utils.c
commons-daemon-1.3.4-native-src/windows/xdocs/index.xml
commons-daemon-1.3.4-native-src/windows/apps/prunmgr/prunmgr.rc
commons-daemon-1.3.4-native-src/windows/apps/prunsrv/prunsrv.rc
commons-daemon-1.3.4-native-src/windows/resources/commons.bmp
commons-daemon-1.3.4-native-src/windows/resources/procrunr.ico
commons-daemon-1.3.4-native-src/windows/resources/procruns.ico
commons-daemon-1.3.4-native-src/windows/resources/procrunw.ico
commons-daemon-1.3.4-native-src/windows/resources/susers.bmp
[root@centos bin]# ls -l
total 908
-rw-r-----. 1 root root 35467 Dec 8 03:27 bootstrap.jar
-rw-r-----. 1 root root 16856 Dec 8 03:27 catalina.bat
-rwxr-x---. 1 root root 25323 Dec 8 03:27 catalina.sh
-rw-r-----. 1 root root 1664 Dec 8 03:27 catalina-tasks.xml
-rw-r-----. 1 root root 2123 Dec 8 03:27 ciphers.bat
-rwxr-x---. 1 root root 1997 Dec 8 03:27 ciphers.sh
drwxr-xr-x. 4 root root 4096 Jan 7 23:03 commons-daemon-1.3.4-native-src
-rw-r-----. 1 root root 25661 Dec 8 03:27 commons-daemon.jar
-rw-r-----. 1 root root 214214 Dec 8 03:27 commons-daemon-native.tar.gz
-rw-r-----. 1 root root 2040 Dec 8 03:27 configtest.bat
-rwxr-x---. 1 root root 1922 Dec 8 03:27 configtest.sh
-rwxr-x---. 1 root root 9100 Dec 8 03:27 daemon.sh
-rw-r-----. 1 root root 2091 Dec 8 03:27 digest.bat
-rwxr-x---. 1 root root 1965 Dec 8 03:27 digest.sh
-rw-r-----. 1 root root 3606 Dec 8 03:27 makebase.bat
-rwxr-x---. 1 root root 3382 Dec 8 03:27 makebase.sh
-rw-r-----. 1 root root 3814 Dec 8 03:27 setclasspath.bat
-rwxr-x---. 1 root root 4317 Dec 8 03:27 setclasspath.sh
-rw-r-----. 1 root root 2020 Dec 8 03:27 shutdown.bat
-rwxr-x---. 1 root root 1902 Dec 8 03:27 shutdown.sh
-rw-r-----. 1 root root 2022 Dec 8 03:27 startup.bat
-rwxr-x---. 1 root root 1904 Dec 8 03:27 startup.sh
-rw-r-----. 1 root root 49609 Dec 8 03:27 tomcat-juli.jar
-rw-r-----. 1 root root 438209 Dec 8 03:27 tomcat-native.tar.gz
-rw-r-----. 1 root root 4576 Dec 8 03:27 tool-wrapper.bat
-rwxr-x---. 1 root root 5540 Dec 8 03:27 tool-wrapper.sh
-rw-r-----. 1 root root 2026 Dec 8 03:27 version.bat
-rwxr-x---. 1 root root 1908 Dec 8 03:27 version.sh
[root@centos bin]# cd commons-daemon-1.3.4-native-src
[root@centos commons-daemon-1.3.4-native-src]# ls -l
total 28
-rw-rw-r--. 1 root root 11358 Apr 23 2023 LICENSE.txt
-rw-rw-r--. 1 root root 175 Apr 23 2023 NOTICE.txt
-rw-rw-r--. 1 root root 1749 Apr 23 2023 RELEASE-NOTES.txt
drwxrwxr-x. 5 root root 4096 Apr 23 2023 unix
drwxrwxr-x. 7 root root 4096 Apr 23 2023 windows
[root@centos commons-daemon-1.3.4-native-src]# cd unix/
[root@centos unix]# ls -l
total 180
-rwxrwxr-x. 1 root root 147628 Apr 23 2023 configure
-rw-rw-r--. 1 root root 5038 Apr 23 2023 configure.in
-rw-rw-r--. 1 root root 2598 Apr 23 2023 INSTALL.txt
-rw-rw-r--. 1 root root 1081 Apr 23 2023 Makedefs.in
-rw-rw-r--. 1 root root 1110 Apr 23 2023 Makefile.in
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 man
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 native
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 support
[root@centos unix]# ./configure
*** Current host ***
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking cached host system type... ok
*** C-Language compilation tools ***
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... -std=gnu11
checking for ranlib... ranlib
checking for strip... strip
*** Host support ***
checking C flags dependant on host system type... ok
*** Java compilation tools ***
checking for JDK location... /usr/local/jdk1.8.0_202
checking for JDK os include directory... linux
gcc flags added
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/capability.h... no
configure: WARNING: cannot find headers for libcap
*** Writing output files ***
configure: creating ./config.status
config.status: creating Makefile
config.status: creating Makedefs
config.status: creating native/Makefile
*** All done ***
Now you can issue "make"
[root@centos unix]# ls -l
total 240
-rw-r--r--. 1 root root 21923 Jan 7 23:04 config.log
-rwxr-xr-x. 1 root root 58 Jan 7 23:04 config.nice
-rwxr-xr-x. 1 root root 24479 Jan 7 23:04 config.status
-rwxrwxr-x. 1 root root 147628 Apr 23 2023 configure
-rw-rw-r--. 1 root root 5038 Apr 23 2023 configure.in
-rw-rw-r--. 1 root root 2598 Apr 23 2023 INSTALL.txt
-rw-r--r--. 1 root root 1209 Jan 7 23:04 Makedefs
-rw-rw-r--. 1 root root 1081 Apr 23 2023 Makedefs.in
-rw-r--r--. 1 root root 1110 Jan 7 23:04 Makefile
-rw-rw-r--. 1 root root 1110 Apr 23 2023 Makefile.in
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 man
drwxrwxr-x. 2 root root 4096 Jan 7 23:04 native
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 support
[root@centos unix]# make
(cd native; make all)
make[1]: Entering directory `/usr/local/apache-tomcat-9.0.84/bin/commons-daemon-1.3.4-native-src/unix/native'
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c jsvc-unix.c -o jsvc-unix.o
jsvc-unix.c: In function ‘run_controller’:
jsvc-unix.c:1311:20: warning: assignment from incompatible pointer type [enabled by default]
act.sa_handler = controller;
^
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c arguments.c -o arguments.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c debug.c -o debug.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c dso-dlfcn.c -o dso-dlfcn.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c dso-dyld.c -o dso-dyld.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c help.c -o help.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c home.c -o home.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c java.c -o java.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c location.c -o location.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c replace.c -o replace.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c locks.c -o locks.o
gcc -std=gnu11 -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/usr/local/jdk1.8.0_202/include -I/usr/local/jdk1.8.0_202/include/linux -c signals.c -o signals.o
ar cr libservice.a arguments.o debug.o dso-dlfcn.o dso-dyld.o help.o home.o java.o location.o replace.o locks.o signals.o
ranlib libservice.a
gcc -std=gnu11 jsvc-unix.o libservice.a -ldl -lpthread -o ../jsvc
make[1]: Leaving directory `/usr/local/apache-tomcat-9.0.84/bin/commons-daemon-1.3.4-native-src/unix/native'
[root@centos unix]# ls -l
total 416
-rw-r--r--. 1 root root 21923 Jan 7 23:04 config.log
-rwxr-xr-x. 1 root root 58 Jan 7 23:04 config.nice
-rwxr-xr-x. 1 root root 24479 Jan 7 23:04 config.status
-rwxrwxr-x. 1 root root 147628 Apr 23 2023 configure
-rw-rw-r--. 1 root root 5038 Apr 23 2023 configure.in
-rw-rw-r--. 1 root root 2598 Apr 23 2023 INSTALL.txt
-rwxr-xr-x. 1 root root 180080 Jan 7 23:05 jsvc
-rw-r--r--. 1 root root 1209 Jan 7 23:04 Makedefs
-rw-rw-r--. 1 root root 1081 Apr 23 2023 Makedefs.in
-rw-r--r--. 1 root root 1110 Jan 7 23:04 Makefile
-rw-rw-r--. 1 root root 1110 Apr 23 2023 Makefile.in
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 man
drwxrwxr-x. 2 root root 4096 Jan 7 23:05 native
drwxrwxr-x. 2 root root 4096 Jan 7 23:03 support
[root@centos unix]# ls -l jsvc
-rwxr-xr-x. 1 root root 180080 Jan 7 23:05 jsvc
[root@centos unix]# cp jsvc ../..
[root@centos unix]# cd ../..
[root@centos bin]# ls -l
total 1084
-rw-r-----. 1 root root 35467 Dec 8 03:27 bootstrap.jar
-rw-r-----. 1 root root 16856 Dec 8 03:27 catalina.bat
-rwxr-x---. 1 root root 25323 Dec 8 03:27 catalina.sh
-rw-r-----. 1 root root 1664 Dec 8 03:27 catalina-tasks.xml
-rw-r-----. 1 root root 2123 Dec 8 03:27 ciphers.bat
-rwxr-x---. 1 root root 1997 Dec 8 03:27 ciphers.sh
drwxr-xr-x. 4 root root 4096 Jan 7 23:03 commons-daemon-1.3.4-native-src
-rw-r-----. 1 root root 25661 Dec 8 03:27 commons-daemon.jar
-rw-r-----. 1 root root 214214 Dec 8 03:27 commons-daemon-native.tar.gz
-rw-r-----. 1 root root 2040 Dec 8 03:27 configtest.bat
-rwxr-x---. 1 root root 1922 Dec 8 03:27 configtest.sh
-rwxr-x---. 1 root root 9100 Dec 8 03:27 daemon.sh
-rw-r-----. 1 root root 2091 Dec 8 03:27 digest.bat
-rwxr-x---. 1 root root 1965 Dec 8 03:27 digest.sh
-rwxr-xr-x. 1 root root 180080 Jan 7 23:05 jsvc
-rw-r-----. 1 root root 3606 Dec 8 03:27 makebase.bat
-rwxr-x---. 1 root root 3382 Dec 8 03:27 makebase.sh
-rw-r-----. 1 root root 3814 Dec 8 03:27 setclasspath.bat
-rwxr-x---. 1 root root 4317 Dec 8 03:27 setclasspath.sh
-rw-r-----. 1 root root 2020 Dec 8 03:27 shutdown.bat
-rwxr-x---. 1 root root 1902 Dec 8 03:27 shutdown.sh
-rw-r-----. 1 root root 2022 Dec 8 03:27 startup.bat
-rwxr-x---. 1 root root 1904 Dec 8 03:27 startup.sh
-rw-r-----. 1 root root 49609 Dec 8 03:27 tomcat-juli.jar
-rw-r-----. 1 root root 438209 Dec 8 03:27 tomcat-native.tar.gz
-rw-r-----. 1 root root 4576 Dec 8 03:27 tool-wrapper.bat
-rwxr-x---. 1 root root 5540 Dec 8 03:27 tool-wrapper.sh
-rw-r-----. 1 root root 2026 Dec 8 03:27 version.bat
-rwxr-x---. 1 root root 1908 Dec 8 03:27 version.sh
[root@centos bin]#
2.4. Run tomcat
Edit configuration file
cp /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
vi /usr/local/tomcat/conf/server.xml
Find Connector port
before change
After change
Configure automatic startup at boot
vi /etc/init.d/tomcat
Add the following content
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 82 20
# description: Tomcat is a servlet runner
JAVA_HOME=/usr/local/jdk1.8.0_202
CATALINA_HOME=/usr/local/tomcat
CATALINA_BASE=/usr/local/tomcat
XMFILE=$CATALINA_HOME/conf/server.xml
JAVA_OPTS="-server -Xms3g -Xmx3g -Xmn1g -Xss256k -XX:+UseParallelGC"
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
export JAVA_HOME CATALINA_HOME CATALINA_BASE JAVA_OPTS
# See how we were called.
case "$1" in
start)
cd $CATALINA_HOME
./bin/startup.sh -config $XMFILE
;;
stop)
cd $CATALINA_HOME
./bin/shutdown.sh -config $XMFILE
;;
restart)
$0 stop
sleep 3
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
chmod +x /etc/init.d/tomcat
chkconfig --add tomcat
Start tomcat
/etc/init.d/tomcat start
Visit http://server-ip:8080 and the following page will appear, indicating that Tomcat is successfully installed.
2.5. File directory
The tomcat root directory is as follows
- bin
/bin - Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files in here. - conf
/conf - Configuration files and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container. - libplacement.jar
_ - logs
/logs - Log files are here by default.
[root@centos tomcat]# ls -lh logs/
total 64K
-rw-r-----. 1 root root 1.7K Jan 7 23:56 catalina.2024-01-07.log
-rw-r-----. 1 root root 21K Jan 8 21:28 catalina.2024-01-08.log
-rw-r-----. 1 root root 22K Jan 8 21:28 catalina.out
-rw-r-----. 1 root root 0 Jan 7 23:56 host-manager.2024-01-07.log
-rw-r-----. 1 root root 0 Jan 8 00:00 host-manager.2024-01-08.log
-rw-r-----. 1 root root 0 Jan 7 23:56 localhost.2024-01-07.log
-rw-r-----. 1 root root 1.7K Jan 8 21:28 localhost.2024-01-08.log
-rw-r-----. 1 root root 1.4K Jan 8 21:41 localhost_access_log.2024-01-08.txt
-rw-r-----. 1 root root 0 Jan 7 23:56 manager.2024-01-07.log
-rw-r-----. 1 root root 0 Jan 8 00:00 manager.2024-01-08.log
Where localhost_access_log.2024-01-08.txt is the access log in the form of
configuration access log: https://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Access_Logging
catalina.out
catalina.out is tomcat's standard output (stdout) and standard error (stderr), which are specified in tomcat's startup script catalina.sh. If not modified, stdout and stderr will be redirected here.
[root@centos tomcat]# grep -C5 CATALINA_OUT bin/catalina.sh
#
# CATALINA_BASE (Optional) Base directory for resolving dynamic portions
# of a Catalina installation. If not present, resolves to
# the same directory that CATALINA_HOME points to.
#
# CATALINA_OUT (Optional) Full path to a file where stdout and stderr
# will be redirected.
# Default is $CATALINA_BASE/logs/catalina.out
#
# CATALINA_OUT_CMD (Optional) Command which will be executed and receive
# as its stdin the stdout and stderr from the Tomcat java
# process. If CATALINA_OUT_CMD is set, the value of
# CATALINA_OUT will be used as a named pipe.
# No default.
# Example (all one line)
# CATALINA_OUT_CMD="/usr/bin/rotatelogs -f $CATALINA_BASE/logs/catalina.out.%Y-%m-%d.log 86400"
#
# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
--
if [ ! -z "$CLASSPATH" ] ; then
CLASSPATH="$CLASSPATH":
fi
CLASSPATH="$CLASSPATH""$CATALINA_HOME"/bin/bootstrap.jar
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
fi
if [ -z "$CATALINA_TMPDIR" ] ; then
# Define the java.io.tmpdir to use for Catalina
CATALINA_TMPDIR="$CATALINA_BASE"/temp
--
fi
fi
fi
shift
if [ -z "$CATALINA_OUT_CMD" ] ; then
touch "$CATALINA_OUT"
else
if [ ! -e "$CATALINA_OUT" ]; then
if ! mkfifo "$CATALINA_OUT"; then
echo "cannot create named pipe $CATALINA_OUT. Start aborted."
exit 1
fi
elif [ ! -p "$CATALINA_OUT" ]; then
echo "$CATALINA_OUT exists and is not a named pipe. Start aborted."
exit 1
fi
$CATALINA_OUT_CMD <"$CATALINA_OUT" &
fi
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
fi
--
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
else
eval $_NOHUP "\"$_RUNJAVA\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" "$CATALINA_OPTS" \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-classpath "\"$CLASSPATH\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
fi
if [ ! -z "$CATALINA_PID" ]; then
echo $! > "$CATALINA_PID"
[root@centos tomcat]#
[root@centos tomcat]#
catalina.xxxx-xx-xx.log
can understand all catalina.xxxx-xx-xx.log. The sum is catalina.out.
It can be seen from the file size that 1650+20614=22264
- temp
The temp directory used by the JVM for temporary files. - webapps
This is where your webapps go. - work
The work directory that contains temporary working directories for the deployed web applications.
2.6. Configure SSL
Reference link: https://tomcat.apache.org/tomcat-9.0-doc/ssl-howto.html
3. Use tomcat to develop your own web application
Tomcat application deployment documentation https://tomcat.apache.org/tomcat-9.0-doc/appdev/index.html