在 CentOS(以及其它 Linux 发行版)中,nohup 默认会把输出写入当前目录下的 nohup.out 文件。如果你想自定义日志路径,可以通过输出重定向来实现。
nohup your_command > /path/to/log.log 2>&1 &
说明:
>:标准输出重定向到指定文件2>&1:标准错误也重定向到标准输出(即同一个日志文件)&:后台运行示例:
nohup java -jar app.jar > /var/log/app.log 2>&1 &
nohup your_command > /path/to/out.log 2> /path/to/err.log &
使用 >> 而不是 >:
nohup your_command >> /path/to/log.log 2>&1 &
cd /opt/app
nohup ./start.sh > /var/log/app.log 2>&1 &
datenohup your_command > /var/log/app_$(date +%Y%m%d).log 2>&1 &
logrotate(推荐生产环境)示例 /etc/logrotate.d/app:
/var/log/app.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}
可能你写了:
nohup command &
没重定向,默认才会生成 nohup.out
确保日志目录可写:
touch /path/to/log.log
chmod 644 /path/to/log.log
如果你有 具体命令(如 Python / Java / Shell 脚本),我可以帮你写一条完整的 nohup 启动命令。