Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CentOS开机启动脚本 #15

Open
johnnian opened this issue Jul 5, 2017 · 0 comments
Open

CentOS开机启动脚本 #15

johnnian opened this issue Jul 5, 2017 · 0 comments
Labels

Comments

@johnnian
Copy link
Owner

johnnian commented Jul 5, 2017

CentOS下,开机启动脚本,可以通过配置/etc/rc.d/rc.local来设定

要配置开机自启动,先执行:

chmod +x /etc/rc.d/rc.local

1. 配置:/etc/rc.d/rc.local

[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            

备注:

  1. 如果发现还是不会执行/etc/rc.d/rc.local, 请确认下该脚本是否有执行的权限;
  2. 如果没有该脚本,可以自己创建一个,或者安装ssh客户端,安装完成后会自动创建,yum -y install openssh-clients;

附录

@johnnian johnnian added the Linux label Jul 5, 2017
@johnnian johnnian changed the title 关于/etc/rc.d/rc.local的备忘 CentOS开机启动脚本 Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant