Three ways to start tomcat on Linux server

Go directly to the topic, first cd into the bin folder of tomcat, and then try the following three startup methods:

The first (current session startup): 

./startup.sh

Effect:

 

Then tomcat starts in the background, and we can continue to enter other commands in the current session, such as

ps -ef | grep 'tomcat'

Let's check the tomcat service we just started:

You can see that its process id is 6951, we can use the following command to close it

kill 6951


This startup method is to start directly in the background, but it does not allow tomcat to run in the background all the time. When we close the session window currently connected to linux, the tomcat service will also be closed.

The second (current session startup with logs):
 

./catalina.sh run

Effect:

 The difference from the first method is that the log will be displayed after the second method is started, which means that the current Linux connection session has become a console, and no other Linux commands can be input. However, the same as the first method, when the current When the connection is closed, the tomcat service started this time will also be closed. Of course, after the startup is successful, we can also use ctrl + c to directly close the startup of tomcat in this link session.

The third type (permanent startup in the background):
1. The simplest way to write:

nohup ./startup.sh &

2. Manually specify the log path when tomcat starts:

nohup ./startup.sh > log.file 2>&1 & 


To understand the difference between the two, it depends on the specific use of nohup:

  • >log.file is to redirect the output of the command to the log.file file, that is, the output content is not printed to the screen, but output to the log.file file.
  • 2>&1 is to redirect the standard error to the standard output, where the standard output has been redirected to the log.file file, that is, the standard error is also output to the log.file file. The last & is to let the command execute in the background.
  • Just imagine what 2>1 means, the combination of 2 and > represents error redirection, and 1 represents error redirection to a file 1 instead of standard output; replace it with 2>&1, and the combination of & and 1 represents standard output. It becomes an error redirection to standard output.


Original link: https://blog.csdn.net/m0_54853420/article/details/123975074

Guess you like

Origin blog.csdn.net/listeningdu/article/details/128131577