systemctl命令的使用
使用systemctl命令可以控制服务,service命令和chkconfig命令依然可以使用,但是主要是出于兼容的原因,应该尽量避免使用。
使用systemctl命令的时候,服务名字的扩展名可以写全,例如:
systemctl stop name.service
也可以忽略:
systemctl stop name
systemctl常用命令
启动服务
systemctl start name.service
关闭服务
systemctl stop name.service
重启服务
systemctl restar tname.service
仅当服务运行的时候,重启服务
systemctl try-restart name.service
重新加载服务配置文件
systemctl relaod name.service
检查服务运作状态
systemctl status name.service
或者
systemctl is-active name.service
展示所有服务状态详细信息
systemctl list-units --type service --all
允许服务开机启动
systemctl enable name.service
禁止服务开机启动
systemctl disable name.service
检查服务开机启动状态
systemctl status name.service
或者
systemctl is-enabled name.service
列出所有服务并且检查是否开机启动
systemctl list-unit-files --type service
使用如下命令列出服务:
默认只列出处于激活状态的服务,如果希望看到所有的服务,使用–all或-a参数:
systemctl list-units --type service
systemctl list-units --type service --all
有时候希望看到所以可以设置开机启动的服务,使用如下命令:
systemctl list-unit-files --type service
查看服务详细信息,使用如下命令:
systemctl status name.service