ntp.conf的配置 (虚拟机不能直接连接公网,修改的地方已标红)
[root@localhost ~]# cat /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# 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
#restrict default nomodify
#restrict -6 default kod nomodify notrap nopeer noquery
#restrict 10.2.0.0 mask 255.255.0.0 nomodify
restrict default nomodify notrap noquery restrict 10.2.0.0 mask 255.255.0.0 notrust nomodify notrap
# 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 pool.ntp.org
#server 127.0.0.1
# 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 # local clock fudge 127.127.1.0 stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# 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
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
logfile /var/log/ntp/ntp.log
执行ntpstat结果
[root@localhost ~]# ntpstat
synchronised to local net at stratum 11
time correct to within 11 ms
polling server every 1024 s
执行ntpq -p结果
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 25 64 377 0.000 0.000 0.000
暂时先贴这些,如果有需要我会追加详细配置情况,请各位达人不吝赐教。
7 个解决方案
#1
首先 你的虚拟机要与宿主机同步时间的话,最重要的一条配置 没有配
server 10.2.1.20
配置后重启ntp服务,10分钟后查看ntpq -p 结果中 10.2.1.20有无*号
其次,有一点可能我也不太清楚,接触过的环境一般ntp server 和ntp client 都是linux
没有设置过 ntp server 是windows的情况,不知道windows通过什么提供ntp服务