打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
CHKCONFIG做成35模式下自动启动

 chkconfig可以管理系统服务的runlevel信息,十分方便,那么对于一个自己添加的脚本,如何用chkconfig管理起来呢?

将脚本注册为系统服务很简单,只要符合script star|stop就可以,当然也可以添加status之类的,这样我们就可以把脚本放在/etc/rc.d/init.d/目录,使用service进行start|stop等,但是这个时候还不能使用chkconfig,会提示service XXX does not support chkconfig,那么chkconfig是如何识别系统服务的呢,原来很简单:

       Each service which should be manageable by chkconfig needs two or more commented lines added to its init.d script. The
       first line tells chkconfig what runlevels the service should be started in by default, as well as the start and stop prior-
       ity levels. If the service should not, by default, be started in any runlevels, a - should be used in place of the run-
       levels list. The second line contains a description for the service, and may be extended across multiple lines with back-
       slash 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.

也就是说,只要在脚本里面添加两个注释就可以了,十分简单,大家不妨尝试一下

 

 

Linux 的服务都是以脚本的方式运行的,这些服务的脚本都放在 /etc/rc.d/init.d目录下。我们可以通过修改此处的各项服务脚本控制其运行细节。
使用chkconfig 工具,可以更加简单地控制服务的运行。
用法:
chkconfig --list [name]
chkconfig --add
chkconfig --del
chkconfig --override
chkconfig [--level ]
例如,要查看所有服务的列表:
# chkconfig --list
只查看一个服务(smb)的运行级别:
# chkconfig --list smb
smb 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
上面的这条可以清晰的显示出在所有运行级别中,smb服务器是关闭的。我们可以用 下面的命令来打开。比如:让smb在3(字符)和5(图形)模式下都开机自动运行:
# chkconfig --level 35 smb on
# chkconfig --list smb
smb 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭

在配置服务访问控制之前,需要先对 Linux 的运行级别 (runlevels)有所了解。在不同的运行级别下,系统所启用的服务也不相同,每个运行级别对应的 /etc/rc.d/rc[x].d目录下包含了此运行级别下的服务。
运行级别

runlevel 0:关机,不要设置为默认运行级
runlevel 1:单用户模式
runlevel 2:多用户模式,不带NFS
runlevel 3:完全的多用户模式,如果没有网络连接的话与2相同
runlevel 4: 未用
runlevel 5:图形用户模式(runlevel 3 + X 窗口系统“图形用户界面”)。
runlevel 6:  重启,不要设成默认运行级


  如果使用命令行界面的登录框,说明系统的运行级别为 3,如果使用图形界面的登录窗口,则说明系统的运行级别为 5。


  通过编辑 /etc/inittab 文档,可以更改系统的默认运行级别 ,只需要将指定的运行级别替换下面这一 行中的数字 5(运行级别 5) 即可:
id:5:initdefault:
  通过编辑 /etc/inittab 完成对默认运行级别的更改之后,新配置会在重新启动系统 时后生效。


查看当前运行级别
/sbin/runlevel

通过下面的命令来切换运行级别 (用数字如 3,5 等来替换 RUNLEVEL):
# /sbin/init RUNLEVEL

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
systemd详解(CentOS 7)
linux /etc/rc.d/目录的详解
Linux中如何将脚本做成系统服务开机自启动
在centos中 将apache httpd 服务加入系统服务
Linux的引导过程,运行级别以及/etc/rc.d/ 与/etc/rc.d/init.d目录分析
linux 基础知识
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服