{"id":44544,"date":"2024-10-06T16:25:23","date_gmt":"2024-10-06T08:25:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/44544\/"},"modified":"2024-10-06T16:25:23","modified_gmt":"2024-10-06T08:25:23","slug":"linux-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8%e5%ae%89%e5%85%a8%e7%9a%84-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/44544\/","title":{"rendered":"Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u6280\u5de7\uff1a\u4f7f\u7528\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668"},"content":{"rendered":"<h1 id=\"linux-%e4%bc%ba%e6%9c%8d%e5%99%a8%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%e6%8a%80%e5%b7%a7%ef%bc%9a%e4%bd%bf%e7%94%a8%e5%ae%89%e5%85%a8%e7%9a%84-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8-GhNpuKpTul\">Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\u6280\u5de7\uff1a\u4f7f\u7528\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u4f3a\u670d\u5668\u7684\u5b89\u5168\u6027\u81f3\u95dc\u91cd\u8981\u3002Linux \u4f3a\u670d\u5668\u4f5c\u70ba\u8a31\u591a\u4f01\u696d\u548c\u500b\u4eba\u7528\u6236\u7684\u9996\u9078\uff0c\u5fc5\u9808\u63a1\u53d6\u6709\u6548\u7684\u5b89\u5168\u7b56\u7565\u4f86\u4fdd\u8b77\u5176\u6578\u64da\u548c\u670d\u52d9\u3002\u5176\u4e2d\uff0c\u7db2\u7d61\u6642\u9593\u5354\u8b70\uff08NTP\uff09\u4f3a\u670d\u5668\u7684\u5b89\u5168\u6027\u5e38\u5e38\u88ab\u5ffd\u8996\uff0c\u4f46\u5b83\u5c0d\u65bc\u4f3a\u670d\u5668\u7684\u6574\u9ad4\u5b89\u5168\u6027\u537b\u6709\u8457\u4e0d\u53ef\u6216\u7f3a\u7684\u5f71\u97ff\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8%ef%bc%9f-GhNpuKpTul\">\u4ec0\u9ebc\u662f NTP \u4f3a\u670d\u5668\uff1f<\/h2>\n<p>NTP\uff08Network Time Protocol\uff09\u662f\u4e00\u7a2e\u7528\u65bc\u540c\u6b65\u8a08\u7b97\u6a5f\u7cfb\u7d71\u6642\u9593\u7684\u5354\u8b70\u3002\u5b83\u80fd\u5920\u78ba\u4fdd\u4f3a\u670d\u5668\u7684\u6642\u9593\u6e96\u78ba\uff0c\u9019\u5c0d\u65bc\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u548c\u670d\u52d9\u4f86\u8aaa\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4f8b\u5982\uff0c\u6b63\u78ba\u7684\u6642\u9593\u6233\u5c0d\u65bc\u65e5\u8a8c\u8a18\u9304\u3001\u6578\u64da\u5eab\u64cd\u4f5c\u548c\u5b89\u5168\u6027\u6aa2\u67e5\u7b49\u90fd\u8d77\u8457\u91cd\u8981\u4f5c\u7528\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7%e9%87%8d%e8%a6%81%ef%bc%9f-GhNpuKpTul\">\u70ba\u4ec0\u9ebc NTP \u4f3a\u670d\u5668\u7684\u5b89\u5168\u6027\u91cd\u8981\uff1f<\/h2>\n<p>\u5982\u679c NTP \u4f3a\u670d\u5668\u53d7\u5230\u653b\u64ca\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u4ee5\u4e0b\u5e7e\u7a2e\u554f\u984c\uff1a<\/p>\n<ul>\n<li><strong>\u6642\u9593\u7be1\u6539\uff1a<\/strong>\u653b\u64ca\u8005\u53ef\u4ee5\u901a\u904e\u64cd\u7e31\u6642\u9593\u4f86\u96b1\u85cf\u5176\u884c\u70ba\uff0c\u6216\u4f7f\u7cfb\u7d71\u7121\u6cd5\u6b63\u5e38\u904b\u884c\u3002<\/li>\n<li><strong>\u6578\u64da\u4e0d\u4e00\u81f4\uff1a<\/strong>\u4e0d\u6e96\u78ba\u7684\u6642\u9593\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u4e0d\u4e00\u81f4\uff0c\u5f71\u97ff\u696d\u52d9\u904b\u4f5c\u3002<\/li>\n<li><strong>\u5b89\u5168\u6f0f\u6d1e\uff1a<\/strong>\u8a31\u591a\u5b89\u5168\u5354\u8b70\u4f9d\u8cf4\u65bc\u6e96\u78ba\u7684\u6642\u9593\u6233\uff0c\u6642\u9593\u932f\u8aa4\u53ef\u80fd\u6703\u5c0e\u81f4\u5b89\u5168\u6f0f\u6d1e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%81%b8%e6%93%87%e5%ae%89%e5%85%a8%e7%9a%84-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8%ef%bc%9f-GhNpuKpTul\">\u5982\u4f55\u9078\u64c7\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668\uff1f<\/h2>\n<p>\u9078\u64c7\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668\u662f\u4fdd\u8b77 Linux \u4f3a\u670d\u5668\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8%e5%8f%af%e4%bf%a1%e7%9a%84%e5%85%ac%e5%85%b1-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8-GhNpuKpTul\">1. \u4f7f\u7528\u53ef\u4fe1\u7684\u516c\u5171 NTP \u4f3a\u670d\u5668<\/h3>\n<p>\u9078\u64c7\u77e5\u540d\u7684\u516c\u5171 NTP \u4f3a\u670d\u5668\uff0c\u5982 <code>pool.ntp.org<\/code>\uff0c\u9019\u4e9b\u4f3a\u670d\u5668\u901a\u5e38\u7531\u793e\u5340\u7dad\u8b77\uff0c\u4e26\u4e14\u6709\u8f03\u9ad8\u7684\u53ef\u7528\u6027\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae-ntp-%e4%bc%ba%e6%9c%8d%e5%99%a8%e7%9a%84%e8%a8%aa%e5%95%8f%e6%8e%a7%e5%88%b6-GhNpuKpTul\">2. \u914d\u7f6e NTP \u4f3a\u670d\u5668\u7684\u8a2a\u554f\u63a7\u5236<\/h3>\n<p>\u5728 NTP \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528 <code>restrict<\/code> \u6307\u4ee4\u4f86\u9650\u5236\u54ea\u4e9b IP \u5730\u5740\u53ef\u4ee5\u8a2a\u554f NTP \u4f3a\u670d\u5668\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>restrict default nomodify notrap nopeer noquery\nrestrict 192.168.1.0 mask 255.255.255.0 nomodify notrap<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-ntp-%e8%ba%ab%e4%bb%bd%e9%a9%97%e8%ad%89-GhNpuKpTul\">3. \u4f7f\u7528 NTP \u8eab\u4efd\u9a57\u8b49<\/h3>\n<p>\u555f\u7528 NTP \u8eab\u4efd\u9a57\u8b49\u53ef\u4ee5\u9632\u6b62\u672a\u7d93\u6388\u6b0a\u7684\u4f3a\u670d\u5668\u5411\u60a8\u7684\u4f3a\u670d\u5668\u767c\u9001\u6642\u9593\u66f4\u65b0\u3002\u60a8\u53ef\u4ee5\u5728 NTP \u914d\u7f6e\u6587\u4ef6\u4e2d\u8a2d\u7f6e\u5bc6\u9470\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\u3002<\/p>\n<pre><code>keys \/etc\/ntp.keys\ntrustedkey 1\nrequestkey 1<\/code><\/pre>\n<h3 id=\"4-%e5%ae%9a%e6%9c%9f%e6%9b%b4%e6%96%b0-ntp-%e8%bb%9f%e4%bb%b6-GhNpuKpTul\">4. \u5b9a\u671f\u66f4\u65b0 NTP \u8edf\u4ef6<\/h3>\n<p>\u4fdd\u6301 NTP \u8edf\u4ef6\u7684\u6700\u65b0\u7248\u672c\u53ef\u4ee5\u4fee\u88dc\u5df2\u77e5\u7684\u5b89\u5168\u6f0f\u6d1e\u3002\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982 <code>apt<\/code> \u6216 <code>yum<\/code>\uff09\u5b9a\u671f\u6aa2\u67e5\u66f4\u65b0\u3002<\/p>\n<h2 id=\"%e7%9b%a3%e6%8e%a7-ntp-%e6%b4%bb%e5%8b%95-GhNpuKpTul\">\u76e3\u63a7 NTP \u6d3b\u52d5<\/h2>\n<p>\u5b9a\u671f\u6aa2\u67e5 NTP \u65e5\u8a8c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u767c\u73fe\u6f5b\u5728\u7684\u5b89\u5168\u554f\u984c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b NTP \u65e5\u8a8c\uff1a<\/p>\n<pre><code>tail -f \/var\/log\/ntp.log<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-GhNpuKpTul\">\u7d50\u8ad6<\/h2>\n<p>\u5728 Linux \u4f3a\u670d\u5668\u7684\u5b89\u5168\u7b56\u7565\u4e2d\uff0c\u4f7f\u7528\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u74b0\u3002\u901a\u904e\u9078\u64c7\u53ef\u4fe1\u7684 NTP \u4f3a\u670d\u5668\u3001\u914d\u7f6e\u8a2a\u554f\u63a7\u5236\u3001\u555f\u7528\u8eab\u4efd\u9a57\u8b49\u4ee5\u53ca\u5b9a\u671f\u66f4\u65b0\u8edf\u4ef6\uff0c\u60a8\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u4f3a\u670d\u5668\u7684\u5b89\u5168\u6027\u3002\u9019\u4e9b\u63aa\u65bd\u4e0d\u50c5\u80fd\u4fdd\u8b77\u60a8\u7684\u6578\u64da\uff0c\u9084\u80fd\u78ba\u4fdd\u696d\u52d9\u7684\u7a69\u5b9a\u904b\u884c\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u548c\u4f3a\u670d\u5668\u5b89\u5168\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Linux \u4f3a\u670d\u5668\u5b89\u5168\u7b56\u7565\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u5b89\u5168\u7684 NTP \u4f3a\u670d\u5668\u4f86\u4fdd\u8b77\u7cfb\u7d71\u6642\u9593\u540c\u6b65\uff0c\u589e\u5f37\u6574\u9ad4\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-44544","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44544","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=44544"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44544\/revisions"}],"predecessor-version":[{"id":44545,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/44544\/revisions\/44545"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=44544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=44544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=44544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}