首先,我ntp
通过sudo apt-get install ntp
我访问/etc/ntp.conf
并根据国家/地区将服务器更改为几个本地服务器,然后我保存并重新启动它,sudo systemctl restart ntp
然后检查显示正在运行的状态sudo systemctl status ntp
。
我也这样做了ntpq -p
,得到了以下结果,我认为这意味着客户端正在运行:
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000
*time-a-g.nist.g .NIST. 1 u - 64 77 11.567 -7.287 7.636
-174.138.107.37 46.243.26.34 2 u 63 64 37 84.975 0.159 4.474
-ns3.weiszhostin 128.138.141.172 2 u 1 64 77 69.844 -11.884 6.043
+li290-38.member 128.138.141.172 2 u 65 64 37 43.448 -3.202 6.023
+pugot.canonical 145.238.203.14 2 u 61 64 37 79.540 -5.833 4.040
+alphyn.canonica 132.246.11.231 2 u 4 64 77 11.714 -5.017 7.244
+chilipepper.can 145.238.203.14 2 u 61 64 37 78.136 -4.269 4.769
+golem.canonical 145.238.203.14 2 u 55 64 37 81.139 -3.766 4.748
但是,我似乎无法让守护进程运行。我发现当我这样做时sudo systemctl status ntpd
,它给出了以下结果:
ntpd.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
我以为它一开始没有启动,所以我就启动了sudo systemctl start ntpd
,但它给出了:
Failed to start ntpd.service: Unit ntpd.service not found.
就在那时,我发现有些事情很严重,我检查了一下ls -l /etc/init.d
,发现ntp
列表中只有,ntpd
找不到。我也试过重新安装,ntp
但没有用。
有什么想法吗?非常感谢!
答案1
这是我在 Ubuntu 18.04 LTS 上长期存在的问题。它已启用,但处于非活动状态,因此每次重启后我都必须手动启动它。
$ sudo systemctl status ntp.service
● ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:ntpd(8)
原因与服务冲突systemd-timesyncd.service,它是 systemd 的一部分。禁用它之后,ntp.service 开始成功启动。
$ sudo systemctl show ntp.service | grep Conflicts
Conflicts=shutdown.target systemd-timesyncd.service
$ sudo systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-07-12 05:17:21 UTC; 18min ago
$ dpkg -S /lib/systemd/system/systemd-timesyncd.service
systemd: /lib/systemd/system/systemd-timesyncd.service
$ sudo systemctl disable systemd-timesyncd.service
Removed /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service.
答案2
sudo apt-get install -y ntp
sudo timedatectl set-ntp on
sudo service ntp restart
sudo service ntp status | cat
答案3
sudo systemctl unmask ntp.service
sudo systemctl start ntp.service
sudo systemctl enable ntp.service
瞧!
答案4
NTP 是一种点对点协议,因此ntpd
守护进程同时充当服务器和客户端。
ntp
在 Ubuntu 上,即使守护进程名为,服务也会被命名ntpd
。如果你查看输出,sudo systemctl status ntp
你会看到它实际上运行了ntpd
:
CGroup: /system.slice/ntp.service
└─1201 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 110:118
所以一切都很好。systemctl
显示ntpd
守护进程正在运行,并ntpq -p
显示它已成功同步到其他服务器。