1 introduction

Now in general, it is rarely necessary to deploy tomcat separately, after all, Spring Boot jar package, you can use the built-in Tomcat, use this not good?

However, some projects still use Spring MVC, so Tomcat installation and deployment are still required.

War file

A War package is a packaged format for Java Web development, which includes Java code and possibly HTML, CSS, and javascript front-end code.

After development, the source code needs to be packaged into a War and distributed on a Linux server.

The War package is stored in webapps under Tomcat and can be decompressed automatically when the Tomcat server is started.

2 Tomcat installation

Tomcat server is a free open source Web application server, which is a lightweight application server. It is widely used in small and medium sized systems and where there are not many concurrent users.

Tomcat is one of the open source and free Java Web servers, which is a project of the Apache Software Foundation, so you need to install the Java JDk before installing Tomcat.

By default, our server is JDK, if not, please install, here is not repeated;

Download tomcat

Here we use Tomcat9, download address

Here we use apache-tomcat-9.0.37.tar.gz

You can download it manually or run the wget command on the server.

10 opt root @ # wget HTTP: / / http://apache.mirrors.pair.com/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gzCopy the code

Unpack the

[root@10 opt]# tar-xvf apache-tomcat-9.0.37.tar.gzCopy the code

Enter the apache tomcat — 9.0.37

[root@10 apache-tomcat-9.0.37]# ll total amount 144 drwxr-x-- 2 root root 4096 August 15 09:07 bin -rw-r----- 1 root root 18982 July 1 DRWX ------ 2 root root 4096 7月 1 04:14 conf-rw-r ----- 1 root root 5409 7月 1 04:14 CONTRIBUTING. Md Drwxr-x -- 2 root root 4096 August 15 09:07 lib-rw-r ----- 1 root root 57092 July 1 04:14 LICENSE drwxr-x-- 2 root root 4096 7月 1 04:09 logs -rw-r----- 1 root root 2333 July 1 04:14 notice-rw-r ----- 1 root root 3255 July 1 04:14 readme.md -rw-r----- 1 root root 6898 Jul 1 04:14 releas-notes-rw-r ----- 1 root root 16262 Jul 1 04:14 running. TXT drwxr-x-- 2 Temp drwxr-x-- 7 root root 4096 7月 1 04:12 webapps drwxr-x-- 2 root root 4096 7月 1 04:09 workCopy the code

Go to the bin directory

[root@10 apache-tomcat-9.0.37]# CD bin/ [root@10 bin]# ll 876-rw-r ----- 1 root root 35926 7月 1 04:11 bootstrap.jar -rw-r----- 1 root root 16608 Jul 1 04:11 Catalina. bat -rwxr-x-- 1 root root 25245 Jul 1 04:12 catalina.sh -rw-r----- 1 Root root 1664 7月 1 04:14 Catalina-tasks. XML -rw-r----- 1 root root 2123 7月 1 04:11 ciphers.bat -rwxr-x-- 1 root root Sh-rw-r ----- 1 root root 25197 July 1 04:11 Commons -daemon.jar -rw-r----- 1 root root 206895 July 1 04:12 Commons -daemon- native-tar.gz -rw-r----- 1 root root 2040 July 1 04:11 configtest.bat -rwxr-x-- 1 root root 1922 July 1 1 04:12 configtest.sh -rwxr-x-- 1 root root 9100 jul 1 04:12 daemon.sh -rw-r----- 1 root root 2091 Jul 1 04:11 Bat -rwxr-x-- 1 root root 1965 7月 1 04:12 digest. Sh -rw-r----- 1 root root 3606 7月 1 04:11 makebase.bat -rwxr-x-- 1 root root 3382 7月 1 04:12 makebase. Sh -rw-r----- 1 root root 3460 7月 1 04:11 setclasspath. Bat -rwxr-x-- 1 Root root 3708 July 1 04:12 setclasspath. Sh -rw-r----- 1 root root 2020 July 1 04:11 shutdown.bat -rwxr-x-- 1 root root Sh-rw-r ----- 1 root root 2022 7月 1 04:11 startup.bat -rwxr-x-- 1 root root 1904 July 1 04:12 Startup. sh -rw-r----- 1 root root 49301 7月 1 04:11 tomcat-juli.jar -rw-r----- 1 root root 419572 7月 1 04:12 Tomcat-native-tar. gz -rw-r----- 1 root root 4574 7月 1 04:11 tool-wrapper.bat -rwxr-x-- -1 root root 5540 7月 1 04:12 Tool-wrapper. sh -rw-r----- 1 root root 2026 Jul 1 04:11 version.bat -rwxr-x-- -- 1 root root 1908 Jul 1 04:12 version.shCopy the code

