首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Centos ntpd不能同步

Centos ntpd不能同步
EN

Server Fault用户
提问于 2021-07-07 20:36:52
回答 1查看 662关注 0票数 0

我有一个Centos 5虚拟机(我知道Centos5非常老),它拒绝同步。我的虚拟机主机是带有HyperV的Windows 10,并且同步没有问题。

我尝试过的事情:

  1. 重新启动vm。
  2. 禁用vm防火墙。
  3. 将ntpd.conf与正在工作且也是Centos 5的远程ntpd.conf进行比较。
  4. 启用HyperV集成服务
  5. 启用HyperV时间同步服务
  6. 安装所有Windows更新。

下面是我的/var/log/消息的摘录:

代码语言:javascript
运行
复制
[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 4.2.2p1@1.1570-o 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 4.2.2p1@1.1570-o 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/消息的提取:

代码语言:javascript
运行
复制
[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 4.2.2p1@1.1570-o 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 4.2.2p1@1.1570-o 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

正如您所看到的,远程消息文件有几行“同步”,但是这些行没有出现在我的消息文件中。

如何启用时间同步?

EDIT1:

代码语言:javascript
运行
复制
[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

EDIT3:

代码语言:javascript
运行
复制
[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]#

EDIT4:

代码语言:javascript
运行
复制
[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:工作(远程)系统时钟(这将是正确的时间):

代码语言:javascript
运行
复制
Thu Jul  8 08:19:36 CDT 2021

我的(不正确)时钟:

代码语言:javascript
运行
复制
Thu Jul  8 01:08:51 CDT 2021

EDIT6: tcpdump -ni eth0 'udp端口123‘的输出

代码语言:javascript
运行
复制
[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
EN

回答 1

Server Fault用户

发布于 2021-07-17 20:47:03

我就是这样解决问题的:

1.-我手动调整时钟:

代码语言:javascript
运行
复制
ntpdate -u  1.centos.pool.ntp.org

2.-我创建了一个cron作业,用于每小时同步时钟一次:

代码语言:javascript
运行
复制
crontab -l
59 * * * * /sbin/ntpdate -u  1.centos.pool.ntp.org >> /root/timesync.txt
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1068934

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档