后端: linux后台运行 nohup: ignoring input and appending output to ‘nohup.out’

  1. Unix/Linux下一般比如想让某个程序在后台运行,很多都是使用 & 在程序结尾来让程序自动运行。 (但是如果终端关闭,那么程序也会被关闭)
  2. 但是为了能够后台运行,那么我们就可以使用nohup这个命令。
    // nohup与&,两者并行使用的,方可保证其在后台正常运行
    nohup: ignoring input and appending output to ‘nohup.out’ (执行nohup命令的时候,经常会出现下面这种没有写入权限的错误)
    在这里插入图片描述

1)解决方法一: 后台运行

// 后台运行程序
nohup node /root/pro/serve.js >/dev/null 2>/dev/null & 
//不要直接关闭xshell终端,执行下面这个
exit

2)解决方法二:开启自动执行 (这里只针对centos7)
在centos7中,/etc/rc.d/rc.local默认不执行,

//添加执行权限
chmod +x /etc/rc.d/rc.local
//在改文件添加开机时需要执行的命令,如下图
/root/node/bin/node /root/pro/serve.js
exit 0

后端: linux后台运行 nohup: ignoring input and appending output to ‘nohup.out’_第1张图片
然后reboot重启linux后就发现改命令执行了

你可能感兴趣的:(后端,linux,bash,运维)