{"id":536,"date":"2025-10-31T23:42:09","date_gmt":"2025-10-31T15:42:09","guid":{"rendered":"https:\/\/www.anysets.tech\/?p=536"},"modified":"2025-11-01T22:30:56","modified_gmt":"2025-11-01T14:30:56","slug":"%e9%85%8d%e7%bd%ae%e5%86%85%e7%bd%91ntp%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.anysets.tech\/?p=536","title":{"rendered":"\u914d\u7f6e\u5185\u7f51ntp\u670d\u52a1\u5668"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e86\u89e3ntp\u670d\u52a1\u5668<\/h2>\n\n\n\n<p>NTP\uff08Network Time Protocol\uff0c\u7f51\u7edc\u65f6\u95f4\u534f\u8bae\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u5728\u7f51\u7edc\u4e2d\u540c\u6b65\u7cfb\u7edf\u65f6\u95f4\u7684\u534f\u8bae\u3002\u901a\u8fc7 NTP\uff0c\u5c40\u57df\u7f51\u6216\u4e92\u8054\u7f51\u4e2d\u7684\u6240\u6709\u8bbe\u5907\u90fd\u53ef\u4ee5\u4fdd\u6301\u65f6\u95f4\u4e00\u81f4\uff0c\u8fd9\u5bf9\u4e8e\u65e5\u5fd7\u5206\u6790\u3001\u4efb\u52a1\u8c03\u5ea6\u3001\u5b89\u5168\u8ba4\u8bc1\u7b49\u573a\u666f\u81f3\u5173\u91cd\u8981\u3002<\/p>\n\n\n\n<p>\u5728\u5c40\u57df\u7f51\u73af\u5883\u4e2d\uff0c\u901a\u5e38\u4f1a\u8bbe\u7f6e\u4e00\u53f0\u4e3b\u673a\u4f5c\u4e3a NTP \u670d\u52a1\u5668\uff08\u65f6\u95f4\u6e90\uff09\uff0c\u5176\u4ed6\u8bbe\u5907\u4f5c\u4e3a NTP \u5ba2\u6237\u7aef \u4ece\u8be5\u670d\u52a1\u5668\u540c\u6b65\u65f6\u95f4\u3002<br>\u5f53\u670d\u52a1\u5668\u80fd\u8bbf\u95ee\u516c\u7f51\u65f6\uff0c\u5b83\u53ef\u4ee5\u4ece\u4e92\u8054\u7f51\u7684\u4e0a\u7ea7 NTP \u670d\u52a1\u5668\u83b7\u53d6\u6807\u51c6\u65f6\u95f4\uff1b\u5f53\u670d\u52a1\u5668\u5904\u4e8e\u79bb\u7ebf\u6216\u5185\u7f51\u73af\u5883\u4e2d\u65f6\uff0c\u4e5f\u53ef\u4ee5\u5c06\u5176\u81ea\u8eab\u4f5c\u4e3a\u65f6\u95f4\u6e90\uff08\u901a\u8fc7 <code>local stratum<\/code> \u53c2\u6570\uff09\uff0c\u4e3a\u5c40\u57df\u7f51\u5185\u7684\u5176\u4ed6\u8bbe\u5907\u63d0\u4f9b\u65f6\u95f4\u540c\u6b65\u3002<\/p>\n\n\n\n<p>Chrony \u662f\u76ee\u524d Linux \u7cfb\u7edf\u4e2d\u4e3b\u6d41\u7684 NTP \u670d\u52a1\u5b9e\u73b0\u4e4b\u4e00\uff0c\u76f8\u6bd4\u65e7\u7684 <code>ntpd<\/code>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u540c\u6b65\u901f\u5ea6\u66f4\u5feb\u3001\u7cbe\u5ea6\u66f4\u9ad8\uff1b<\/li>\n\n\n\n<li>\u80fd\u81ea\u52a8\u8c03\u6574\u7f51\u7edc\u5ef6\u8fdf\u5bfc\u81f4\u7684\u65f6\u95f4\u504f\u5dee\uff1b<\/li>\n\n\n\n<li>\u65ad\u7f51\u540e\u4ecd\u80fd\u7ef4\u6301\u8f83\u4e3a\u51c6\u786e\u7684\u672c\u5730\u65f6\u949f\uff1b<\/li>\n\n\n\n<li>\u914d\u7f6e\u7b80\u5355\uff0c\u652f\u6301\u52a8\u6001\u7f51\u7edc\u73af\u5883\uff08\u5982\u7b14\u8bb0\u672c\u3001\u865a\u62df\u673a\u7b49\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 <code>chrony<\/code> \u914d\u7f6e\u5c40\u57df\u7f51\u5185\u7684\u65f6\u95f4\u540c\u6b65\u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u914d\u7f6e\u670d\u52a1\u7aef<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\u3001\u5b89\u88c5chrony\u8f6f\u4ef6\u5305<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install chrony -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/h3>\n\n\n\n<p>\u4f7f\u7528<code>sudo vim \/etc\/chrony\/chrony.conf<\/code>\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u6309\u9700\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5141\u8bb8\u8fdb\u884c\u65f6\u95f4\u540c\u6b65\u7684\u7f51\u6bb5\nallow 192.168.3.0\/24\n\n# \u82e5\u4e0d\u9650\u5236\u7f51\u6bb5\uff0c\u53ef\u4ee5\u76f4\u63a5\u5199all\nallow all\n\n# \u8bbe\u7f6e\u672c\u5730\u4e3a\u65f6\u95f4\u540c\u6b65\u6e90\nserver 127.0.0.1 iburst\n\n# \u5982\u679c\u670d\u52a1\u5668\u65e0\u6cd5\u4ece\u516c\u7f51\u540c\u6b65\u65f6\u95f4\uff0c\u6dfb\u52a0\u8be5\u884c\u4ee5\u5141\u8bb8\u5c40\u57df\u7f51\u5176\u4ed6\u8bbe\u5907\u901a\u8fc7\u672c\u670d\u52a1\u5668\u540c\u6b65\u65f6\u95f4\nlocal stratum 10 orphan<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3\u3001\u542f\u7528\u670d\u52a1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable chronyd  # \u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\nsudo systemctl start chronyd  # \u542f\u52a8\u670d\u52a1\n\n# \u5982\u679c\u4e0a\u9762\u7684\u65e0\u6cd5\u6b63\u5e38\u542f\u7528\nsudo systemctl enable chrony\nsudo systemctl start chrony<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4\u3001\uff08\u53ef\u9009\uff09\u653e\u884c\u7aef\u53e3<\/h3>\n\n\n\n<p><code>chrony<\/code>\u670d\u52a1\u9ed8\u8ba4\u8dd1\u5728123\u7aef\u53e3\u4e0a\uff0c\u82e5\u670d\u52a1\u5668\u914d\u7f6e\u6709\u9632\u706b\u5899\uff0c\u8bb0\u5f97\u653e\u884c123\u7aef\u53e3\uff0cudp\u534f\u8bae\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u914d\u7f6e\u5ba2\u6237\u7aef<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\u3001\u5b89\u88c5chrony\u8f6f\u4ef6\u5305<\/h3>\n\n\n\n<p>\u548c\u670d\u52a1\u7aef\u914d\u7f6e\u540c\u6837\u5730\uff0c\u9700\u8981\u5148\u5b89\u88c5chrony<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install chrony -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/h3>\n\n\n\n<p>\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\uff1a<code>sudo vim \/etc\/chrony\/chrony.conf<\/code><\/p>\n\n\n\n<p>\u6ce8\u91ca\u6389\u6240\u6709\u7684pool\u5f00\u5934\u7684\u8bed\u53e5\uff0c\u5e76\u8bbe\u7f6e\u76ee\u6807\u670d\u52a1\u5668\u4e3a\u5c40\u57df\u7f51\u4e2d\u670d\u52a1\u7aef\u7684ip<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#pool ntp.ubuntu.com        iburst maxsources 4\n#pool 0.ubuntu.pool.ntp.org iburst maxsources 1\n#pool 1.ubuntu.pool.ntp.org iburst maxsources 1\n#pool 2.ubuntu.pool.ntp.org iburst maxsources 2\n\nserver 192.168.3.178 iburst  # \u6b64\u5904\u987b\u5c06ip\u6539\u4e3a\u4e0a\u9762\u670d\u52a1\u7aef\u7684ip\u5730\u5740\uff0c\u8fd9\u91cc\u4ee5192.168.3.178\u4e3a\u4f8b<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3\u3001\u542f\u7528\u670d\u52a1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable chronyd  # \u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\nsudo systemctl start chronyd  # \u542f\u52a8\u670d\u52a1\n\n# \u5982\u679c\u4e0a\u9762\u7684\u65e0\u6cd5\u6b63\u5e38\u542f\u7528\nsudo systemctl enable chrony\nsudo systemctl start chrony<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4\u3001\u9a8c\u8bc1\u8fde\u63a5<\/h3>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528chronyc\u9a8c\u8bc1\u662f\u5426\u80fd\u4e0e\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chronyc sources -v<\/code><\/pre>\n\n\n\n<p>\u82e5\u51fa\u73b0\u7c7b\u4f3c\u5982\u4e0b\u7684\u8fd4\u56de\u503c\uff08^*\u5f00\u5934\uff09\uff0c\u5219\u8bf4\u660e\u6210\u529f\u4ece\u670d\u52a1\u5668\u540c\u6b65\u65f6\u95f4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>^* 192.168.3.178<\/code><\/pre>\n\n\n\n<p>\u4e0b\u8868\u662f\u8fd4\u56de\u503c\u72b6\u6001\u7684\u542b\u4e49<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u524d\u7f00<\/th><th>\u542b\u4e49<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>^*<\/code><\/td><td>\u5f53\u524d\u540c\u6b65\u6e90<\/td><td>\u7cfb\u7edf\u6b63\u4f7f\u7528\u6b64\u670d\u52a1\u5668\u4f5c\u4e3a\u4e3b\u65f6\u95f4\u6e90<\/td><\/tr><tr><td><code>^+<\/code><\/td><td>\u5019\u9009\u540c\u6b65\u6e90<\/td><td>\u65f6\u95f4\u6b63\u5e38\u3001\u7a33\u5b9a\uff0c\u4f46\u672a\u88ab\u9009\u4e3a\u4e3b\u6e90<\/td><\/tr><tr><td><code>^-<\/code><\/td><td>\u88ab\u6392\u9664\u7684\u6e90<\/td><td>\u53ef\u80fd\u6f02\u79fb\u8f83\u5927\u6216\u5ef6\u8fdf\u4e0d\u7a33\u5b9a<\/td><\/tr><tr><td><code>^?<\/code><\/td><td>\u4e0d\u53ef\u8fbe\u6e90<\/td><td>\u7f51\u7edc\u4e2d\u65ad\u6216\u5c1a\u672a\u5efa\u7acb\u8054\u7cfb<\/td><\/tr><tr><td><code>^x<\/code><\/td><td>\u9519\u8bef\u6e90<\/td><td>\u88ab\u8bc6\u522b\u4e3a\u63d0\u4f9b\u9519\u8bef\u65f6\u95f4<\/td><\/tr><tr><td><code>^~<\/code><\/td><td>\u6296\u52a8\u6e90<\/td><td>\u65f6\u95f4\u53d8\u5316\u592a\u5927\uff0c\u4e0d\u53ef\u4fe1<\/td><\/tr><tr><td><code>=#<\/code><\/td><td>\u672c\u5730\u65f6\u949f\u6e90<\/td><td>\u4e00\u822c\u7528\u4e8e\u65e0\u5916\u90e8 NTP \u65f6 fallback<\/td><\/tr><tr><td><code>?<\/code>\uff08\u5355\u72ec\uff09<\/td><td>\u672a\u8bc6\u522b<\/td><td>\u8be5\u6e90\u6682\u65f6\u65e0\u72b6\u6001\u6570\u636e<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u82e5\u60f3\u624b\u52a8\u540c\u6b65\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chronyc makestep<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u4e86\u89e3ntp\u670d\u52a1\u5668 NTP\uff08Network Time Protocol\uff0c\u7f51\u7edc\u65f6\u95f4\u534f\u8bae\uff09\u662f\u4e00\u79cd\u7528\u4e8e\u5728\u7f51\u7edc\u4e2d\u540c\u6b65 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-536","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=536"}],"version-history":[{"count":2,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/536\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/536\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}