CentOS 7与RHEL 7的systemd指令

CentOS 7 已经切换到 systemd,系统指令也有所变化。之前用于启动、重启、停止各种服务的 service 作为向后兼容的指令还能使用,但是将来可能会消失。同时,chkconfig 也改成了 systemctl 。这里列举了一些常用的对应于 service 和 chkconfig 的新的 systemctl 指令。

服务

在目前的 CentOS 7(或 RHEL 7)系统中,依然可以使用 service 指令。例如,

[root@localhost ~]# service network restart
Restarting network (via systemctl):                        [  OK  ]

[root@localhost ~]# service httpd restart
Redirecting to /bin/systemctl restart  httpd.service

[root@localhost ~]# service sshd restart
Redirecting to /bin/systemctl restart  sshd.service

但是系统会自动重定向该指令到新的指令 /bin/systemctl 来执行,并给出提示。

是时候切换到新的指令格式了,直接使用 systemctl 吧。这个指令的意思就是 system contrl。下面是一些常用的例子:

  • 启动服务:
systemctl start httpd
  • 停止服务:
systemctl stop httpd
  • 重启服务(先停止,后启动):
systemctl restart httpd
  • 重新加载(使用新的配置文件):
systemctl reload httpd
  • 显示服务状态:
systemctl status httpd

自启动

与此同时,之前用于设定系统启动时自动运行某服务的指令 chkconfig 也改成 systemctl。

  • 自启动服务 chkconfig service on 改成
systemctl enable httpd
  • 关闭自启动 chkconfig service off 改成
systemctl disable httpd
  • 检查服务状态的 chkconfig service 改成
systemctl is-enabled httpd
  • 列举出所有服务的指令 chkconfig –list 改成
systemctl list-unit-files --type=service
上一篇 Linux scp命令
下一篇 Windows端5款MySQL客户端工具
目录
文章列表
1 【面试必备】快速理解数据库事务隔离级别
【面试必备】快速理解数据库事务隔离级别
2
Python字符串操作
Python字符串操作
3
使用数据库中间件MyCat+SpringBoot完成分库分表
使用数据库中间件MyCat+SpringBoot完成分库分表
4
美团Robust热修复接入实践
美团Robust热修复接入实践
5
利用XStream在Java对象和XML之间相互转换
利用XStream在Java对象和XML之间相互转换
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。