这是我的情况:我在我的工作站上运行多个虚拟机来模拟生产环境。 在一天结束的时候,我在下午6点睡觉我的工作站(我的虚拟机在后台运行)。 当我第二天早上8点回到办公室并唤醒工作站时,所有的虚拟机都在下午6点。
厌倦了重置NTP或者简单地记住强制更新,我把下面的内容放在5分钟的cron中
service ntp stop && ntpd -gq && service ntp start
这是我的/etc/ntp.conf
tinker panic 0 driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntpd.log # Enable this if you want statistics to be logged. #statsdir /var/log/ntpstats/ statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # Specify one or more NTP servers. # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for # more information. server 0.ubuntu.pool.ntp.org server 1.ubuntu.pool.ntp.org server 2.ubuntu.pool.ntp.org server 3.ubuntu.pool.ntp.org # Use Ubuntu's ntp server as a fallback. server ntp.ubuntu.com # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions> # might also be helpful. # # Note that "restrict" applies to both servers and clients, so a configuration # that might be intended to block requests from certain clients could also end # up blocking replies from your own upstream servers. # By default, exchange time with everybody, but don't allow configuration. restrict -4 default kod notrap nomodify nopeer noquery restrict -6 default kod notrap nomodify nopeer noquery # Local users may interrogate the ntp server more closely. restrict 127.0.0.1 restrict ::1 # Clients from this (example!) subnet have unlimited access, but only if # cryptographically authenticated. #restrict 192.168.123.0 mask 255.255.255.0 notrust # If you want to provide time to your local subnet, change the next line. # (Again, the address is an example only.) #broadcast 192.168.123.255 # If you want to listen to time broadcasts on your local subnet, de-comment the # next lines. Please do this only if you trust everybody on the network! #disable auth #broadcastclient
有没有更好的方法来完成这个?
如果您正在使用VMware Workstation(或VMware vSphere),则可以使用特定的方法在您的(Linux)虚拟机上处理计时 。 但是,这是不够的,你的睡眠情况。 客人专用的NTP在这里没有帮助。
您绝对需要在来宾虚拟机上安装VMware来宾工具 ,并确保在主机上运行NTP。 这将解决睡眠问题和客人被暂停时发生的漂移。
编辑:
哦,这是Ubuntu …我发现许多Ubuntu用户不会安装本地VMware工具套件。 下面是完成这个步骤 (和一个video)。
您的ntp.conf应该工作! 我发现有时ntpd需要相当长的一段时间来纠正一个实质性的时间差异。 (我已经看到它需要12个小时才能真正进行修正)。
你应该发现,如果你把它放在一夜之间(没有你的cron工作),那么它最终会自我纠正。
使用iburst也可以帮助更快地设置时钟,但是这只对服务启动有效。
大多数应用程序可能需要使用server命令指定iburst选项。 通过这个选项,大量的信息被交换来修整数据并在十秒内设置时钟。
您需要找出重启APCI恢复服务的方法。 ( 你可以试试这个)