systemd服务单元

以前版本的 Oracle Linux 使用 /etc/rc.d/init.d 目录中的脚本来控制服务。

在 Oracle Linux 7(Redhat Linux 7) 中,这些脚本已被 systemd 服务单元取代。

使用 systemctl 命令列出有关服务单元的信息。

列出所有加载的服务单元:

# systemctl list-units --type service --all

要查看启用了哪些服务单元:

# systemctl list-unit-files --type service
www. On IT Road .com

启动和停止服务

service 实用程序systemctl 实用程序描述
service name startsystemctl start name启动服务
service name stopsystemctl stop name停止服务
service name restartsystemctl restart name重新启动服务
service name condrestartsystemctl try-restart name仅当服务正在运行时才重新启动服务
service name reloadsystemctl reload name重新加载配置
service name statussystemctl status name检查服务是否正在运行
service -status- allsystemctl list-units -type service -all显示所有服务的状态

显示服务状态

systemd 服务单元对应系统服务。

要显示有关 httpd 服务的详细信息:

# systemctl status httpd

要检查服务是否正在运行(活动)或者未运行(非活动):

# systemctl is-active sshd
active

要检查服务是否已启用:

# systemctl is-enabled sshd
enabled
RHEL 7 启动、停止和检查网络服务的状态

启用和禁用服务

chkconfig 实用程序systemctl 实用程序描述
chkconfig name onsystemctl enable name启用服务
chkconfig name offsystemctl disable name禁用服务
chkconfig -list namesystemctl status name, systemctl is-enabled name检查服务是否已启用
chkconfig -listsystemctl list-unit-files -type service列出所有服务并检查它们是否已启用
日期:2020-09-17 00:14:48 来源:oir作者:oir