chkconfig和systemctl

一、chkconfig

chkconfig可以更新(启动或停止)和查询系统服务(service)运行级信息。更简单一点,chkconfig是一个用于维护/etc/rc[0-6].d目录的命令行工具。

chkconfig 提供5个功能:

1. 设置service启动信息

# chkconfig name on/off/reset

 

on、off、reset用于改变service的启动信息。
on表示开启,off表示关闭,reset表示重置。
默认情况下,on和off开关只对运行级2,3,4,5有效,reset可以对所有运行级有效。
例如,

# chkconfig httpd on

 

2. 设置service运行级别

# chkconfig --level levels

 

例如,

# chkconfig --level 2345 httpd on

 

指定运行级为2,3,4,5
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动

3. 添加service

# chkconfig --add name

 

添加一个chkconfig管理的service,并在/etc/rc[0-6].d 目录下添加相应的符号链接(symbolic links)。

4. 移除service

# chkconfig --del name

 

从chkconfig 管理名单中删除该service,并且删除 /etc/rc[0-6].d 目录下所有与之关联的符号链接(symbolic links)。

5. 列出service的启动信息

# chkconfig --list [name]

 

如果不指定name,会列出所有services的信息。

每个service每个运行级别都会有一个启动和停止脚本;当切换运行级别时,init不会重启已经启动的service,也不会重新停止已经停止的service。

下面举例说明

(1).列出所有服务的启动情况

$ chkconfig --list
auditd          0:off   1:off   2:on    3:on    4:on    5:on    6:off
redis           0:off   1:off   2:off   3:off   4:off   5:off   6:off
restorecond     0:off   1:off   2:off   3:off   4:off   5:off   6:off
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
rpcgssd         0:off   1:off   2:off   3:on    4:on    5:on    6:off
rpcsvcgssd      0:off   1:off   2:off   3:off   4:off   5:off   6:off
rsyslog         0:off   1:off   2:on    3:on    4:on    5:on    6:off
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
smb             0:off   1:off   2:off   3:on    4:off   5:on    6:off
。。。
xinetd based services:
    rsync:          off
    swat:           off

 

(2)增加mysqld服务

$ chkconfig --add mysqld

 

(3)删除mysqld服务

$ chkconfig --del mysqld

 

(4)设置mysqld运行级别为2,3,4,5

$ chkconfig --level 2345 httpd on

 

(5)列出mysqld 服务启动信息情况

$ chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

(6)设置启动信息

$ chkconfig mysqld on

默认的运行级别为2,3,4,5
实际上,与4中命令作用是一样的。

二、systemctl(代替chkconfig和service)

在Centos 中 systemctl  是设置系统服务的命令,即 service  ,   它融合之前service和chkconfig的功能于一体。

可以使用它永久性或只在当前会话中启用/禁用服务。

小贴士: 
- 在 systemctl 參数中加入 -H <username>@<主机名> 能够实现对其它机器的远程控制。

该过程使用 SSH连接。 
- systemadm 是 systemd 的官方图形前端。官方软件仓库 提供了稳定版本号 systemd-ui。

systemctl常见用法

启动、停止、重启、重载服务
systemctl start name.service
systemctl stop name.service
systemctl restart name.service
systemctl reload name.service
(2)systemctl | grep agent
systemctl | grep server
systemctl | grep proxy

 

三、chkconfig和systemctl区别对比

任务旧指令新指令
使某服务自动启动chkconfig --level 3 httpd onsystemctl enable httpd.service
使某服务不自动启动chkconfig --level 3 httpd offsystemctl disable httpd.service
检查服务状态service httpd status

systemctl status httpd.service (服务详细信息)

systemctl is-active httpd.service (仅显示是否 Active)

加入自定义服务chkconfig --add  testsystemctl   load test.service
删除服务chkconfig --del  xxx停掉应用,删除相应的配置文件
显示所有已启动的服务chkconfig --listsystemctl list-units --type=service
启动某服务service httpd startsystemctl start httpd.service
停止某服务service httpd stopsystemctl stop httpd.service
重启某服务service httpd restartsystemctl restart httpd.service
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值