Deploying spring boot programs using Linux
*** After using the command to start the program, if SSH is disconnected, will the program be shut down? The first problem is easy to solve. You only need to ensure that the JDK is installed correctly, so there will be no big problem. The thorny problem is the latter one. The key to solving the problem is to ensure that the program runs in a daemon (background mode). This time, let's share how to correctly deploy the program under Linux
In order to solve this problem, I consulted the information on the Internet and found the following three solutions
1. Turn the jar package into a system service (not recommended)
The disadvantage of this method is also obvious, that is, it is easy to fail to start the service, because different Linux distributions are more or less different
2. Use nohup command with kill - 9 XXX
This method is easy to accept and a compromise, but it is troublesome to stop the program. You need to use the command to find the process and then use kill - 9
3. Use screen, TMUX, etc. (recommended)
Considering this method comprehensively, it is more scientific because it provides a unified interface and corresponding functions for managing multiple sessions. It is simpler to operate, but it requires a little learning cost
TMUX common commands:
$TMUX new - s session name create a new session $TMUX a - t session name access the specified session $TMUX detach / $ctrl-b D disconnect the current session $TMUX kill session - t session name close the session
$TMUX LS show all sessions
Screen common commands:
$screen - s window name new session $screen - R session number or name access specified session / reconnect session $screen - LS display all sessions Ctrl + a B separate current session Ctrl + a k
Here are the differences between them. Although TMUX is relatively advanced, how to choose depends on your usage habits
TMUX is similar to screen, but better than screen. The simple answer to where to say hello is that although it has the same function as screen, TMUX is better designed. Although screen is available, it is very unstable.
Here are some TMUX advantages over screen:
It is convenient for spring boot to use Maven for packaging. Check POM XML to ensure the following configuration:
Just use Maven install for packaging. If the packaging is successful, find the corresponding jar, rename it and upload it to the Linux server for authorization
In this way, the application is started. Even if the command line is closed or disconnected from SSH, the normal operation of the program will not be affected
Disconnect
After the session ends, the program is shut down, as shown below
The use of screen is similar to that of TMUX. It has been practiced here. Deploy the program to run in the background. The effect of selecting screen and TMUX is similar.
PS: let's introduce how to deploy spring boot for Linux
First clean the project maven, then make a jar package of Maven install on the project, and then delete the process of the previous version on Linux
View the command of java process PS - EF | grep Java
Kill process - 9 process number
Directly run the spring boot project nohup Java - jar sinocube Jar & when using nohup, be sure to end with &
Nohup returns the output log file. The log file name can be customized. The default is nohup nohup. out
cat nohup. Out view log nohup Out is the file name tail nohup Out view log in real time