SpringBoot项目发布到Linux服务器上,如果按如下命令直接启动
java -jar demo.jar
那么应用起来之后如果再关闭当前窗口,这个应用也会被关闭,也就是说这个应用不是以后台方式运行的。这样是很不方便的
所以我们要以后台运行的方式启动,命令如下:
[root@VM_0_11_centos apps]# nohup java -jar register-peer-two-0.0.1-SNAPSHOT.jar > /root/logs/register.logs 2>&1 &
命令说明:
- 最后一个字符:&表示以后台方式运行
- 2>&1表示标准错误输出和标准输出
- > /root/logs/register.logs表示将应用日志输出到指定文件,输出内容即
2>&1 - nohup是命令标识
nohup命令的具体用法如下:
[root@VM_0_11_centos apps]# nohup --help
Usage: nohup COMMAND [ARG]...
or: nohup OPTION
Run COMMAND, ignoring hangup signals.
--help display this help and exit
--version output version information and exit
If standard input is a terminal, redirect it from /dev/null.
If standard output is a terminal, append output to 'nohup.out' if possible,
'$HOME/nohup.out' otherwise.
If standard error is a terminal, redirect it to standard output.
To save output to FILE, use 'nohup COMMAND > FILE'.