编辑该文件,将要执行的命令放里面
vi /etc/rc.d/rc.local
如:
/etc/init.d/mysqld start # mysql开机启动
/etc/init.d/nginx start # nginx开机启动
sh /home/shell/rabbitmq_start.sh
如果没有可执行权限,则需要增加执行权限
chmod +x rc.local
可能会出现的问题:
-
rc.local文件没有可执行权限:添加可执行权限 (备注:/etc/rc.d/rc.local为源文件,/etc/rc.local /etc/rc3.d/S99lcoal等均为软连接文件)
-
缺少环境变量,因为系统启动后最后执行rc.local,但是一些系统或者用户的环境变量没有加载:解决办法:在执行脚本之前添加source /etc/profile命令加载环境变量。今天下午执行node程序脚本不成功就是因为node变量的问题
#!/bin/sh
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
source /etc/profile
sh /home/shell/rabbitmq_start.sh
#set push_start.sh
sh /home/shell/push_start.sh
echo never > /sys/kernel/mm/transparent_hugepage/enabled
- 还有一种情况就是报错:我遇到的是启动rabbitmq时报:erlexec:home must be set 解决方法:在执行脚本里添加export HOME=/usr/local/erlang
#设置erlang家目录,否则rabbitmq不能开机自启动
export HOME=/usr/local/erlang
#rabbitmq start
/usr/local/rabbitmq/sbin/rabbitmq-server