我有一台 Centos 5(我知道 Centos5 非常非常老)虚拟机,它拒绝同步。我的虚拟机主机是带有 HyperV 的 Windows 10,同步没有问题。
我尝试过的事情:
- 重新启动虚拟机。
- 禁用虚拟机防火墙。
- 将 ntpd.conf 与正在运行且也是 Centos 5 的远程 ntpd.conf 进行比较。
- 启用 HyperV 集成服务
- 启用 HyperV 时间同步服务
- 安装所有 Windows 更新。
以下是我的 /var/log/messages 的摘录:
[root@evtest etc]# cat /var/log/messages | grep "ntpd"
Jul 5 15:10:03 evtest ntpd[2174]: ntpd exiting on signal 15
Jul 6 01:44:26 evtest ntpd[2174]: ntpd [email protected] Sat Dec 20 02:52:11 UTC 2014 (1)
Jul 6 01:44:26 evtest ntpd[2175]: precision = 1.000 usec
Jul 6 01:44:26 evtest ntpd[2175]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Jul 6 01:44:26 evtest ntpd[2175]: Listening on interface lo, 127.0.0.1#123 Enabled
Jul 6 01:44:26 evtest ntpd[2175]: Listening on interface eth0, 192.168.1.36#123 Enabled
Jul 6 01:44:26 evtest ntpd[2175]: kernel time sync status 0040
Jul 6 01:44:26 evtest ntpd[2175]: getaddrinfo: "::1" invalid host address, ignored
Jul 6 01:44:26 evtest ntpd[2175]: frequency initialized 2.488 PPM from /var/lib/ntp/drift
Jul 6 01:47:47 evtest ntpd[2175]: synchronized to LOCAL(0), stratum 10
Jul 6 01:47:47 evtest ntpd[2175]: kernel time sync enabled 0001
Jul 6 14:30:39 evtest ntpd[2175]: ntpd exiting on signal 15
Jul 7 00:16:54 evtest ntpd[2174]: ntpd [email protected] Sat Dec 20 02:52:11 UTC 2014 (1)
Jul 7 00:16:54 evtest ntpd[2175]: precision = 1.000 usec
Jul 7 00:16:54 evtest ntpd[2175]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Jul 7 00:16:54 evtest ntpd[2175]: Listening on interface lo, 127.0.0.1#123 Enabled
Jul 7 00:16:54 evtest ntpd[2175]: Listening on interface eth0, 192.168.1.36#123 Enabled
Jul 7 00:16:54 evtest ntpd[2175]: kernel time sync status 0040
Jul 7 00:16:54 evtest ntpd[2175]: getaddrinfo: "::1" invalid host address, ignored
Jul 7 00:16:56 evtest ntpd[2175]: frequency initialized 2.488 PPM from /var/lib/ntp/drift
Jul 7 00:20:12 evtest ntpd[2175]: synchronized to LOCAL(0), stratum 10
Jul 7 00:20:12 evtest ntpd[2175]: kernel time sync enabled 0001
以下是远程 /var/log/messages 的摘录:
[root@centos5 etc]# cat /var/log/messages.1 | grep "ntpd"
Jun 29 20:25:13 centos5 ntpd[3301]: ntpd exiting on signal 15
Jun 29 20:44:25 centos5 ntpd[3298]: ntpd [email protected] Sat Dec 20 02:52:11 UTC 2014 (1)
Jun 29 20:44:25 centos5 ntpd[3299]: precision = 1.000 usec
Jun 29 20:44:25 centos5 ntpd[3299]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Jun 29 20:44:25 centos5 ntpd[3299]: Listening on interface lo, 127.0.0.1#123 Enabled
Jun 29 20:44:25 centos5 ntpd[3299]: Listening on interface eth0, 1.10.100.57#123 Enabled
Jun 29 20:44:25 centos5 ntpd[3299]: kernel time sync status 0040
Jun 29 20:44:25 centos5 ntpd[3299]: getaddrinfo: "::1" invalid host address, ignored
Jun 29 20:44:26 centos5 ntpd[3299]: frequency initialized 39.595 PPM from /var/lib/ntp/drift
Jun 29 20:47:41 centos5 ntpd[3299]: synchronized to LOCAL(0), stratum 10
Jun 29 20:47:41 centos5 ntpd[3299]: kernel time sync enabled 0001
Jun 29 20:49:51 centos5 ntpd[3299]: synchronized to 192.36.143.130, stratum 1
Jun 29 21:09:14 centos5 ntpd[3299]: time reset +2.461477 s
Jun 29 21:13:01 centos5 ntpd[3299]: synchronized to LOCAL(0), stratum 10
Jun 29 21:15:10 centos5 ntpd[3299]: synchronized to 192.36.143.130, stratum 1
Jul 3 18:52:20 centos5 ntpd[3299]: ntpd exiting on signal 15
Jul 3 22:08:54 centos5 ntpd[3299]: ntpd [email protected] Sat Dec 20 02:52:11 UTC 2014 (1)
Jul 3 22:08:54 centos5 ntpd[3300]: precision = 1.000 usec
Jul 3 22:08:54 centos5 ntpd[3300]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Jul 3 22:08:54 centos5 ntpd[3300]: Listening on interface lo, 127.0.0.1#123 Enabled
Jul 3 22:08:54 centos5 ntpd[3300]: Listening on interface eth0, 1.10.100.57#123 Enabled
Jul 3 22:08:54 centos5 ntpd[3300]: kernel time sync status 0040
Jul 3 22:08:54 centos5 ntpd[3300]: getaddrinfo: "::1" invalid host address, ignored
Jul 3 22:08:55 centos5 ntpd[3300]: frequency initialized 37.845 PPM from /var/lib/ntp/drift
Jul 3 22:12:08 centos5 ntpd[3300]: synchronized to LOCAL(0), stratum 10
Jul 3 22:12:08 centos5 ntpd[3300]: kernel time sync enabled 0001
Jul 3 22:14:16 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
Jul 3 22:29:31 centos5 ntpd[3300]: time reset +15.928958 s
Jul 3 22:33:42 centos5 ntpd[3300]: synchronized to LOCAL(0), stratum 10
Jul 3 22:34:17 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
Jul 3 23:17:50 centos5 ntpd[3300]: synchronized to 41.220.128.73, stratum 2
Jul 3 23:33:59 centos5 ntpd[3300]: synchronized to 193.182.111.13, stratum 2
Jul 3 23:38:16 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
Jul 4 00:00:48 centos5 ntpd[3300]: synchronized to 41.220.128.73, stratum 2
Jul 4 00:08:13 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
Jul 4 00:13:02 centos5 ntpd[3300]: synchronized to 41.220.128.73, stratum 2
Jul 4 00:15:57 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
Jul 4 00:16:13 centos5 ntpd[3300]: synchronized to 193.182.111.13, stratum 2
Jul 4 00:48:05 centos5 ntpd[3300]: synchronized to 41.220.128.73, stratum 2
Jul 4 03:07:45 centos5 ntpd[3300]: synchronized to 45.231.168.6, stratum 2
如您所见,远程消息文件有几行“同步到”但这些行没有出现在我的消息文件中。
如何启用时间同步?
编辑1:
[root@evtest etc]# echo "peers" | ntpq
remote refid st t when poll reach delay offset jitter
==============================================================================
karhu.miuku.net .INIT. 16 u - 1024 0 0.000 0.000 0.000
ntp2.flashdance .RMOT. 16 u - 1024 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 10 l 24 64 377 0.000 0.000 0.001
[root@evtest etc]#
EDIT2:我更喜欢使用 ntpd
编辑3:
[root@evtest etc]# cat /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
server 3.centos.pool.ntp.org
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
restrict 0.centos.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 1.centos.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 2.centos.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 3.centos.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
[root@evtest etc]#
编辑4:
[root@evtest etc]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@evtest etc]#
EDIT5:工作(远程)系统时钟(这将是正确的时间):
Thu Jul 8 08:19:36 CDT 2021
我的(错误)时钟:
Thu Jul 8 01:08:51 CDT 2021
EDIT6: tcpdump -ni eth0'udp port 123' 的输出
[root@evtest ~]# tcpdump -ni eth0 'udp port 123'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
09:16:26.065503 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
09:16:30.064984 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
09:33:30.065630 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
09:33:33.064632 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
09:50:35.065585 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
09:50:39.065966 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
10:07:40.065476 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
10:07:42.065569 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
10:24:44.065691 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
10:24:45.066300 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
10:41:49.065627 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
10:41:50.065270 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
10:58:54.065499 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
10:58:55.065089 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
11:15:58.065713 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
11:15:59.065277 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
11:33:01.065423 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
11:33:05.064858 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
11:50:07.065780 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
11:50:09.066043 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
12:07:11.065087 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
12:07:14.065845 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
12:24:16.064951 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
12:24:18.065121 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
12:41:21.065706 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
12:41:21.065719 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
12:58:24.065325 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
12:58:25.064950 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
13:15:29.066151 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
13:15:31.066342 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
13:32:32.065751 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
13:32:37.065828 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
13:49:35.065384 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
13:49:41.065109 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
14:06:41.065836 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
14:06:47.066553 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
14:23:44.065511 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
14:23:51.065093 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
14:40:47.066145 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
14:40:55.065992 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
14:57:50.065718 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
14:57:58.065650 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
15:14:55.064675 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
15:15:01.065336 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
15:32:01.065972 IP 192.168.1.36.ntp > 195.3.254.2.ntp: NTPv4, Client, length 48
15:32:07.065768 IP 192.168.1.36.ntp > 192.36.143.130.ntp: NTPv4, Client, length 48
答案1
无法访问您的远程对等点。这可能是由于 中的本地限制/etc/ntp.conf
、本地防火墙设置、上游防火墙设置或您与 NTP 服务器之间的连接问题。
/etc/ntp.conf
您的和诊断的内容iptables
表明问题可能不是您的本地配置。您的tcpdump -ni eth0 'udp port 123'
确认数据包已成功离开您的系统,但尚未得到回复。
因此,看起来您遇到了上游连接问题。
答案2
这就是我解决问题的方法:
1.-我手动调整了时钟:
ntpdate -u 1.centos.pool.ntp.org
2.-我创建了一个 cron 作业来每小时同步一次我的时钟:
crontab -l
59 * * * * /sbin/ntpdate -u 1.centos.pool.ntp.org >> /root/timesync.txt