第七章 服务管理

目录

1.管理服务当前状态

2.管理服务开机是否自动启动

3.判断服务名是什么


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
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值