方法一 修改/etc/rc.local
修改好脚本,在任意目录启动时正常执行在/etc/rc.local
的末尾添加一行以绝对路径启动脚本的行vim /etc/rc.local
#!/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./bin/bash /server/scripts/test123.sh >/dev/null 2>/dev/null
保存并重启
方法二 chkconfig管理
init.d目录下都为可执行程序,他们其实是服务脚本,按照一定格式编写,Linux 在启动时会自动执行,类似Windows下的服务 用root帐号登录,
vi /etc/rc.d/init.d/mystart
,追加如下内容:
#!/bin/bash#chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,# 6指的是重启,其他为正常启动。80为启动的优先级,05为关闭的优先机#description:mystart service#!/bin/bash# chkconfig: 3 88 88/bin/bash /server/scripts/test123.sh >/dev/null 2>/dev/null
chmod +x /etc/init.d/mystart# 添加到chkconfig,开机自启动chkconfig --add mystart# 查看服务进程的状态chkconfig --list mystart# chkconfig管理中删除chkconfig --del mystart