前言
今天在使用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。
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论