{"id":219607,"date":"2021-06-02T08:17:58","date_gmt":"2021-06-02T00:17:58","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=219607"},"modified":"2021-05-25T15:18:16","modified_gmt":"2021-05-25T07:18:16","slug":"centos8-chrony-sync-time","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos8-chrony-sync-time.html","title":{"rendered":"Centos8\u4e2d\u5982\u4f55\u4f7f\u7528Chrony\u540c\u6b65\u65f6\u95f4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728Linux\u670d\u52a1\u5668\u4e2d\u5982\u679c\u6211\u4eec\u5e0c\u671b\u6240\u6709Linux\u670d\u52a1\u5668\u90fd\u5177\u6709\u6b63\u786e\u7684\u65f6\u95f4\uff0c\u5219\u5fc5\u987b\u914d\u7f6e\u4e00\u4e9bNTP\u5ba2\u6237\u7aef\uff0c\u8be5\u5ba2\u6237\u7aef\u5c06\u59cb\u7ec8\u4ece\u8fdc\u7a0bNTP\u670d\u52a1\u5668\u83b7\u53d6\u6b63\u786e\u7684\u65f6\u95f4\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5b89\u88c5chrony<\/strong><\/div>\n

\u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5728Centos8\u4e2d\u5b89\u88c5chrony\uff1a<\/p>\n

\r\n[root@server1 ~]# yum -y install chrony\r\n<\/pre>\n

chrony\u5b89\u88c5\u5b8c\u6210\u4e4b\u540e\uff0c\u4f1a\u6709\u4e24\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\uff1a<\/p>\n

    \n
  • chronyc<\/code>: chrony\u547d\u4ee4\u884c\u5de5\u5177<\/li>\n
  • chronyd<\/code>: chrony\u7684\u5b88\u62a4\u8fdb\u7a0b<\/li>\n<\/ul>\n
    Chrony\u7684\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n

    Chrony\u7684\u914d\u7f6e\u6587\u4ef6\u662f\/etc\/chrony.conf<\/code>\uff0c\u4e0b\u9762\u5217\u51fa\u4e86\u793a\u4f8bchrony.conf\u6587\u4ef6\uff1a<\/p>\n

    \r\n[root@server1 ~]# cat \/etc\/chrony.conf \r\n<\/pre>\n

    \"\"<\/p>\n

    pool 2.centos.pool.ntp.org iburst<\/code> chrony\u5c06\u4ece\u4e2d\u83b7\u53d6\u65f6\u95f4\u7684\u8fdc\u7a0bNTP\u670d\u52a1\u5668\u3002<\/p>\n

    driftfile \/var\/lib\/chrony\/drift<\/code> \u7cfb\u7edf\u65f6\u949f\u9891\u7387\u90fd\u6709\u5c0f\u5c0f\u7684\u8bef\u5dee\uff0c\u8fd9\u4e2a\u5c31\u662f\u4e3a\u4ec0\u4e48\u8ba1\u7b97\u673a\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\u65f6\u95f4\u4f1a\u4e0d\u7cbe\u786e\u3002NTP\u4f1a\u81ea\u52a8\u6765\u76d1\u6d4b\u6211\u4eec\u65f6\u949f\u7684\u8bef\u5dee\u503c\u5e76\u4e88\u4ee5\u8c03\u6574\uff0c\u6240\u4ee5\u5b83\u4f1a\u628a\u8bb0\u5f55\u4e0b\u6765\u7684\u8bef\u5dee\u5148\u5199\u5165driftfile\uff0c\u91cd\u65b0\u542f\u52a8\u7cfb\u7edf\u540e\uff0c\u4e4b\u524d\u7684\u8ba1\u7b97\u7ed3\u679c\u4e5f\u5c31\u4e0d\u4f1a\u4e22\u5931\u4e86\u3002<\/p>\n

    keyfile \/etc\/chrony.keys<\/code> \u8be5\u6587\u4ef6\u5305\u542b\u7528\u4e8eNTP\u8eab\u4efd\u9a8c\u8bc1\u7684\u5bc6\u94a5\u3002<\/p>\n

    logdir \/var\/log\/chrony<\/code> \u5b83\u662f\u8bb0\u5f55Chrony\u7684\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

    \u6d4b\u8bd5chrony<\/strong><\/div>\n

    \u5c31\u50cfntpdate<\/code>\u547d\u4ee4\u4e00\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528chronyd\u624b\u52a8\u5c06Linux\u670d\u52a1\u5668\u7684\u65f6\u95f4\u4e0e\u8fdc\u7a0bNTP\u670d\u52a1\u5668\u8fdb\u884c\u540c\u6b65\u3002<\/p>\n

    \u8bed\u6cd5\uff1a<\/p>\n

    \r\nchronyd -q \u2018server {ntp_server_name} iburst\u2019\r\n<\/pre>\n

    \u4e0b\u9762\u4f7f\u7528\u5b9e\u4f8b\uff1a<\/p>\n

    \r\n[root@server1 ~]# chronyd -q 'server s1a.time.edu.cn iburst'\r\n2021-05-25T01:59:38Z chronyd version 3.5 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)\r\n2021-05-25T01:59:38Z Initial frequency -4.035 ppm\r\n2021-05-25T01:59:42Z System clock wrong by -0.006248 seconds (step)\r\n2021-05-25T01:59:42Z chronyd exiting\r\n<\/pre>\n

    \"\"
    \n\u4ece\u4e0a\u9762\u7684\u8f93\u51fa\u4e2d\u53ef\u4ee5\u770b\u5230\uff0cchrony\u5df2\u6821\u6b63\u4e86\u7cfb\u7edf\u65f6\u95f4\u3002<\/p>\n

    Start\u548cEnable chronyd\u670d\u52a1<\/strong><\/div>\n

    \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u542f\u7528chronyd\u670d\u52a1\uff1a<\/p>\n

    \r\n[root@server1 ~]# systemctl enable chronyd\r\n[root@server1 ~]# systemctl start chronyd\r\n<\/pre>\n

    \u8fd0\u884c\u4e0b\u9762\u547d\u4ee4\u67e5\u770bchronyd\u7684\u670d\u52a1\u72b6\u6001\uff1a<\/p>\n

    \r\n[root@server1 ~]# systemctl status chronyd\r\n<\/pre>\n

    \"\"<\/p>\n

    \u9a8c\u8bc1chrony\u7684\u540c\u6b65<\/strong><\/div>\n

    \u8981\u9a8c\u8bc1\u7cfb\u7edf\u65f6\u95f4\u662f\u5426\u5df2\u4f7f\u7528chrony\u540c\u6b65\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n

    \r\n[root@server1 ~]# chronyc tracking \r\nReference ID    : 4E2E66B4 (electrode.felixc.at)\r\nStratum         : 4\r\nRef time (UTC)  : Tue May 25 02:04:47 2021\r\nSystem time     : 0.000002501 seconds slow of NTP time\r\nLast offset     : +0.016273908 seconds\r\nRMS offset      : 0.016273908 seconds\r\nFrequency       : 98.064 ppm fast\r\nResidual freq   : +1.774 ppm\r\nSkew            : 155.311 ppm\r\nRoot delay      : 0.227135062 seconds\r\nRoot dispersion : 0.028634518 seconds\r\nUpdate interval : 64.4 seconds\r\nLeap status     : Normal\r\n<\/pre>\n

    Reference ID<\/code> \u662f\u7cfb\u7edf\u65f6\u95f4\u5f53\u524d\u540c\u6b65\u5230\u7684\u670d\u52a1\u5668\u7684ID\u548c\u540d\u79f0\u3002<\/p>\n

    \u68c0\u67e5chrony\u6765\u6e90<\/strong><\/div>\n

    \u8981\u5217\u51fa\u6709\u5173chronyd\u4f7f\u7528\u7684\u5f53\u524d\u65f6\u95f4\u6e90\u7684\u4fe1\u606f\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

    \r\n[root@server1 ~]# chronyc sources\r\n210 Number of sources = 4\r\nMS Name\/IP address         Stratum Poll Reach LastRx Last sample               \r\n===============================================================================\r\n^- electrode.felixc.at           3   6   377    29    -14ms[  -14ms] +\/-  137ms\r\n^- ntp7.flashdance.cx            2   6   377    91  +2336us[+2505us] +\/-  174ms\r\n^? ntp8.flashdance.cx            0   6     0     -     +0ns[   +0ns] +\/-    0ns\r\n^* 111.230.189.174               2   6   377    28   +423us[ +648us] +\/-   50ms\r\n<\/pre>\n

    \"\"
    \n\u8981\u5217\u51fa\u6709\u5173chronyd\u4f7f\u7528\u7684\u6bcf\u4e2a\u6e90\u7684\u6f02\u79fb\u901f\u5ea6\u548c\u504f\u79fb\u4f30\u8ba1\u7684\u4fe1\u606f\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

    \r\n[root@server1 ~]# chronyc sourcestats  -v\r\n210 Number of sources = 4\r\n                             .- Number of sample points in measurement set.\r\n                            \/    .- Number of residual runs with same sign.\r\n                           |    \/    .- Length of measurement set (time).\r\n                           |   |    \/      .- Est. clock freq error (ppm).\r\n                           |   |   |      \/           .- Est. error in freq.\r\n                           |   |   |     |           \/         .- Est. offset.\r\n                           |   |   |     |          |          |   On the -.\r\n                           |   |   |     |          |          |   samples. \\\r\n                           |   |   |     |          |          |             |\r\nName\/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev\r\n==============================================================================\r\nelectrode.felixc.at        12   5   527     -2.019     22.417    -13ms  2921us\r\nntp7.flashdance.cx         10   5   397     +1.957     29.018  +2410us  2684us\r\nntp8.flashdance.cx          0   0     0     +0.000   2000.000     +0ns  4000ms\r\n111.230.189.174            12   9   527     -0.001     10.537    -60ns  1360us\r\n<\/pre>\n

    \"\"<\/p>\n

    \u914d\u7f6eChrony NTP\u670d\u52a1<\/strong><\/div>\n

    \u5982\u679c\u4f60\u8981\u5c06Linux\u670d\u52a1\u5668\u914d\u7f6e\u4e3a\u6240\u6709\u5185\u90e8\u7cfb\u7edf\u7684Chrony NTP\u670d\u52a1\u5668\u3002\u6211\u4eec\u9700\u8981\u5728\/etc\/chrony.conf<\/code>\u914d\u7f6e\u6587\u4ef6\u4e2d\u7a0d\u4f5c\u4fee\u6539\uff1a<\/p>\n

    \r\n[root@server1 ~]# sed -i \"s\/#local stratum 10\/local stratum 10\/g\" \/etc\/chrony.conf\r\n[root@server1 ~]# sed -i \"s\/#allow 192.168.0.0\\\/16\/allow 192.168.0.0\\\/16\/\" \/etc\/chrony.conf\r\n<\/pre>\n

    \"\"
    \n\u5f53\u6211\u4eec\u53d6\u6d88\u6ce8\u91calocal stratum 10<\/code>\u884c\u65f6\uff0c\u5219\u4f7f\u6211\u4eec\u7684Linux\u670d\u52a1\u5668\u6210\u4e3a\u5b9e\u65f6NTP\u670d\u52a1\u5668\uff0c\u5373\u4f7f\u5b83\u4e0e\u7f51\u7edc\u65ad\u5f00\u8fde\u63a5\u4e5f\u53ef\u4ee5\u7ee7\u7eed\u6b63\u5e38\u5de5\u4f5c\u3002\u800callow 192.168.0.0\/26<\/code>\u8868\u793a\u5141\u8bb8\u8be5\u7f51\u6bb5\u7684\u8bbe\u5907\u8fde\u63a5\u5230\u6211\u4eec\u7684Chrony NTP\u670d\u52a1\u5668\u4ee5\u8fdb\u884c\u65f6\u95f4\u540c\u6b65\u3002<\/p>\n

    \u66f4\u6539\u540e\uff0c\u91cd\u542fchrony\u670d\u52a1\u5e76\u8ddf\u8e2achrony\uff1a<\/p>\n

    \r\n[root@server1 ~]# systemctl restart chronyd ; watch chronyc tracking\r\n<\/pre>\n

    \"\"
    \n\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728\u9632\u706b\u5899\u4e2d\u5141\u8bb8NTP\u670d\u52a1\uff1a<\/p>\n

    \r\n[root@server1 ~]# firewall-cmd --permanent --add-service=ntp\r\nsuccess\r\n[root@server1 ~]# firewall-cmd --reload\r\nsuccess\r\n<\/pre>\n

    \"\"<\/p>\n

    \u603b\u7ed3<\/strong><\/div>\n

    \u8fd9\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u4f60\u80fd\u4e86\u89e3\u5982\u4f55\u4f7f\u7528chrony\u670d\u52a1\u5c06Linux\u7684\u65f6\u95f4\u4e0eNTP\u670d\u52a1\u5668\u540c\u6b65\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u4f7f\u7528\u4e0b\u9762\u547d\u4ee4\u5728Centos8\u4e2d\u5b89\u88c5chrony\uff1a [root@server1 ~]# yum -y insta […]<\/p>\n","protected":false},"author":309,"featured_media":219608,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-219607","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219607","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\/309"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=219607"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219607\/revisions"}],"predecessor-version":[{"id":219617,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/219607\/revisions\/219617"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/219608"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=219607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=219607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=219607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}