chkconfig工具

来源:互联网 发布:天赋宝宝探险软件 编辑:程序博客网 时间:2024/06/04 00:46

chkconfig工具介绍

chkconfig工具用于检查、设置系统的各种服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接(该命令多用于centos6及以前版本)。

命令语法

chkconfig [options]

命令选项

–list:查看在使用chkconfig命令的服务的状态
–add:增加指定服务
–del:删除指定服务
–level:指定某系统服务要在系统某运行级别中开启或关毕。


  • 查看当前系统服务状态
[root@localhost ~]# chkconfig --list    注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。netconsole      0:1:2:3:4:5:6:关network         0:1:2:3:4:5:6:

说明:
从上述描述可知,centos6以及之前的版本使用的Linux系统管理机制是SysV服务,而7版本用到管理机制是systemd服务。


  • 服务所在位置
[root@localhost ~]# ls /etc/init.dfunctions  netconsole  network  README

  • 运行级别配置文件
[root@localhost init.d]# cat /etc/inittab    //centos7已经不再使用

  • 更改服务的所有级别状态
[root@localhost init.d]# chkconfig network off    //关闭network的所有级别状态[root@localhost init.d]# chkconfig --list    //查看服务注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。netconsole      0:1:2:3:4:5:6:关network         0:1:2:3:4:5:6:

  • 更改服务的单个及多个级别状态
[root@localhost init.d]# chkconfig --level 345 network off    //使用--level 更改运行级别 off为关闭状态 on为开启状态[root@localhost init.d]# chkconfig --list    //查看服务状态注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关network         0:关 1:关 2:开 3:关 4:关 5:关 6:关    //可以看出345级别已经关闭了

  • 自定义一个shell脚本,并加入服务列表
-rw-r--r--. 1 root root 15131 912 2016 functions-rwxr-xr-x. 1 root root  2989 912 2016 netconsole-rwxr-xr-x. 1 root root  6643 912 2016 network-rw-r--r--. 1 root root  1160 117 2016 README[root@localhost init.d]# cp network 123[root@localhost init.d]# ls -l总用量 40-rwxr-xr-x. 1 root root  6643 125 14:29 123-rw-r--r--. 1 root root 15131 912 2016 functions-rwxr-xr-x. 1 root root  2989 912 2016 netconsole-rwxr-xr-x. 1 root root  6643 912 2016 network-rw-r--r--. 1 root root  1160 117 2016 README[root@localhost init.d]# chkconfig --list注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关network         0:关 1:关 2:关 3:关 4:关 5:关 6:关[root@localhost init.d]# chkconfig --add 123[root@localhost init.d]# chkconfig --list注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。123             0:关 1:关 2:开 3:开 4:开 5:开 6:关netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关network         0:关 1:关 2:关 3:关 4:关 5:关 6:关步骤:首先要有一个shell脚本,然后加入到/etc/init.d目录下,最后使用chkconfig --add 添加到服务列表

注意:脚本格式要求
符合要求才能被识别。

这里写图片描述


  • 删除一个服务
[root@localhost init.d]# chkconfig --del 123[root@localhost init.d]# chkconfig --list注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。      欲查看对特定 target 启用的服务请执行      'systemctl list-dependencies [target]'。netconsole      0:1:2:3:4:5:6:关network         0:1:2:3:4:5:6:
原创粉丝点击