0、写在前言
说明 | 并没有列出所有的选项,只是列出常用的选项。如果以后有用到没有记录的选项,会对该博客进行更新和维护。 |
联系方式 | QQ:1369929127 Email:zhanglianghhh@163.com |
1、概述
chkconfig更新和查询系统服务的运行级别信息
开机自启动项
2、命令格式
chkconfig[--list] [--type type][name]
chkconfig--add name
chkconfig--del name
chkconfig--override name
chkconfig[--level levels] [--type type] name <on|off|reset|resetpriorities>
chkconfig[--level levels] [--type type] name
3、常用命令选项
当前开机自启动项
[root@oldboy ~]# chkconfig --list | grep '3:on'
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off
--list name 列出对应服务在每个运行级别启动或关闭信息
[root@oldboy ~]# chkconfig --list network
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4、常用示例
1、查询所有开启自启动项,不管是开始还是关闭
[root@oldboy ~]# chkconfig --list
abrt-ccpp 0:off 1:off 2:off 3:off 4:off 5:off 6:off
abrtd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
acpid 0:off 1:off 2:off 3:off 4:off 5:off 6:off
atd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
auditd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
blk-availability 0:off 1:on 2:off 3:off 4:off 5:off 6:off
cpuspeed 0:off 1:on 2:off 3:off 4:off 5:off 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
………………
2、查询指定服务开机启动信息
[root@oldboy ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3、查询所有开启的开机自启动项信息
[root@oldboy ~]# chkconfig --list | grep '3:on' # 优化后的信息
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off #定时任务
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off #网络
rsyslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off #日志
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off #SSH远程连接
sysstat 0:off 1:on 2:on 3:on 4:on 5:on 6:off #性能监控检测
4、如何优化开机自启动项【Linux优化】
0、模拟数据命令信息
生产环境默认的运营级别都为3【命令行模式】
#chkconfig --list | awk '{print $1}'
#chkconfig --list | awk '{print "chkconfig",$1,"on"}' # 使用空格分隔 如: chkconfig ntpd on
#chkconfig --list | awk '{print "chkconfig",$1,"on"}' | bash # 将所有信息将给bash执行
#chkconfig –list ##或者: chkconfig --list | grep '3:on' # 所有的服务都已经开启
1、思路1:关闭所有服务,打开我们需要的服务
命令行命令如下: *:请依次操作
#chkconfig --list
#chkconfig --list | awk '{print $1}'
#chkconfig --list | awk '{print "chkconfig",$1,"off"}'
#chkconfig --list | awk '{print "chkconfig",$1,"off"}' | bash
#chkconfig --list | grep '3:on' # 没有任何信息
#chkconfig --list | grep -E 'crond|rsyslog|network|sshd|sysstat'
#chkconfig --list | grep -E 'crond|rsyslog|network|sshd|sysstat' | awk '{print "chkconfig",$1,"on"}'
#chkconfig --list | grep -E 'crond|rsyslog|network|sshd|sysstat' | awk '{print "chkconfig",$1,"on"}' | bash
#chkconfig --list | grep '3:on'
2、思路2:除了我们需要的服务,其他的服务都关闭 【推荐使用】
#chkconfig --list
#chkconfig --list | grep -Ev 'crond|network|rsyslog|sshd|sysstat'
#chkconfig --list | grep -Ev 'crond|network|rsyslog|sshd|sysstat' | awk '{print "chkconfig",$1,"off"}'
#chkconfig --list | grep -Ev 'crond|network|rsyslog|sshd|sysstat' | awk '{print "chkconfig",$1,"off"}' | bash
#chkconfig --list | grep '3:on'
5、如何操作一个自启动项的开启和关闭
[root@oldboy ~]# chkconfig saslauthd off
[root@oldboy ~]# chkconfig --list saslauthd
saslauthd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@oldboy ~]# chkconfig --level 35 saslauthd on #运行级别3和5
[root@oldboy ~]# chkconfig --list saslauthd
saslauthd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@oldboy ~]# chkconfig saslauthd on # 级别2-5
[root@oldboy ~]# chkconfig --list saslauthd
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5、命令所在位置和类型
[root@oldboy ~]# which chkconfig
/sbin/chkconfig
[root@oldboy ~]# type chkconfig
chkconfig is hashed (/sbin/chkconfig)
6、另请参见