systemctl和service、chkconfig常用命令对比

前言

  • systemctl 是RHEL 7的系统服务管理器指令,它融合之前 service 和 chkconfig 的功能于一体,是 service 命令和 chkconfig 命令的集合和代替。可以使用它永久性或只在当前会话中启用/禁用服务
  • CentOS是基于 RHEL (RedHat Enterprise Linux) 的Linux发行版本之一,CentOS 7也是使用systemctl,取代了service 和 chkconfig,在CentOS 7中使用后两个命令时会被重定向到使用等价的 systemctl 命令
  • 以 sshd.service 服务为例

systemctl 常用命令

列出所有服务:systemctl list-unit-files --type=service
列出服务层级和依赖关系:systemctl list-dependencies sshd.service

显示服务状态:systemctl status sshd.service
启动服务:systemctl start sshd.service
关闭服务:systemctl stop sshd.service
重启服务:systemctl restart sshd.service

设置服务开机自启动:systemctl enable sshd.service
禁止服务开机自启动:systemctl disable sshd.service

查看服务是否自启动:systemctl is-enabled sshd.service
列出系统所有服务的启动情况:systemctl list-units --type=service
列出所有自启动服务:systemctl list-unit-files|grep enabled

service、chkconfig 常用命令

显示服务状态:service sshd status
启动服务:service sshd start
关闭服务:service sshd stop
重启服务:service sshd restart

设置服务自启动:chkconfig --level 3 sshd on
禁止服务自启动:chkconfig --level 3 sshd off

查看服务是否自启动:chkconfig --list sshd
列出系统所有服务的启动情况:chkconfig --list

参考资料:

Linux - 利用systemctl命令管理服务
Linux下systemctl命令和service、chkconfig命令的区别


End~

发布了15 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/TomAndersen/article/details/104237056