基于Systemd的系统使用systemctl命令:适用于 Fedora Linux v22/23/24/26/27/28/29/30/31CentOS/RHEL 7.0 /8.0
列出正在运行的服务systemctl
systemctl | more
systemctl | grep httpd
systemctl list-units --type service
systemctl list-units --type mount
列出所有服务systemctl list-unit-files
查看与特定服务(cgroup)关联的进程systemd-cgtop
输出示例:
Path Tasks %CPU Memory Input/s Output/s
/ 211 2.5 817.5M - -
/system.slice/ModemManager.service 1 - - - -
/system.slice/NetworkManager.service 2 - - - -
/system.slice/abrt-oops.service 1 - - - -
/system.slice/abrt-xorg.service 1 - - - -
/system.slice/abrtd.service 1 - - - -
/system.slice/accounts-daemon.service 1 - - - -
在CentOS/RHEL 7.x +上列出SysV服务chkconfig --list
如何使用systemd检查服务状态检查sshd的状态
$ systemctl status sshd.service
确认服务状态检查服务是否正在运行
systemctl is-active sshd
systemctl is-enabled sshd
systemctl is-active nginx
systemctl is-enabled nginx
systemctl is-enabled httpd
在RHEL/CentOS 8.x查看服务列出当前加载的服务:
$ sudo systemctl list-units --type=service
显示已加载的和活动的单元/服务:
$ sudo systemctl
使用grep命令/egrep命令过滤掉:
$ sudo systemctl | egrep 'httpd|php-fpm|mysqld|nginx'
$ sudo systemctl list-units --type=service | grep nginx
查看服务/单元的依赖关系# systemctl list-dependencies {service-name}
# systemctl list-dependencies nginx.service
# systemctl list-dependencies php-fpm.service
# systemctl list-dependencies sshd.service
# systemctl list-dependencies crond.service