在 CentOS 上用 nohup 启动程序时,日志一般有两种情况,查错误的方法如下:
常见启动方式:
nohup command > app.log 2>&1 &
或
nohup command &
如 app.log:
tail -f app.log
查看错误(如果有):
grep -i error app.log
nohup 默认输出到:
nohup.out
一般在当前目录:
ls -l nohup.out
tail -f nohup.out
tail -f nohup.out
或
tail -f app.log
只看错误:
tail -f app.log | grep ERROR
tail -100 nohup.out
journalctl -xe
或
dmesg | tail
grep -i "killed process" /var/log/messages
(CentOS 7 可能在 /var/log/messages 或 journalctl)
nohup command > app.log 2>&1 &
>:标准输出2>&1:错误也写进日志Permission denied → 权限问题command not found → 环境变量问题Address already in use → 端口被占No such file or directory → 路径错误如果你愿意,可以把:
发出来,我可以直接帮你定位错误。