使用systemctl status name[.type]来查询服务状态。如果未提供单元类型(type),则默认为service服务单元。(如果该服务单元存在的话~)
systemctl status sshd.service #查看ssh服务器守护进程的状态 ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-01-31 10:38:57 CST; 3h 15min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1572 (sshd) Tasks: 1 (limit: 49169) Memory: 7.7M CGroup: /system.slice/sshd.service └─1572 /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes256-cbc,aes128-gcm@openssh.com,aes128-ctr,aes128-cbc -oMACs=hmac-sh> Jan 31 11:32:15 centos8 sshd[4221]: Accepted password for yourname from 192.168.1.157 port 44876 ssh2 Jan 31 11:32:15 centos8 sshd[4221]: pam_unix(sshd:session): session opened for user yourname by (uid=0) Jan 31 11:32:27 centos8 sshd[4307]: Accepted password for yourname from 192.168.1.157 port 44900 ssh2
在上面的状态中找到几个关键词:
关键词
描述
loaded
单元配置文件已受理
enabled
在系统启动时自动运行
disabled
在启动运行时不会自动启动
active(running)
正在通过一个或多个进程持续运行中
active(exited)
已经成功完成一次性的任务并结束守护
active(waiting)
运行中,但正在等待事件发生…
inactive
进程没有运行
控制系统服务
停止服务并检查服务状态
systemctl stop sshd.service systemctl status sshd.service
启动服务并检查服务状态
systemctl start sshd.service systemctl status sshd.service
重启服务实现对服务的停止和启动
systemctl restart sshd.service systemctl status sshd.service