{"id":147350,"date":"2019-06-16T08:43:54","date_gmt":"2019-06-16T00:43:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=147350"},"modified":"2019-06-10T20:45:38","modified_gmt":"2019-06-10T12:45:38","slug":"linux-ntp","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-ntp.html","title":{"rendered":"\u5728 Linux \u4e0b\u786e\u8ba4 NTP \u662f\u5426\u540c\u6b65\u7684\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nNTP \u610f\u5373\u7f51\u7edc\u65f6\u95f4\u534f\u8baeNetwork Time Protocol\uff0c\u5b83\u901a\u8fc7\u7f51\u7edc\u540c\u6b65\u8ba1\u7b97\u673a\u7cfb\u7edf\u4e4b\u95f4\u7684\u65f6\u949f\u3002NTP \u670d\u52a1\u5668\u53ef\u4ee5\u4f7f\u7ec4\u7ec7\u4e2d\u7684\u6240\u6709\u670d\u52a1\u5668\u4fdd\u6301\u540c\u6b65\uff0c\u4ee5\u51c6\u786e\u65f6\u95f4\u6267\u884c\u57fa\u4e8e\u65f6\u95f4\u7684\u4f5c\u4e1a\u3002NTP \u5ba2\u6237\u7aef\u4f1a\u5c06\u5176\u65f6\u949f\u4e0e NTP \u670d\u52a1\u5668\u540c\u6b65\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Linux \u4e2d\u6709\u4e09\u4e2a\u547d\u4ee4\u53ef\u7528\u4e8e\u9a8c\u8bc1 NTP \u540c\u6b65\u60c5\u51b5\u3002\u8be6\u60c5\u5982\u4e0b\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u544a\u8bc9\u60a8\u5982\u4f55\u4f7f\u7528\u6240\u6709\u8fd9\u4e9b\u547d\u4ee4\u9a8c\u8bc1 NTP \u540c\u6b65\u3002<\/p>\n

ntpq<\/span>\uff1antpq \u662f\u4e00\u4e2a\u6807\u51c6\u7684 NTP \u67e5\u8be2\u7a0b\u5e8f\u3002
\nntpstat<\/span>\uff1a\u663e\u793a\u7f51\u7edc\u4e16\u754c\u540c\u6b65\u72b6\u6001\u3002
\ntimedatectl<\/span>\uff1a\u5b83\u63a7\u5236 systemd \u7cfb\u7edf\u4e2d\u7684\u7cfb\u7edf\u65f6\u95f4\u548c\u65e5\u671f\u3002<\/p>\n

\u65b9\u6cd5 1\uff1a\u5982\u4f55\u4f7f\u7528 ntpq \u547d\u4ee4\u68c0\u67e5 NTP \u72b6\u6001\uff1f<\/strong><\/div>\n

ntpq<\/span> \u5b9e\u7528\u7a0b\u5e8f\u7528\u4e8e\u76d1\u89c6 NTP \u5b88\u62a4\u7a0b\u5e8f ntpd<\/span> \u7684\u64cd\u4f5c\u5e76\u786e\u5b9a\u6027\u80fd\u3002<\/p>\n

\u8be5\u7a0b\u5e8f\u53ef\u4ee5\u4ee5\u4ea4\u4e92\u6a21\u5f0f\u8fd0\u884c\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u53c2\u6570\u8fdb\u884c\u63a7\u5236\u3002\u5b83\u901a\u8fc7\u5411\u670d\u52a1\u5668\u53d1\u9001\u591a\u4e2a\u67e5\u8be2\u6765\u6253\u5370\u51fa\u8fde\u63a5\u7684\u5bf9\u7b49\u9879\u5217\u8868\u3002\u5982\u679c NTP \u6b63\u5e38\u5de5\u4f5c\uff0c\u4f60\u5c06\u83b7\u5f97\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u7684\u8f93\u51fa\u3002<\/p>\n

# ntpq -p\r\n     remote           refid      st t when poll reach   delay   offset  jitter\r\n==============================================================================\r\n*CentOS7.2daygee 133.243.238.163  2 u   14   64   37    0.686    0.151  16.432<\/pre>\n

\u7ec6\u8282\uff1a<\/p>\n

-p<\/span>\uff1a\u6253\u5370\u670d\u52a1\u5668\u5df2\u77e5\u7684\u5bf9\u7b49\u9879\u5217\u8868\u4ee5\u53ca\u5176\u72b6\u6001\u6458\u8981\u3002<\/p>\n

\u65b9\u6cd5 2\uff1a\u5982\u4f55\u4f7f\u7528 ntpstat \u547d\u4ee4\u68c0\u67e5 NTP \u72b6\u6001\uff1f<\/strong><\/div>\n

ntpstat<\/span> \u5c06\u62a5\u544a\u5728\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u7684 NTP \u5b88\u62a4\u7a0b\u5e8f\uff08ntpd<\/span>\uff09\u7684\u540c\u6b65\u72b6\u6001\u3002\u5982\u679c\u53d1\u73b0\u672c\u5730\u7cfb\u7edf\u4e0e\u53c2\u8003\u65f6\u95f4\u6e90\u4fdd\u6301\u540c\u6b65\uff0c\u5219 ntpstat<\/span> \u5c06\u62a5\u544a\u5927\u81f4\u7684\u65f6\u95f4\u7cbe\u5ea6\u3002
\nntpstat<\/span> \u547d\u4ee4\u6839\u636e NTP \u540c\u6b65\u72b6\u6001\u8fd4\u56de\u4e09\u79cd\u72b6\u6001\u7801\u3002\u8be6\u60c5\u5982\u4e0b\u3002
\n0<\/span>\uff1a\u5982\u679c\u65f6\u949f\u540c\u6b65\u5219\u8fd4\u56de 0\u3002
\n1<\/span>\uff1a\u5982\u679c\u65f6\u949f\u4e0d\u540c\u6b65\u5219\u8fd4\u56de 1\u3002
\n2<\/span>\uff1a\u5982\u679c\u65f6\u949f\u72b6\u6001\u4e0d\u786e\u5b9a\uff0c\u5219\u8fd4\u56de 2\uff0c\u4f8b\u5982 ntpd \u4e0d\u53ef\u8054\u7cfb\u65f6\u3002<\/p>\n

# ntpstat\r\nsynchronised to NTP server (192.168.1.8) at stratum 3\r\n   time correct to within 508 ms\r\n   polling server every 64 s<\/pre>\n
\u65b9\u6cd5 3\uff1a\u5982\u4f55\u4f7f\u7528 timedatectl \u547d\u4ee4\u68c0\u67e5 NTP \u72b6\u6001\uff1f<\/strong><\/div>\n

timedatectl<\/span> \u547d\u4ee4\u7528\u4e8e\u67e5\u8be2\u548c\u66f4\u6539\u7cfb\u7edf\u65f6\u949f\u53ca\u5176\u5728 systmed \u7cfb\u7edf\u4e2d\u7684\u8bbe\u7f6e\u3002<\/p>\n

# timedatectl\r\n\u6216\r\n# timedatectl status\r\n      Local time: Thu 2019-05-30 05:01:05 CDT\r\n  Universal time: Thu 2019-05-30 10:01:05 UTC\r\n        RTC time: Thu 2019-05-30 10:01:05\r\n       Time zone: America\/Chicago (CDT, -0500)\r\n     NTP enabled: yes\r\nNTP synchronized: yes\r\n RTC in local TZ: no\r\n      DST active: yes\r\n Last DST change: DST began at\r\n                  Sun 2019-03-10 01:59:59 CST\r\n                  Sun 2019-03-10 03:00:00 CDT\r\n Next DST change: DST ends (the clock jumps one hour backwards) at\r\n                  Sun 2019-11-03 01:59:59 CDT\r\n                  Sun 2019-11-03 01:00:00 CST<\/pre>\n
\u66f4\u591a\u6280\u5de7<\/strong><\/div>\n

Chrony \u662f\u4e00\u4e2a NTP \u5ba2\u6237\u7aef\u7684\u66ff\u4ee3\u54c1\u3002\u5b83\u53ef\u4ee5\u66f4\u5feb\u5730\u540c\u6b65\u7cfb\u7edf\u65f6\u949f\uff0c\u65f6\u95f4\u7cbe\u5ea6\u66f4\u9ad8\uff0c\u5bf9\u4e8e\u4e00\u76f4\u4e0d\u5728\u7ebf\u7684\u7cfb\u7edf\u5c24\u5176\u6709\u7528\u3002<\/p>\n

chronyd \u8f83\u5c0f\uff0c\u5b83\u4f7f\u7528\u8f83\u5c11\u7684\u5185\u5b58\uff0c\u53ea\u5728\u5fc5\u8981\u65f6\u624d\u5524\u9192 CPU\uff0c\u8fd9\u6837\u53ef\u4ee5\u66f4\u597d\u5730\u8282\u7701\u7535\u80fd\u3002\u5373\u4f7f\u7f51\u7edc\u62e5\u585e\u8f83\u957f\u65f6\u95f4\uff0c\u5b83\u4e5f\u80fd\u5f88\u597d\u5730\u8fd0\u884c\u3002<\/p>\n

\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4efb\u4f55\u547d\u4ee4\u6765\u68c0\u67e5 Chrony \u72b6\u6001\u3002<\/p>\n

\u68c0\u67e5 Chrony \u8ddf\u8e2a\u72b6\u6001\u3002<\/p>\n

# chronyc tracking\r\nReference ID    : C0A80105 (CentOS7.2daygeek.com)\r\nStratum         : 3\r\nRef time (UTC)  : Thu Mar 28 05:57:27 2019\r\nSystem time     : 0.000002545 seconds slow of NTP time\r\nLast offset     : +0.001194361 seconds\r\nRMS offset      : 0.001194361 seconds\r\nFrequency       : 1.650 ppm fast\r\nResidual freq   : +184.101 ppm\r\nSkew            : 2.962 ppm\r\nRoot delay      : 0.107966967 seconds\r\nRoot dispersion : 1.060455322 seconds\r\nUpdate interval : 2.0 seconds\r\nLeap status     : Normal<\/pre>\n

\u8fd0\u884csources<\/span> \u547d\u4ee4\u4ee5\u663e\u793a\u6709\u5173\u5f53\u524d\u65f6\u95f4\u6e90\u7684\u4fe1\u606f\u3002<\/p>\n

# chronyc sources\r\n210 Number of sources = 1\r\nMS Name\/IP address         Stratum Poll Reach LastRx Last sample\r\n===============================================================================\r\n^* CentOS7.2daygeek.com          2   6    17    62    +36us[+1230us] +\/- 1111ms<\/pre>\n

via: https:\/\/www.2daygeek.com\/check-verify-ntp-sync-is-working-or-not-in-linux-using-ntpq-ntpstat-timedatectl\/<\/p>\n

\u4f5c\u8005\uff1aMagesh Maruthamuthu \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1awxy \u6821\u5bf9\uff1a\u6821\u5bf9\u8005ID<\/p>\n

\u672c\u6587\u7531 LCTT \u539f\u521b\u7f16\u8bd1\uff0cLinux\u4e2d\u56fd \u8363\u8a89\u63a8\u51fa<\/p>\n","protected":false},"excerpt":{"rendered":"

Linux \u4e2d\u6709\u4e09\u4e2a\u547d\u4ee4\u53ef\u7528\u4e8e\u9a8c\u8bc1 NTP \u540c\u6b65\u60c5\u51b5\u3002\u8be6\u60c5\u5982\u4e0b\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u544a\u8bc9\u60a8\u5982\u4f55\u4f7f\u7528\u6240\u6709\u8fd9\u4e9b\u547d\u4ee4\u9a8c\u8bc1 […]<\/p>\n","protected":false},"author":63,"featured_media":147351,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-147350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/147350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=147350"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/147350\/revisions"}],"predecessor-version":[{"id":147356,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/147350\/revisions\/147356"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/147351"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=147350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=147350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=147350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}