Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

10.5. 控制远程机器上的 systemd

除了在本地控制 systemd 系统和服务管理器外,system ctl 还允许您通过 SSH 协议与远程机器上运行的 systemd 交互。如果远程机器上的 sshd 服务正在运行,您可以使用 --host-H 命令行选项运行 systemctl 命令来连接此机器:

systemctl --host user_name@host_name command

使用远程用户名称替换 user _namehost_name 替换为计算机的主机名,而 command 替换为上述任何 systemctl 命令。请注意,远程计算机必须配置为允许选定的用户通过 SSH 协议进行远程访问。有关如何配置 SSH 服务器的详情请参考 第 12 章 OpenSSH

例 10.16. 远程管理

以 root 用户身份登录名为 server-01.example.com 的远程机器 并确定 httpd.service 单元的当前状态,在 shell 提示符后输入以下内容:

~]$ systemctl -H root@server-01.example.com status httpd.service
>>>>>>> systemd unit files -- update
root@server-01.example.com's password:
httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
  Active: active (running) since Fri 2013-11-01 13:58:56 CET; 2h 48min ago
 Main PID: 649
  Status: "Total requests: 0; Current requests/sec: 0; Current traffic:  0 B/sec"
  CGroup: /system.slice/httpd.service