centos没有/sbin/service命令的恢复方法(-bash: service: command not found)

centos系统中,如果/sbin目录下没有service这个命令,就会出现

-bash: service: command not found

的错误。

解决步骤如下:

1、输入:

[plain]  view plain  copy
  1. # yum list | grep initscripts  
会出现

initscripts.x86_64                         9.49.30-1.el7_2.3           updates

2、上面给出了可安装软件的yum源版本。

上面是目前系统已安装的initscripts情况,因为没有了service文件,显然已经出现了错误,然后执行

[plain]  view plain  copy
  1. # yum install initscripts  
会显示

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.btte.net
Resolving Dependencies
--> Running transaction check
---> Package initscripts.x86_64 0:9.49.30-1.el7_2.3 will be installed
--> Processing Dependency: iproute for package: initscripts-9.49.30-1.el7_2.3.x86_64
--> Running transaction check
---> Package iproute.x86_64 0:3.10.0-54.el7_2.1 will be installed
--> Processing Dependency: libxtables.so.10()(64bit) for package: iproute-3.10.0-54.el7_2.1.x86_64
--> Running transaction check
---> Package iptables.x86_64 0:1.4.21-16.el7 will be installed
--> Finished Dependency Resolution


Dependencies Resolved


===================================================================================================
 Package                Arch              Version                         Repository          Size
===================================================================================================
Installing:
 initscripts            x86_64            9.49.30-1.el7_2.3               updates            429 k
Installing for dependencies:
 iproute                x86_64            3.10.0-54.el7_2.1               updates            526 k
 iptables               x86_64            1.4.21-16.el7                   base               424 k


Transaction Summary
===================================================================================================
Install  1 Package (+2 Dependent packages)


Total download size: 1.3 M
Installed size: 4.2 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): iproute-3.10.0-54.el7_2.1.x86_64.rpm                                 | 526 kB  00:00:00     
(2/3): initscripts-9.49.30-1.el7_2.3.x86_64.rpm                             | 429 kB  00:00:00     
(3/3): iptables-1.4.21-16.el7.x86_64.rpm                                    | 424 kB  00:00:00     
---------------------------------------------------------------------------------------------------
Total                                                              1.7 MB/s | 1.3 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iptables-1.4.21-16.el7.x86_64                                                   1/3 
  Installing : iproute-3.10.0-54.el7_2.1.x86_64                                                2/3 
  Installing : initscripts-9.49.30-1.el7_2.3.x86_64                                            3/3 
  Verifying  : iptables-1.4.21-16.el7.x86_64                                                   1/3 
  Verifying  : iproute-3.10.0-54.el7_2.1.x86_64                                                2/3 
  Verifying  : initscripts-9.49.30-1.el7_2.3.x86_64                                            3/3 


Installed:
  initscripts.x86_64 0:9.49.30-1.el7_2.3                                                           


Dependency Installed:
  iproute.x86_64 0:3.10.0-54.el7_2.1                iptables.x86_64 0:1.4.21-16.el7               


Complete!


3、此时service已经可以使用。




附加:

如果还出现

bash: service: command not found

这个错误。两种方式解决:

两种方式: 
a、直接使用su - root来切换到root用户,然后使用 service 
b、使用su root切换到root用户,并同时使用/sbin/service来操作,如/sbin/service mysql restart.


参考:

http://www.centoscn.com/CentosBug/osbug/2015/0120/4527.html

http://lishaorui.iteye.com/blog/1583789


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值