Linux chkconfig命令详解
chkconfig命令检查、设置系统的各种服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
chkconfig常见命令参数
用法: 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原理通俗理解
chkconfig 处理的命令类似于我们平时执行的 /etc/init.d/sshd restart这样的命令
每一个运行级别(0-6)对应一个 /etc/rc.d/rc3.d/ 这样的 目录
[root@localhost ~]# chkconfig |grep sshd # 运行级别是2345的时候开启sshd服务

[root@localhost rc3.d]# ll /etc/rc.d/rc3.d/S55sshd #s表示start,s55表示开机启动的时候是第55个开启的服务

[root@localhost rc3.d]# grep 'chkconfig' /etc/init.d/sshd
# chkconfig: 2345 55 25 # 注释脚本里有默认的开启关闭的参数,这里开始是55
注:利用yum,rqm安装的服务,启动命令都会自动放在init.d下面,并且接受chkconfig管理

自定义启动服务
自己写chkconfig管理的脚本,放在/etc/init.d目录下
vim /etc/init.d/FTL
# chkconfig: 345 77 69
# description: FTL is a protocol for secure remote shell access. \
# This serddvice starts up the OpenSSH server daemon.
. /etc/init.d/functions
case "$1" in
start)
action "FTL Linux is $1ing"/bin/true
;;
esac
chmod +x /etc/init.d/FTL # 增加执行权限
chkconfig --add FTL # 添加到启动服务
chkconfig --list FTL # 查看启动服务,显示默认的345级别开, 默认修改/etc/rc3.d/ /etc/rc5.d/

ll /etc/rc3.d/ | grep FTL # 默认第77个开启服务

/etc/init.d/FTL start # 因为文件写了一个可以开启的函数

chkconfig管理脚本的要求:
1.执行 /etc/init.d/FTL start 格式执行正常服务
2.脚本开头增加如下内容;
# chkconfig: 345 77 69 【345是启动级别,77是第77个启动程序,69是第69个关闭程序】
# description: FTL is Coming
3.chkconfig 是针对程序是否需要机器后开启
# /etc/init.d/FTL start 让程序当前运行
4.可以参考/etc/rc.d/rc3.d/下的文件去写
常用的命令展示
界面设置自启动服务
ntsysv

显示某个服务,例如sshd
[root@localhost ~]# chkconfig --list sshd

显示当前系统开启的服务
[root@localhost ~]# chkconfig | egrep 3:on

关闭某个服务
[root@localhost ~]# chkconfig --list|grep FTL
[root@localhost ~]# chkconfig FTL off
[root@localhost ~]# chkconfig --list|grep FTL

开启/关闭服务的3级别
[root@localhost ~]# chkconfig --list|grep FTL
[root@localhost ~]# chkconfig --level 3 FTL on 【开启3级别】
[root@localhost ~]# chkconfig --level 3 FTL off 【关闭3级别】

关闭我们不常用的服务【Linux服务最小原则】
chkconfig |grep 3:on | awk '{print $1}' | grep -Ev "sshd|network|crond|sysstat|rsyslog" | xargs -I{} chkconfig {} off
==>for name in `chkconfig | grep 3:on |awk '{print $1}'` ; do chkconfig $name off; done;
==命令用反引号 tab键上
==>chkconfig | awk '{print $1}' | grep -Ev "sshd|network|crond|sysstat|rsyslog" | sed -r 's#(.*)#chkconfig /1 off#g' | bash
|bash 之前输出的只是字符串
|bash 之后是将内容交给bash处理
==>chkconfig | awk '{print $1}' | grep -Ev "sshd|network|crond|sysstat|rsyslog" | awk '{print "chkconfig " $1 " off" }' | bash
Linux chkconfig命令详解的更多相关文章
- Linux chkconfig 命令详解
一.简介 chkconfig 命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 二.安装&启动 us ...
- Linux/CentOS 服务安装/卸载,开机启动chkconfig命令详解|如何让MySQL、Apache开机启动?
chkconfig chkconfig在命令行操作时会经常用到.它可以方便地设置和查询不同运行级上的系统服务.这个可要好好掌握,用熟练之后,就可以轻轻松松的管理好你的启动服务了. 注:谨记chkcon ...
- Linux下chkconfig命令详解(转)
Linux下chkconfig命令详解 chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. ...
- Linux知识积累(4) Linux下chkconfig命令详解
Linux下chkconfig命令详解 chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. ...
- 转载的 Linux下chkconfig命令详解
Linux下chkconfig命令详解 chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. ...
- linux awk命令详解
linux awk命令详解 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分 ...
- linux cat 命令详解
linux cat 命令详解 http://linux.chinaunix.net/techdoc/system/2007/11/16/972467.shtml adb shell su //这个不一 ...
- 【初级】linux rm 命令详解及使用方法实战
rm:删除命令 前言: windows中的删除命令大家都不陌生,linux中的删除命令和windows中有一个共同特点,那就是危险,前两篇linux mkdir 命令详解及使用方法实战[初级]中我们就 ...
- Linux netstat命令详解
Linux netstat命令详解 一 简介 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多 ...
随机推荐
- docker 创建tomcat镜像
Dockerfile ############################################ # version : wenbronk/jdkiu121/tomcat8 # desc ...
- BEA-141150 - An error occurred while preparing application component uri of application application with HTTP response responseCode: message
网上查询的 Cause:This is either because the resource it self is not available on the administration serve ...
- APP消息推送机制的实现(PUSH)
出于好奇,想了解一下消息推送机制,在网上搜索到了几篇文章,感觉还不错,粘贴下来,等真正用到的时候再仔细研究 以下两篇是关于ios的 1.http://blog.csdn.net/xyxjn/artic ...
- docker改国内官方镜像
如何使用官方镜像 Docker 中国官方镜像加速可通过 registry.docker-cn.com 访问.目前该镜像库只包含流行的公有镜像,而私有镜像仍需要从美国镜像库中拉取. 您可以使用以下命令直 ...
- 使用 ahk 让普通键盘变为Dvorak键盘
本文告诉大家,如何使用软件做出Dvorak键盘. 在开始说如何做之前,需要告诉大家,什么是Dvorak键盘. Dvorak Simplified Keyboard /ˈdvɔːræk, dəˈvɔː- ...
- [javaSE] 位运算符(&|^)
位运算是直接对二进制进行计算 左移 << 右移 >> 先把整数换成四个8bit 0000-0000 0000-0000 0000-0000 0000-0000 这个二进制左右移 ...
- mysql information_schema介绍
mysql information_schema介绍 一.information_schema是什么 information_schema是MySQL自带的一个信息数据库,其保存着关于MySQL服务器 ...
- RabbitMQ--学习资源汇
1.RabbitMQ 实战教程 文集(alibaba) 2.RabbitMQ从入门到精通(9篇系列博文 )(anzhsoft2008 ) 3. RabbitMQ目录(nick's blog) 使用 ...
- Linux学习8-Linux常用命令(4)
链接命令 命令名称:ln 命令英文原意:link 命令所在路径:/bin/ln 执行权限:所有用户 功能描述:生成链接文件 语法:ln 选项[-s][原文件] [目标文件] 选项: -s 创建 ...
- UVAlive6800The Mountain of Gold?(负环)
题意 题目链接 问从\(0\)出发能否回到\(0\)且边权为负 Sol 先用某B姓算法找到负环,再判一下负环上的点能否到\(0\) #include<bits/stdc++.h> #def ...