linux 服务开机自启动
(2013-03-08 17:37:06)一、启动级别
1、查看linux 系统默认启动级别
cat /etc/inittab
id:3:initdefault: ##可以看出默认为三
2、查看某一服务在各个启动级别上是否启动
[root@localhost ~]# chkconfig --list
nfs
3、在Linux中有7种启动级别
分别为:
#
#
#
#
#
#
#
各个运行级的详细解释:
0 为停机,机器关闭。
1 为单用户模式,就像Win9x下的安全模式类似。
2 为多用户模式,但是没有NFS支持。
3 为完整的多用户模式,是标准的运行级。
4 一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本电脑的电池用尽时,可以切换到这个模式来做一些设置。
5 就是X11,进到X Window系统了。
6 为重启,运行init 6机器就会重启。
0和6一般不用;
二、 chkconfig
说明 :linux 的所有服务都在 /etc/init.d/
1、chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
2、 chkconfig --list :显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。
3、举例sendmail:
1)cat /etc/inittab
id:3:initdefault:
2)chkconfig --list
sendmail
查看连接 :
ll /etc/rc0.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov
ll /etc/rc1.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov
ll
lrwxrwxrwx 1 root root 18 Nov
ll /etc/rc3.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov
ll /etc/rc4.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov
ll /etc/rc5.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov
lrwxrwxrwx 1 root root 18 Nov
3)chkconfig --del
service sendmail supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add sendmail')
查看连接
[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail
[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail
[root@localhost init.d]#
4)
[root@localhost init.d]# chkconfig --add
[root@localhost init.d]# chkconfig --list
sendmail
查看连接:
[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
5)chkconfig
[root@localhost init.d]# chkconfig --list
sendmail
查看连接:
[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:36 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
6)chkconfig
[root@localhost init.d]# chkconfig --list
sendmail
查看连接:
[root@localhost init.d]# ll /etc/rc0.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc1.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc2.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc3.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc4.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc5.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:40 S80sendmail -> ../init.d/sendmail
[root@localhost init.d]# ll /etc/rc6.d/ |grep sendmail
lrwxrwxrwx 1 root root 18 Nov 10 23:33 K30sendmail -> ../init.d/sendmail
7)
chkconfig
[root@localhost init.d]# chkconfig --list
sendmail
[root@localhost init.d]# chkconfig --level 3
[root@localhost init.d]# chkconfig --list
sendmail
[root@localhost init.d]# chkconfig --level 0
[root@localhost init.d]# chkconfig --list
sendmail
[root@localhost init.d]# chkconfig
[root@localhost init.d]# chkconfig --list
sendmail
[root@localhost init.d]# chkconfig --level 0
[root@localhost init.d]# chkconfig --list
sendmail
8)
[root@localhost init.d]# chkconfig
[root@localhost init.d]# chkconfig --list
sendmail
[root@localhost init.d]# chkconfig
[root@localhost init.d]# chkconfig --list
sendmail