我在运行 Windows 8 Hyper-V 的虚拟 Debian 8 机器上反复遇到日期时间停滞的问题。我没有做太多的安装后配置,这是一个刻意的相当普通的安装,没有什么花哨的东西——我只是把这个盒子当作一个独立的 POSIX 环境,通过 SSH 使用 PuTTY 登录。
当主机休眠时,日期似乎“冻结”,大约一天后,我打开主机笔记本电脑的盖子将其唤醒。Windows 上 PuTTy 与虚拟机的 SSH 会话始终保持完整。我不想为 Linux 的 Hyper-V 特定时间同步服务而烦恼,我满足于使用 NTP。NTP 已安装,apt-get install ntp
最初我使用 获得以下信息systemctl status ntp
:
● ntp.service - LSB: Start NTP daemon
Loaded: loaded (/etc/init.d/ntp)
Active: active (running) since Mon 2017-08-14 23:16:55 CEST; 20h ago
Process: 1167 ExecStop=/etc/init.d/ntp stop (code=exited, status=0/SUCCESS)
Process: 1175 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/ntp.service
└─1184 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 108:115
今天唤醒笔记本电脑并再次观察昨天的“冻结”日期后,与上述相同的命令告诉我服务已退出:
● ntp.service - LSB: Start NTP daemon
Loaded: loaded (/etc/init.d/ntp)
Active: active (exited) since Mon 2017-08-14 21:28:57 CEST; 1h 43min ago
Process: 450 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
为什么服务似乎会自动退出?显然,只要主机从睡眠/休眠状态解冻,它就会退出。而且0/SUCCESS
,为什么让我相信它的行为是按照设计进行的,并且不会遇到错误?
一旦我systemctl restart ntp
将该进程重新归入计划进程中并且日期已同步。执行systemctl start ntp
不会产生相同的效果(可能是因为它已经“加载”/“活动”)。
发生了什么事?NTP 不是应该一直运行,并在时钟漂移时根据需要定期同步时钟吗?这是内核中与 Hyper-V 相关的一些模块,它是否采纳了 Microsoft 的建议,即不要将 NTP 与虚拟机一起使用,或者可能是网络堆栈导致 NTP 失效?即使它是 UDP,甚至虚拟机的 SSH 仍然存在,那么这为什么会成为问题呢?
/etc/ntp.conf,我自己从来没有编辑过它:
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(6) for help
driftfile /var/lib/ntp/ntp.drift
# 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
# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
# 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
答案1
默认情况下,ntpd
如果系统时间与其计算的时间相差太远,它将退出。(我不确定它将使用什么退出代码。)您可以添加配置指令tinker panic 0
来阻止它退出。