1./etc/rc.local 自启动
2.通过chkconfig管理
如何让一个脚本被chkconfig管理
[root@oldboyedu01 ~]# vim /etc/init.d/oldgirld
# chkconfig: 2345 99 99 ##这步必须的 vim /etc/init.d/crond 配置中可见
# description:[XM1] Saves and restores system entropy pool for \
echo 1
~
[root@oldboyedu01 ~]# chmod +x /etc/init.d/oldgirld ##给文件加x执行权限
[root@oldboyedu01 ~]# chkconfig --add oldgirld ##添加自启动
[root@oldboyedu01 ~]# chkconfig |grep old
oldgirld 0:off 1:off 2:on 3:on 4:on 5:on6:off
翻译
RUNLEVEL FILES
Each service which should be manageable by chk-
config needs two or more commented lines added
to its init.d script. The first line tells chk-
config what runlevels the service should be
started in by default, as well as the start and
stop priority levels. If the service should
not, by default, be started in any runlevels, a
- should be used in place of the runlevels
list. The second line contains a description
for the service, and may be extended across
multiple lines with backslash continuation.
For example, random.init has these three lines:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
This says that the random script should be
started in levels 2, 3, 4, and 5, that its
start priority should be 20, and that its stop
priority should be 80. You should be able to
figure out what the description says; the \
causes the line to be continued. The extra
space in front of the line is ignored.
译:
RUNLEVEL文件每个服务应该由chkconfig管理,chkconfig需要添加到init.d脚本中的两个或更多注释行。第一行告诉chkconfig默认应该在什么运行级别启动服务,以及启动和停止优先级级别。在任何运行级别中,都应该使用a-来代替runlevel列表。通过反斜杠的延续。例如,Rand.init有以下三行:#chkconfig:2345 20 80#Description:保存和恢复系统熵池以提高质量\#随机数生成。这意味着随机脚本应该在级别2、3、4和5中启动,它的开始优先级应该是20,它的停止优先级应该是80。你应该能够弄清楚描述中写了什么;\导致行被继续。该行前面的额外空间被忽略了。
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
使用范例:
chkconfig --list #列出所有的系统服务
chkconfig --add httpd #增加httpd服务
chkconfig --del httpd #删除httpd服务
chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --list #列出系统所有的服务启动情况
chkconfig --list mysqld #列出mysqld服务设置情况
chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级
如何增加一个服务:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig --add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了; 3.chkconfig --level 35 mysqld on
修改服务的默认启动等级。
[XM1]说明,注释