启用和禁用服务
在早期版本的 RHEL 中,chkconfig 实用程序用于启用和禁用服务。
在 RHEL 7 中,systemctl 实用程序提供了一组等效的子命令。
下表显示了 chkconfig 实用程序与 systemctl 的比较。
chkconfig 实用程序 | systemctl 实用程序 | 描述 |
---|---|---|
chkconfig name on | systemctl enable name | 启用服务 |
chkconfig name off | systemctl disable name | 禁用服务 |
chkconfig -list name | systemctl status name, systemctl is-enabled name | 检查服务是否已启用 |
chkconfig -list | systemctl list-unit-files -type service | 列出所有服务并检查它们是否已启用 |
以前版本的 Oracle Linux 使用位于 /etc/rc.d/init 目录中的 init 脚本来启动和停止服务。
在 RHEL 7 中,这些 init 脚本已替换为 systemd 服务单元。
服务单位有一个 .service 扩展名。
使用 systemctl 命令列出所有加载的服务单元:
# systemctl list-units --type service --all UNIT LOAD ACTIVE SUB DESCRIPTION auditd.service loaded active running Security Auditing Service avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack .....
其中:
LOAD 服务负载状态
高级 (ACTIVE) 和低级 (SUB) 单元激活状态
DESCRIPTION 服务单元的描述。
省略 -all 选项以仅列出活动服务单元。
使用 list-unit-files 选项查看启用了哪些服务单元:
# systemctl list-unit-files --type service
欢迎来到之路教程(on itroad-com)
启动和停止服务
在以前的 RHEL 版本中,服务实用程序用于停止和启动服务。
在 RHEL 7 中,systemctl 实用程序提供了一组等效的子命令。
下表显示了 service 实用程序与 systemctl 的比较。
service 实用程序 | systemctl 实用程序 | 描述 |
---|---|---|
service name start | systemctl start name | 启动服务 |
service name stop | systemctl stop name | 停止服务 |
service name restart | systemctl restart name | 重新启动服务 |
service name condrestart | systemctl try- restart name | 仅当服务正在运行时才重新启动服务 |
service name reload | systemctl reload name | 重新加载配置 |
service name status | systemctl status name | 检查服务是否正在运行 |
service -status- all | systemctl list-units -type service -all | 显示所有服务的状态 |
显示服务状态
systemd 服务单元对应系统服务。
使用以下命令显示有关服务单元的详细信息。
此示例显示有关 sshd 服务单元的信息。
# systemctl status sshd
以下信息可用于指定的服务单位:
Loaded:如果已加载服务,则为服务单元文件的绝对路径,如果 服务单元已启用 Active:如果服务单元正在运行并且有时间戳 主PID:对应系统服务的进程ID和服务名称 Status:有关相应系统服务的其他信息 Process:有关相关进程的其他信息 CGroup:有关相关控制组的其他信息
要检查服务是否正在运行(活动)或者未运行(非活动):
# systemctl is-active sshd active
要检查服务是否已启用:
# systemctl is-enabled sshd enabled
日期:2020-09-17 00:12:47 来源:oir作者:oir