systemctl 命令

2019-06-04 02:44 systemctl 命令已关闭评论

从Centos 7开始,系统管理命令默认使用systemctl命令。

1.旧版本service命令与systemctl命令对比

service命令 systemctl命令 说明
service [服务] start systemctl start [unit type] 启动服务
service [服务] stop systemctl stop [unit type] 停止服务
service [服务] restart systemctl restart [unit type] 重启服务

:systemctl命令特殊参数

  • status:参数用来查看服务运行情况
  • reload:重新加载更新后的配置文件(并不是所有服务都支持这个参数,如network.service)

示例:

#启动网络服务 systemctl start network.service

#停止网络服务 systemctl stop network.service

#重启网络服务 systemctl restart network.service

#查看网络服务状态 systemctl status network.serivce

 

2.旧版chkconfig命令与systemctl命令对比

chkconfig命令 systemctl命令 说明
chkconfig [服务] on systemctl enable [unit type] 设置开机启动
chkconfig [服务] off systemctl disable [unit type] 禁止开机启动

示例:

#停止firewalld服务 systemctl stop firewalld.service

#禁止firewalld服务开机启动 systemctl disable firewalld.service

#查看firewalld服务状态 systemctl status firewalldservice

#重新设置firewalld服务开机启动 systemctl enable firewalld.service

 

3.systemctl命令的特殊参数

systemctl命令 说明
systemctl is-active [unit type] 查看服务是否在运行
systemctl is-enable [unit type] 查看服务是否设置开机启动
systemctl mask [unit type] 注销指定的服务
systemctl unmask [unit type] 取消注销指定的服务

示例:

#查看网络服务是否启动 systemctl is-active network.service

#检查网络服务是否设置为开机启动 systemctl is-enable network.service

#停止firewalld服务 systemctl stop firewalld.service

#注销firewalld服务 systemctl mask firewalld.service

#查看firewalld服务状态 systemctl status firewalld.service

#取消注销firewalld服务 systemctl unmask firewalld.service

 

4.系统运行级别

init级别 systemctl target
0 shutdown.target
1 emergency.target
2 rescure.target
3

multi-user.target

4
5 graphical.target
6

5.设置运行级别

命令格式:systemctl [command] [unit.target]

参数详解:

command:
  • get-default :取得当前的target
  • set-default :设置指定的target为默认的运行级别
  • isolate :切换到指定的运行级别
  • unit.target :为上表中列出的运行级别

示例:

systemctl命令

说明
systemctl get-default 获得当前的运行级别
systemctl set-default multi-user.target 设置默认的运行级别为mulit-user
systemctl isolate multi-user.target 在不重启的情况下,切换到运行级别mulit-user下
systemctl isolate graphical.target 在不重启的情况下,切换到图形界面下

image

版权声明:本文著作权归原作者所有,欢迎分享,谢谢支持!
转载请保留注明:systemctl 命令 | DPIP知识库
分类:Commands 标签:

评论已关闭!