云计算百科
云计算领域专业知识百科平台

Linux启动NTP服务报错Failed to start ntpd.service: Unit ntpd.service not found的解决办法

文章目录

  • 前言
  • 研究过程
  • 解决方法

前言

今天在使用Linux的过程中安装了NTP服务,刚安装完成时使用systemctl start ntpd命令顺利地启动了NTP服务,但接下来我尝试使用systemctl diable ntpd禁用开机自启动后,系统执行了以下操作:

Removed "/etc/systemd/system/multi-user.target.wants/ntpsec.service".
Removed "/etc/systemd/system/ntpd.service".
Removed "/etc/systemd/system/ntp.service".

然后再使用systemctl enable ntpd命令就提示Failed to enable unit: Unit file ntpd.service does not exist错误,使用systemctl start ntpd命令就会提示Failed to start ntpd.service: Unit ntpd.service not found错误。比较闲的话可以看看我的研究过程,不愿意看研究过程的可以直接看最后的解决办法。

研究过程

出现问题后,首先考虑的就是卸载重装NTP,但是这种方法好像并不会完全删除配置文件(即使是使用apt remove –purge也不行),无法恢复到最初状态,导致仍无法启动NTP以及查看状态。我根据网上给出的方法,使用systemctl list-units –type=service命令查看全部服务,但是由于我没有翻页查看导致我没看到NTP相关的服务,导致我认为是没有安装成功,于是我在可视化界面中找到etc目录(软件包一般安装在这个目录),在这个目录中找到了一个叫ntpsec的文件夹,于是我怀疑是命令有所更新,于是使用了systemctl enable ntpsec命令,发现成功输出了NTP有关信息!神奇的是,接下来再使用systemctl enable ntpd或systemctl start ntpd或systemctl status ntpd等命令均可成功执行。但具体是什么原理还没搞清楚。

解决方法

遇到Failed to start ntpd.service: Unit ntpd.service not found或Failed to enable unit: Unit file ntpd.service does not exist的错误时,可尝试使用如下命令:

systemctl enable ntpsec

然后再使用systemctl start ntpd等命令。目前沾点边的猜测是服务名称全名是ntpsec,最初安装时默认enable,disable之后必须使用全名来才能enable,之后才能使用类似缩写的ntpd。具体原理还没有搞清楚,欢迎大家一起讨论。

赞(0)
未经允许不得转载:网硕互联帮助中心 » Linux启动NTP服务报错Failed to start ntpd.service: Unit ntpd.service not found的解决办法
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!