An article explaining the deployment of web projects (war packages) on Linux

Generate war package

​ First, we need to package the Web project into a war package

Insert image description here

Connect to Linux server

​ Here we use the SSH client to connect to the remote Linux server. We need to know the Linux IP address, login user name, password, etc. in advance;

Commonly used SSH tools include Xshell, Xftp, etc., as well as MobaXterm, etc.

​ Here is demonstrated through the MobaXterm tool:

If you have not installed or used this MobaXterm tool, you can refer to this article: Remote tool MobaXterm installation

​ Open the MobaXterm tool and select Session:
Insert image description here

​ Enter the Linux IP address and click OK to connect:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-S7rQRo9D-1688708578234) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707113616252.png)]

After the connection is successful, you will enter the command line terminal. We can enter the user name and password (the password is hidden by default, just enter it normally):

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-xK6X65Dz-1688708578235) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707114000621.png)]

After the username and password are verified, we officially enter the command line window:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-yXOhaMag-1688708578235) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707114220652.png)]

Enter the Tomcat container

​ Next, we need to enter the directory where Tomcat is located on Linux (if it is not installed, you need to install Tomcat on Linux first). Of course, the premise is that we need to know the directory where tomcat is located. For example, here is /usr/local/tomcat ;Then I will enter through the command: cd /usr/local/tomcat:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-zLoClKPE-1688708578236) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707115854762.png)]

For convenience, we need to keep the folder on the left and the command line window synchronized for subsequent file operations. Check the following buttons:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-re76eRf2-1688708578236) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707123117045.png)]

Close original service

Before deploying the war package, we need to shut down the originally started tomcat, otherwise when you start it new, the startup may fail due to port occupation;

​ We first use the ps -ef | grep tomcat command to check whether there is a started tocmat, and make sure it is the tomcat started in the current directory.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-csIp0v20-1688708578236) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707124822360.png)]

​ You can see that tomcat is already running in the directory to be deployed. We run: ./shutdown.sh to shut it down:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-P4K83PHZ-1688708578237) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707125109165.png)]

Back up the original War package

​ Then we enter the tomcat webapps directory:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-DNUOQaQB-1688708578237) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707125726982.png)]

You can see the previously deployed war package and the files decompressed after running. We need to back up the previous war package first (it can be rolled back if an upgrade error occurs).

Deploy new War package

​ Then, in the file operation window on the left, we delete the original war package through the toolbar, and then upload the previously prepared war package.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-MinEBNhc-1688708578238) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707133210902.png)]

Start Tomcat

After deploying the new war package to the webapps directory, we return to the bin directory and start tomcat through the ./startup.sh command:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-rBzxu8UL-1688708578238) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707133450292.png)]

At this point, tomcat has been successfully started!

Check the startup log to ensure normal startup

​ If after tomcat starts successfully, we first check the real-time log after startup. What should we do?

We can enter the log directory and use the tail -f -n 100 catalina.out command to view the last 100 real-time log information and support dynamic refresh:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-aV5FKy3m-1688708578239) (C:\Users\lixuewen\AppData\Roaming\Typora\typora-user-images\ image-20230707134046567.png)]

Use the lina.out command to view the last 100 log messages in real time and support dynamic refresh:

[External link pictures are being transferred...(img-aV5FKy3m-1688708578239)]

​ If you don’t want to read it, you can use ctrl + C to stop the above query.

Guess you like

Origin blog.csdn.net/weixin_40709965/article/details/131595083