You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[root@localhost ~]$ vi /etc/rc.d/rc.local
source /etc/bashrc
<你的初始化脚本>
如果需要以普通用户的权限运行脚本,这个时候,可以这样配置(示例),可以替换成具体的用户:
[root@localhost ~]$ vi /etc/rc.d/rc.local
source /etc/bashrc
#需要先切换到对应目录,否则脚本在写日志的情况下,会报错:permission deny
cd /home/johnnian/demo #替换成实际的脚本路径目录
su johnnian -c "/home/johnnian/demo/start.sh" #替换成实际的用户、脚本路径
2. 开机启动脚本的调试
如果发现开机启动脚本有异常,或是服务没有正常启动,可以打开调试的开关、日志:
[root@localhost ~]$ vi /etc/rc.d/rc.local
#在 #!/bin/sh 后面加上下面的配置
# send stderr from rc.local to a log file
exec 2> /tmp/rc.local.log
# send stdout to the same log file
exec 1>&2
# tell sh to display commands before execution
set -x
CentOS下,开机启动脚本,可以通过配置
/etc/rc.d/rc.local
来设定要配置开机自启动,先执行:
1. 配置:/etc/rc.d/rc.local
如果需要以普通用户的权限运行脚本,这个时候,可以这样配置(示例),可以替换成具体的用户:
2. 开机启动脚本的调试
如果发现开机启动脚本有异常,或是服务没有正常启动,可以打开调试的开关、日志:
备注:
/etc/rc.d/rc.local
, 请确认下该脚本是否有执行的权限;yum -y install openssh-clients
;附录
The text was updated successfully, but these errors were encountered: