1. 系统服务管理介绍
CentOS7启用了新的系统和服务管理器,采用systemctl命令代替了老版本的service和chkconfig。
为了保持兼容性,在CentOS7中,老版本的service和chkconfig命令仍然可以使用。
systemctl命令是system(系统)和control(控制)两个单词的简写,它是一个功能强大的命令,
本文只介绍与服务管理相关的用法。
在使用systemctl命令时会有一点不足,就是很多命令执行后没有提示信息,会有些不习惯。
2. 系统服务管理命令
2.1 服务启动方法:
命令语法格式:
systemctl start name.service
说明:命令信息中的name.service的.service可以省略不写,只写启动服务的名称即可。
具体用法举例:
systemctl start network
或者
systemctl start network.service
2.2 服务停止方法:
命令语法格式:
systemctl stop name.service
2.3 服务重启方法:
命令语法格式:
systemctl restart name.service
2.4 服务检查方法:
命令语法格式:
# 简单确认服务运行状态:
systemctl is-active name.service
# 详细查看服务运行状态:
systemctl status name.service
在执行详细查看服务运行状态命令后,会显示比较全的信息,但主要关注以下信息即可:
序号 | 信息 | 说明 |
01 | Loaded | 关于服务启动需要加载的文件信息。 |
02 | Active | 服务处于正在运行状态,然后是启动时间信息。 |
03 | Process | 进程额外信息。 |
04 | Main PID | 服务启动运行后产生的主进程pid信息。 |
05 | CGroup | Control Groups额外信息。 |
2.5 实现服务开机自动:
命令语法格式:
# 设置方法
systemctl enable name.service
# 查看方法
systemctl is-enabled name.service
2.5 禁用服务开机自启:
命令语法格式:
# 设置方法
systemctl disable name.service
# 查看方法
systemctl is-enabled name.service
2.6 查看启动失败服务:
命令语法格式:
systemctl --failed
2.7 查看服务依赖关系:
命令语法格式:
# 列出在指定服务之前启动的服务
systemctl list-dependencies --after name.service
# 列出在指定服务之后启动的服务
systemctl list-dependencies --before name.service
说明:在进行信息查看时按空格键显示下一页,按q键退出。