在 CentOS 上使用 nohup 时日志报错,通常不是 nohup 本身的问题,而是命令、环境、权限或输出方式导致的。下面按常见原因 → 排查方式 → 解决办法来系统说明。
nohup: failed to run command ‘xxx’: Permission denied
原因
nohup.out 无法创建)解决
chmod +x your_script.sh
或手动指定日志文件:
nohup ./your_script.sh > my.log 2>&1 &
nohup: command not found
或
./xxx: No such file or directory
原因
解决 ✅ 使用 绝对路径
nohup /usr/bin/python3 app.py > app.log 2>&1 &
✅ 或 source 环境变量
nohup bash -c "source /etc/profile && python app.py" > app.log 2>&1 &
nohup: ignoring input and redirecting stderr to stdout
nohup: failed to open ‘nohup.out’: Permission denied
原因
解决
df -h # 查看磁盘
touch nohup.out
✅ 指定输出路径
nohup command > /tmp/app.log 2>&1 &
nohup java -jar app.jar
日志里是 程序本身的错误
原因
排查
tail -f nohup.out
✅ 建议
nohup java -jar app.jar > app.log 2>&1 &
nohup command &
问题
✅ 推荐写法
nohup command > app.log 2>&1 &
在 cron / systemd 下:
nohup 可能无效✅ 改用 systemd(推荐)
[Service]
ExecStart=/usr/bin/python3 /opt/app.py
Restart=always
nohup /绝对路径/命令 > app.log 2>&1 &
tail -f app.log
ps -ef | grep 命令
你可以直接把完整报错贴出来,例如:
nohup: failed to ...Permission deniedcommand not found我可以 逐行帮你分析 ✅