Start tomcat

[root@10 bin]# sh startup.sh Using CATALINA_BASE: /opt/apache-tomcat-9.0.37 Using CATALINA_HOME: /opt/apache-tomcat-9.0.37 Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.37/temp Using JRE_HOME: /usr Using CLASSPATH: / opt/apache tomcat - 9.0.37 / bin/bootstrap jar: / opt/apache tomcat - 9.0.37 / bin/tomcat - juli. Jar tomcat is started.Copy the code

Enabling the Firewall

The default port is 8080, which is enabled on the firewall

cd /etc/sysconfig
vim iptables

#add
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT

#restart
service iptables restart

#If you do not want to modify the iptables table, type the following command
#Linux iptables open port command
iptables -I INPUT -p tcp --dport 8080 -j ACCEPT  
Copy the code

OK, Tomcat is deployed successfully and access is normal.

How to find the location of the execution program through the port

[root@10 bin]# lsof -i:8080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 26236 root 56u IPv6 795405 0t0 TCP *:webcache (LISTEN) [root@10 bin]# netstat -antlp|grep 8080 tcp 0 0 :::8080 :::* LISTEN 26236/java [root@10 bin]# cd /proc/26236 [root@10 26236]# ll total amount 0 dr-xr-xr-x 2 root root 0 8月 15 09:16 attr-rw-r --r-- 1 root root 0 8月 15 09:17 Autogroup -r-------- 1 root root 0 8月 15 09:17 auxv-r --r--r-- 1 root root 0 8月 15 09:17 cgroup --w------- 1 root root 0 8月 15 09:17 clear_refs -r--r--r-- 1 root root 0 8月 15 09:13 cmdline-rw-r --r-- 1 root root 0 8月 15 09:17 comm -rw-r--r-- 1 root root 0 8月 15 09:17 coreDump_filter -r--r-- 1 root root 0 8月 15 09:17 cpuset LRWXRWXRWX 1 root root 0 8月 15 09:17 CWD -> /opt/apache-tomcat-9.0.37/bin... .Copy the code

3 Deploy the WAR application

Let’s take Jenkins for example:

FTP uploading to the server

Here I use wget direct download!

Wget HTTP: / / http://mirrors.jenkins-ci.org/war/2.252/jenkins.warCopy the code

Restart the service

[root@10 apache-tomcat-9.0.37]# cd bin/
[root@10 bin]# sh shutdown.sh
[root@10 bin]# sh startup.sh
Copy the code

The default access path is Ip:8080/productName

How to remove the productName layer path

<Context path="" docBase="jenkins" reloadable="true"></Context>#docBase should be changed to your project directory. #reloadable = true #reloadable = true #reloadable = true #reloadable = true #reloadable = true #reloadable = true<Context path="/test" docBase="jenkins" reloadable="true"></Context>
Copy the code

Then, restart Tomcat

[root@10 bin]# sh Using CATALINA_BASE: /opt/apache-tomcat-9.0.37 Using CATALINA_HOME: /opt/apache-tomcat-9.0.37 Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.37/temp Using JRE_HOME: /usr Using CLASSPATH: / opt/apache tomcat - 9.0.37 / bin/bootstrap jar: / opt/apache tomcat - 9.0.37 / bin/tomcat - juli. Jar [10 bin] root @ # sh startup. Sh Using CATALINA_BASE: /opt/apache-tomcat-9.0.37 Using CATALINA_HOME: /opt/apache-tomcat-9.0.37 Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.37 Using CATALINA_TMPDIR: /opt/apache-tomcat-9.0.37/temp Using JRE_HOME: /usr Using CLASSPATH: / opt/apache tomcat - 9.0.37 / bin/bootstrap jar: / opt/apache tomcat - 9.0.37 / bin/tomcat - juli. Jar tomcat is started.Copy the code

End of this article!