為什麼NTP服務會成功退出?
在 Windows 8 Hyper-V 中執行的虛擬 Debian 8 機器上,我經常遇到日期時間停滯的問題。我沒有做太多的安裝後配置,這是一個特意的普通安裝,沒有花哨的東西——我只是將盒子用作一個獨立的 POSIX 環境,通過 SSH 使用 PuTTY 登錄。
當主機睡覺時,日期似乎“凍結”了,大約一天后,我在打開主機筆記型電腦的蓋子後將其喚醒。從 Windows 上的 PuTTy 到 VM 的 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 到 VM 仍然存在,那為什麼會是一個問題呢?
/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
預設情況下,
ntpd
如果系統時間與其計算時間相差太遠,將退出。(我不確定它將使用什麼退出程式碼。)您可以添加配置指令tinker panic 0
以防止它退出。