目录
1.管理服务当前状态
(1)查看后缀为service的服务。
[root@rhel1 ~]# systemctl list-unit-files --type service
(2)查看sshd服务的是否正常运行。
[root@rhel1 ~]# systemctl is-active sshd 查看
active active表示运行
[root@rhel1 ~]# systemctl stop sshd 关闭sshd服务
[root@rhel1 ~]# systemctl is-active sshd 查看
inactive inactive表示关闭
(3)服务的开启、查看状态、关闭、重启、开机自动启动命令如下。
[root@rhel1 ~]# systemctl start sshd 开启服务
[root@rhel1 ~]# systemctl status sshd 查看状态,按【q】键退出
[root@rhel1 ~]# systemctl stop sshd 关闭服务
[root@rhel1 ~]# systemctl restart sshd 重启服务
[root@rhel1 ~]# systemctl enable sshd 开机自动启动
(4)禁用服务和取消禁用。
[root@rhel1 ~]# systemctl mask sshd 禁用sshd服务
Created symlink /etc/systemd/system/sshd.service → /dev/null.
[root@rhel1 ~]# systemctl unmask sshd 取消禁用
Removed /etc/systemd/system/sshd.service.
-
将sshd设置为mask,此服务关闭之后就不能再启动了,这个类似于Windows中把某服务禁用了。
2.管理服务开机是否自动启动
(1)查看服务是否开机自动启动。
[root@rhel1 ~]# systemctl is-enabled sshd
enabled enabled表示开机会自动运行
[root@rhel1 ~]# systemctl disable sshd 关闭开机自动运行
[root@rhel1 ~]# systemctl is-enabled sshd
disabled disabled表示开机不会自动运行
3.判断服务名是什么
很多时候我们安装了某个软件之后,想知道服务名是什么,可以通过“systemctl list-unit-files--type service | grep关键字”来判断。例如,ssh这个服务到底是ssh还是 sshd ?
[root@rhel1 ~]# systemctl list-unit-files --type service | grep ssh
anaconda-sshd.service static
sshd-keygen@.service disabled
sshd.service disabled
sshd@.service static
sssd-ssh.service indirect





