{"id":208364,"date":"2025-07-26T17:55:44","date_gmt":"2025-07-26T09:55:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/?p=208364"},"modified":"2025-07-26T17:55:44","modified_gmt":"2025-07-26T09:55:44","slug":"ubuntu%e8%87%aa%e5%8b%95%e6%99%82%e9%96%93%e5%90%8c%e6%ad%a5%e8%a8%ad%e5%ae%9a%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208364\/","title":{"rendered":"Ubuntu\u81ea\u52d5\u6642\u9593\u540c\u6b65\u8a2d\u5b9a\u6307\u5357"},"content":{"rendered":"<p>\u5728 Ubuntu 20.04 \u4e2d\u8a2d\u5b9a\u6642\u9593\u540c\u6b65\u975e\u5e38\u7c21\u55ae\uff0c\u56e0\u70ba\u7cfb\u7d71\u9810\u8a2d\u4f7f\u7528 `systemd-timesyncd` \u670d\u52d9\u9032\u884c\u81ea\u52d5\u6642\u9593\u540c\u6b65\u3002\u4ee5\u4e0b\u662f\u5b8c\u6574\u7684\u8a2d\u5b9a\u6b65\u9a5f\uff1a<\/p>\n<p>### 1. \u6aa2\u67e5\u7576\u524d\u6642\u9593\u72c0\u614b<br \/>\n&#8220;`bash<br \/>\ntimedatectl<br \/>\n&#8220;`<br \/>\n\u67e5\u770b\u8f38\u51fa\u4e2d\u7684\u95dc\u9375\u8cc7\u8a0a\uff1a<br \/>\n&#8211; `System clock synchronized`: \u61c9\u70ba `yes`\uff08\u8868\u793a\u5df2\u555f\u7528\u540c\u6b65\uff09<br \/>\n&#8211; `NTP service`: \u61c9\u70ba `active`\uff08\u8868\u793a\u670d\u52d9\u5df2\u555f\u7528\uff09<\/p>\n<p>### 2. \u555f\u7528\u6642\u9593\u540c\u6b65\u670d\u52d9<br \/>\n&#8220;`bash<br \/>\nsudo timedatectl set-ntp on<br \/>\n&#8220;`<\/p>\n<p>### 3. \u91cd\u555f\u6642\u9593\u540c\u6b65\u670d\u52d9<br \/>\n&#8220;`bash<br \/>\nsudo systemctl restart systemd-timesyncd<br \/>\n&#8220;`<\/p>\n<p>### 4. \u9a57\u8b49\u540c\u6b65\u72c0\u614b<br \/>\n&#8220;`bash<br \/>\ntimedatectl status<br \/>\n&#8220;`<br \/>\n\u78ba\u8a8d\uff1a<br \/>\n&#8211; `System clock synchronized: yes`<br \/>\n&#8211; `NTP service: active`<\/p>\n<p>### 5. \uff08\u53ef\u9078\uff09\u8a2d\u5b9a\u81ea\u8a02 NTP \u4f3a\u670d\u5668<br \/>\n\u7de8\u8f2f\u8a2d\u5b9a\u6a94\uff1a<br \/>\n&#8220;`bash<br \/>\nsudo nano \/etc\/systemd\/timesyncd.conf<br \/>\n&#8220;`<br \/>\n\u4fee\u6539\u5167\u5bb9\uff08\u4f8b\u5982\u4f7f\u7528\u963f\u91cc\u96f2 NTP \u4f3a\u670d\u5668\uff09\uff1a<br \/>\n&#8220;`ini<br \/>\n[Time]<br \/>\nNTP=ntp.aliyun.com<br \/>\nFallbackNTP=ntp.ubuntu.com<br \/>\n&#8220;`<br \/>\n\u5132\u5b58\u5f8c\u5957\u7528\u8b8a\u66f4\uff1a<br \/>\n&#8220;`bash<br \/>\nsudo systemctl restart systemd-timesyncd<br \/>\n&#8220;`<\/p>\n<p>### 6. \uff08\u53ef\u9078\uff09\u8a2d\u5b9a\u6642\u5340<br \/>\n&#8220;`bash<br \/>\n# \u5217\u51fa\u6240\u6709\u6642\u5340<br \/>\ntimedatectl list-timezones<\/p>\n<p># \u8a2d\u5b9a\u6642\u5340\uff08\u4f8b\u5982\u4e0a\u6d77\uff09<br \/>\nsudo timedatectl set-timezone Asia\/Shanghai<br \/>\n&#8220;`<\/p>\n<p>### 7. \u67e5\u770b\u8a73\u7d30\u540c\u6b65\u8cc7\u8a0a<br \/>\n&#8220;`bash<br \/>\nsystemctl status systemd-timesyncd<br \/>\n&#8220;`<br \/>\n\u8f38\u51fa\u4e2d\u61c9\u5305\u542b\u985e\u4f3c\u8cc7\u8a0a\uff1a<br \/>\n&#8220;`<br \/>\nActive: active (running)<br \/>\nStatus: &#8220;Synchronized to time server 203.107.6.88:123 (ntp.aliyun.com)&#8221;<br \/>\n&#8220;`<\/p>\n<p>### 8. \u624b\u52d5\u5f37\u5236\u540c\u6b65\uff08\u6e2c\u8a66\u7528\uff09<br \/>\n&#8220;`bash<br \/>\nsudo systemctl stop systemd-timesyncd<br \/>\nsudo systemd-timesyncd &#8211;force<br \/>\nsudo systemctl start systemd-timesyncd<br \/>\n&#8220;`<\/p>\n<p>### \u5e38\u898b\u554f\u984c\u89e3\u6c7a\uff1a<\/p>\n<p>**Q: \u6642\u9593\u540c\u6b65\u4e0d\u5de5\u4f5c\u600e\u9ebc\u8fa6\uff1f**<br \/>\n1. \u6aa2\u67e5\u7db2\u8def\u9023\u7dda\uff1a<br \/>\n&#8220;`bash<br \/>\nping ntp.aliyun.com<br \/>\n&#8220;`<br \/>\n2. \u6aa2\u67e5\u9632\u706b\u7246\u662f\u5426\u5141\u8a31 NTP\uff08UDP 123\u7aef\u53e3\uff09\uff1a<br \/>\n&#8220;`bash<br \/>\nsudo ufw allow 123\/udp<br \/>\n&#8220;`<br \/>\n3. \u67e5\u770b\u670d\u52d9\u65e5\u8a8c\uff1a<br \/>\n&#8220;`bash<br \/>\njournalctl -u systemd-timesyncd<br \/>\n&#8220;`<\/p>\n<p>**Q: \u5982\u4f55\u5fb9\u5e95\u505c\u7528\u6642\u9593\u540c\u6b65\uff1f**<br \/>\n&#8220;`bash<br \/>\nsudo timedatectl set-ntp off<br \/>\nsudo systemctl stop systemd-timesyncd<br \/>\nsudo systemctl disable systemd-timesyncd<br \/>\n&#8220;`<\/p>\n<p>&gt; **\u6ce8\u610f**\uff1a<br \/>\n&gt; &#8211; Ubuntu 20.04 \u9810\u8a2d\u4f7f\u7528 `systemd-timesyncd`\uff0c\u7121\u9700\u984d\u5916\u5b89\u88dd\u8edf\u9ad4<br \/>\n&gt; &#8211; \u5982\u679c\u9700\u8981\u66f4\u9ad8\u968e\u7684\u6642\u9593\u540c\u6b65\uff08\u5982\u4f3a\u670d\u5668\u74b0\u5883\uff09\uff0c\u53ef\u5b89\u88dd `chrony`\uff1a<br \/>\n&gt; &#8220;`bash<br \/>\n&gt; sudo apt install chrony<br \/>\n&gt; sudo systemctl enable &#8211;now chrony<br \/>\n&gt; &#8220;`<br \/>\n&gt; &#8211; \u786c\u9ad4\u6642\u9418\u540c\u6b65\uff1a`sudo hwclock &#8211;systohc`<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Ubuntu 20.04 \u4e2d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-208364","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208364"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208364\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}