每天2个Linux命令 chkconfig systemctl


2017-08-13 每天2个Linux命令 chkconfig命令

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

(1)用法:

用法:  chkconfig  [必要参数]  [服务]

(2)功能:

功能:  chkconfig命令用来安装,查看或修改 services随系统启动的启动选项的设置。是Red Hat公司遵循GPL规则所开发的程序,
它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。

注意:  谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
每一个被chkconfig管理的服务都首先要在/etc/init.d中添加他们。  

(3)选项参数:

  1) --add         开启指定的服务程序

  2) --del        关闭指定的服务程序

  3) --list          列出chkconfig所知道的所有服务

  4) --level<代号>     设置服务程序的等级代号,是一串0~7的数字

(4)实例:

  1)[root@localhost sunjimeng]# chkconfig --list   查看系统程序列表     

复制代码
[root@localhost sunjimeng]# 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:关

基于 xinetd 的服务:
    chargen-dgram:     关
    chargen-stream:    关
    daytime-dgram:     关
    daytime-stream:    关
    discard-dgram:     关
    discard-stream:    关
    echo-dgram:        关
    echo-stream:       关
    tcpmux-server:     关
    time-dgram:        关
    time-stream:       关

2)在shell脚本中检查service的启动选项的设置

[root@localhost sunjimeng]# chkconfig network && echo "Network service is configured"
Network service is configured
      当你执行chkconfig加service名字,如果service被配置为自动启动,则它将返回true。

[root@localhost sunjimeng]# chkconfig xinetd
注意:正在将请求转发到“systemctl is-enabled xinetd.service”。
enabled
[root@localhost sunjimeng]# chkconfig xinetd
注意:正在将请求转发到“systemctl is-enabled xinetd.service”。
enabled

3)添加或删除指定的服务

[root@localhost /]# chkconfig --del netconsole
[root@localhost /]# chkconfig --add netconsole

(5)其他:

  1)等级代号列表:

  等级0表示:表示关机

  等级1表示:单用户模式

  等级2表示:无网络连接的多用户命令行模式

  等级3表示:有网络连接的多用户命令行模式

  等级4表示:不可用

  等级5表示:带图形界面的多用户模式

  等级6表示:重新启动

      需要说明的是,level选项可以指定要查看的运行级而不一定是当前运行级。对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。 
      2)运行级文件:

  每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用-代替运行级。第二行对服务进行描述,可以用\跨行注释。

2017-08-13 每天2个Linux命令 systemctl命令

systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

(1)用法:

用法:  systemctl  [参数]  [服务]

(2)功能:

功能:  systemd 是 Linux 下的一款系统和服务管理器,兼容 SysV 和 LSB 的启动脚本。

(3)选项参数:

  start,stop,restart,status,enable,disable,is-enabled

(4)实例:

  1)[root@localhost sunjimeng]# systemctl | more -5           显示所有已经激活的服务

复制代码
[root@localhost sunjimeng]# systemctl | more -5
UNIT                                                                                                     LOAD   ACTIVE SUB       
DESCRIPTION
proc-sys-fs-binfmt_misc.automount                                                                        loaded active running   
Arbitrary Executable File Formats File System Automount Point
sys-devices-pci0000:00-0000:00:07.1-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device                      loaded active plugged   
--More--
[5]+  已停止               systemctl | more -5
[root@localhost sunjimeng]# systemctl list-units |more -5
UNIT                                                                                                     LOAD   ACTIVE SUB       
DESCRIPTION
proc-sys-fs-binfmt_misc.automount                                                                        loaded active running   
Arbitrary Executable File Formats File System Automount Point
sys-devices-pci0000:00-0000:00:07.1-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device                      loaded active plugged   
--More--

2)[root@localhost sunjimeng]# systemctl list-unit-files |more -5   显示所有已经安装的服务

复制代码
[root@localhost sunjimeng]# systemctl list-unit-files |more -5
UNIT FILE                                   STATE   
proc-sys-fs-binfmt_misc.automount           static  
dev-hugepages.mount                         static  
dev-mqueue.mount                            static  
proc-fs-nfsd.mount                          static  
--More--

3)[root@localhost sunjimeng]# systemctl is-enabled telnet.socket   查看特定服务是否设定为开机自启 

[root@localhost sunjimeng]# systemctl is-enabled telnet.socket
enabled
[root@localhost sunjimeng]# chkconfig telnet.socket        //这里不需要再加上.socket(加上之后没有反应)
[root@localhost sunjimeng]# chkconfig telnet
注意:正在将请求转发到“systemctl is-enabled telnet.socket”。
enabled

(5)其他:

systemd 的特性有:

复制代码
支持并行化任务;
同时采用 socket 式与 D-Bus 总线式激活服务;
按需启动守护进程(daemon);
利用 Linux 的 cgroups 监视进程;
支持快照和系统恢复;
维护挂载点和自动挂载点;
各服务间基于依赖关系进行精密控制。

文章作者: 邓滔
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 邓滔 !
评论
  目录