CentOS/RedHat:
1、编辑文件 /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.touch /var/lock/subsys/local
#在文件末尾加上你开机需要启动的程序或执行的命令即可(执行的程序需要写绝对路径, 添加到系统环境变量的除外),如
/usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
自己写一个 shell 脚本将写好的脚本(.sh 文件)放到目录 /etc/profile.d/ 下,系统启 动后就会自动执行该目录下的所有 shell 脚本
Debian/Ubuntu:
1、把*.sh文件放置在/etc/init.d目录中,赋予可执行权限,然后执行一下。
cd /etc/init.dchmod +x /etc/init.d/ *.sh./ *.shupdate-rc.d *.sh start 99 2 3 4 5 . stop 01 0 1 6 .
#表示在2、3、4、5这五个运行级别中,由小到大,第二十个运行*.sh
#在0、1、6三个级别中,第一个关闭*.sh。
#注意它有2个点号,效果等于下面方法:
update-rc.d *.sh defaults
(使用update-rc.d 命令来控制具体的加入,有点类似于redhat下的chkconfig命令) 删除执行下面的命令:
update-rc.d -f *.sh remove
完成后重启服务器,测试是否生效。