`
cocos
  • 浏览: 393679 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

使用chkconfig管理服务的runlevel

阅读更多

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

分享到:
评论

相关推荐

    Ubuntu上支持chkconfig命令

    现在ubuntu上,默认是不支持chkconfig命令的,但支持自己安装,需要自己去下载对应的安装包。 方法:在存放该文件的目录下执行:dpkg -i chkconfig_11.0-79.1-1ubuntu1_all.deb

    ubuntu14.04中安装chkconfig服务管理程序的方法

    主要介绍了ubuntu14.04中安装chkconfig服务管理程序的方法,在文章给大家提到了ubuntu使用chkconfig命令来管理服务的命令写法,需要的朋友可以参考下

    Linux 添加系统服务、设置开机启动、设置启动顺序、chkconfig.docx

    文档是我自己亲自整理的文档,详细介绍了 chkconfig 命令,使用该命令再进行配置Linux的服务和启动服务

    使用 chkconfig 和 systemctl 命令启用或禁用 Linux 服务的方法

    在 Linux 中,无论何时当你安装任何带有服务和守护进程的包,系统默认会把这些服务的初始化及 systemd 脚本添加进去...下面小编给大家带来了使用 chkconfig 和 systemctl 命令启用或禁用 Linux 服务的方法,一起看看吧

    操作系统安全:chkconfig.docx

    chkconfig Chkconfig chkconfig: chkconfig命令主要用来更新(启动或停止)和查询系统服务的... --add 增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。 ?? --del 删

    Linux chkconfig 命令的使用

    1.命令简介 chkconfig 命令用于更新和查询系统服务的运行等级信息。它可查询操作系统在每一个运行等级中会自动执行哪些系统服务,包括各类常驻服务,比如 ...(2)从 chkconfig 管理服务列表中删除服务; (3)列出

    Linux应用技术:服务与进程管理.docx

    学会Linux服务管理 实验内容 注意!实验前,请将主机名修改为zhangsan(zhangsan为自己姓名全拼) 修改方式如下: 关闭终端,重新打开后主机名即可临时生效,如下图所示: 实验报告中所有截图,必须包含主机名信息。...

    chkconfig命令详解

    chkconfig命令详解

    适用于ubuntu系统的chkconfig 安装文件

    ubuntu默认没有安装chkconfig。需要我们自己安装。在浏览器下载后通过WinSCP(这里有很多种方法,全靠个人喜好)传到服务器目录,执行dpkg -i chkconfig_11.0-79.1-2_all.deb 即可安装成功

    Linux下chkconfig命令详解.docx

    Linux下chkconfig命令详解.docx

    ubuntu安装chkconfig

    ubuntu安装chkconfig 1.Update the package index: # sudo apt-get update 2.Install chkconfig deb package: # sudo apt-get install chkconfig

    linux命令详解之chkconfig命令使用方法

    使用语法:chkconfig[–add][–del][–list][系统服务] 或chkconfig[–level < 等级代号>][系统服务][on/off/reset] chkconfig在没有参数运行时,显示用法。如果加上服务名,那么就检查这个服务是否在当前运行级...

    chkconfig_11.0-79.1-2_all.deb

    在ubuntu上默认是不支持chkconfig命令的,但可以自己安装,安装包已经上传,方法:在存放目录执行:dpkg -i chkconfig_11.0-79.1-2_all.deb

    linux中chkconfig 启动程序顺序.docx

    linux中chkconfig 启动程序顺序.docx

    chkconfig命令 检查与设置系统的各种服务

    增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据 –del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据 –level ...

    Linux chkconfig命令用法详解

    Linux chkconfig命令 Linux chkconfig命令用于检查,设置系统的各种服务。 这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个...–del 删除所指定的系统服务,不再由chkconfig指令管理,并同时在系

    Linux下的chkconfig命令详解

    Linux下的chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。 使用语法 chkconfig [–add][–del][–list][系统...

    chkconfig.deb

    ubuntu12.04以上的系统均可安装(ubuntu14.04, ubuntu16.04, Ubuntu18.04等), Ubuntu专用! 其他的系统不可用!

    chkconfig-1.19.1-1.el8.aarch64.rpm

    离线安装包,亲测可用

Global site tag (gtag.js) - Google Analytics