配置NTP服务
Last updated
2023-01-28 10:38:59
{"value":"### Linux \u5b9e\u4f8b\uff1a\u914d\u7f6e NTP \u670d\u52a1\n\n#### \u64cd\u4f5c\u573a\u666f\n\n\tntpd\uff08Network Time Protocol daemon\uff09\u662f Linux \u64cd\u4f5c\u7cfb\u7edf\u7684\u4e00\u4e2a\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7528\u4e8e\u6821\u6b63\u672c\u5730\u7cfb\u7edf\u4e0e\u65f6\u949f\u6e90\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u65f6\u95f4\uff0c\u5b8c\u6574\u7684\u5b9e\u73b0\u4e86 NTP \u534f\u8bae\u3002ntpd \u4e0e ntpdate \u7684\u533a\u522b\u662f ntpd \u662f\u6b65\u8fdb\u5f0f\u7684\u9010\u6e10\u6821\u6b63\u65f6\u95f4\uff0c\u4e0d\u4f1a\u51fa\u73b0\u65f6\u95f4\u8df3\u53d8\uff0c\u800c ntpdate \u662f\u65ad\u70b9\u66f4\u65b0\u3002\u672c\u6587\u6863\u4ee5 CentOS 7.5 \u64cd\u4f5c\u7cfb\u7edf\u4e91\u670d\u52a1\u5668\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u5b89\u88c5\u548c\u914d\u7f6e ntpd\u3002\n\n#### \u6ce8\u610f\u4e8b\u9879\n\n\u90e8\u5206\u64cd\u4f5c\u7cfb\u7edf\u91c7\u7528 chrony \u4f5c\u4e3a\u9ed8\u8ba4 NTP \u670d\u52a1\uff0c\u8bf7\u786e\u8ba4 ntpd \u6b63\u5728\u8fd0\u884c\u5e76\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u52a8\u3002\n\uf06c\u4f7f\u7528\u00a0systemctl is-active ntpd.service\u00a0\u547d\u4ee4\uff0c\u53ef\u67e5\u770b ntpd \u662f\u5426\u6b63\u5728\u8fd0\u884c\u3002\n\uf06c\u4f7f\u7528\u00a0systemctl is-enabled ntpd.service\u00a0\u547d\u4ee4\uff0c\u53ef\u67e5\u770b ntpd \u662f\u5426\u5f00\u673a\u81ea\u542f\u52a8\u3002\nNTP \u670d\u52a1\u7684\u901a\u4fe1\u7aef\u53e3\u4e3a UDP 123\uff0c\u8bbe\u7f6e NTP \u670d\u52a1\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u7ecf\u5f00\u653e UDP 123 \u7aef\u53e3\u3002\n\n#### \u64cd\u4f5c\u6b65\u9aa4\n\n**\u5b89\u88c5 ntpd**\n\n\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5224\u65ad\u662f\u5426\u5b89\u88c5 ntpd\u3002\n\n\trpm -qa | grep ntp\n\n\u5982\u679c\u8fd4\u56de\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u679c\uff0c\u8868\u793a\u5df2\u5b89\u88c5 ntpd\u3002\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F1.png)\n\n\u5982\u679c\u672a\u5b89\u88c5 ntpd\uff0c\u8bf7\u4f7f\u7528\u00a0yum install ntp\u00a0\u5b89\u88c5 ntpd\u3002\n\n\tyum -y install ntp\n\nntpd \u9ed8\u8ba4\u4e3a\u5ba2\u6237\u7aef\u8fd0\u884c\u65b9\u5f0f\u3002\n\n**\u914d\u7f6e NTP**\n\n1.\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6253\u5f00 NTP \u670d\u52a1\u914d\u7f6e\u6587\u4ef6\u3002\n\n\tvi \/etc\/ntp.conf\n\n2.\u6309\u00a0i\u00a0\u5207\u6362\u81f3\u7f16\u8f91\u6a21\u5f0f\uff0c\u627e\u5230 server \u76f8\u5173\u914d\u7f6e\uff0c\u5c06 server \u4fee\u6539\u4e3a\u60a8\u9700\u8981\u8bbe\u7f6e\u7684\u76ee\u6807 NTP \u65f6\u949f\u6e90\u670d\u52a1\u5668\uff08\u4f8b\u5982\u00a0time1.tencentyun.com\uff09\uff0c\u5e76\u5220\u9664\u6682\u65f6\u4e0d\u9700\u8981\u7684 NTP \u65f6\u949f\u6e90\u670d\u52a1\u5668\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F2.png)\n\n3.\u6309\u00a0Esc\uff0c\u8f93\u5165\u00a0:wq\uff0c\u4fdd\u5b58\u6587\u4ef6\u5e76\u8fd4\u56de\u3002\n\n**\u542f\u52a8 ntpd\uff0c\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8**\n\n\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u91cd\u542f ntpd \u670d\u52a1\u3002\n\n\tsystemctl restart ntpd.service\n\tsystemctl enable ntpd.service\n\n**\u68c0\u67e5 ntpd \u72b6\u6001**\n\n\u6839\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u6267\u884c\u4ee5\u4e0b\u4e0d\u540c\u7684\u547d\u4ee4\uff0c\u68c0\u67e5 ntpd \u7684\u72b6\u6001\u3002\n\n\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b NTP \u670d\u52a1\u7aef\u53e3 UDP 123 \u7aef\u53e3\u662f\u5426\u88ab\u6b63\u5e38\u76d1\u542c\u3002\n\n\tnetstat -nupl\n\n\u8fd4\u56de\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u679c\uff0c\u8868\u793a\u76d1\u542c\u6b63\u5e38\u3002\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F3.png)\n\n\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b ntpd \u72b6\u6001\u662f\u5426\u6b63\u5e38\u3002\n\n\tservice ntpd status\n\n\u8fd4\u56de\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u679c\uff0c\u8868\u793a ntpd \u72b6\u6001\u6b63\u5e38\u3002\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F4.png)\n\n\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u83b7\u53d6\u66f4\u8be6\u7ec6\u7684 NTP \u670d\u52a1\u4fe1\u606f\u3002\n\n\tntpq -p\n\n\u8fd4\u56de\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u679c\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F5.png)\n\n*\u00a0: \u8868\u793a\u76ee\u524d\u4f7f\u7528\u7684 NTP \u670d\u52a1\u5668\u3002\nremote\uff1a\u54cd\u5e94\u8fd9\u4e2a\u8bf7\u6c42\u7684 NTP \u670d\u52a1\u5668\u7684\u540d\u79f0\u3002\nrefid\uff1aNTP \u670d\u52a1\u5668\u4f7f\u7528\u7684\u4e0a\u4e00\u7ea7 NTP \u670d\u52a1\u5668\u3002\nst\uff1aremote \u8fdc\u7a0b\u670d\u52a1\u5668\u7684\u7ea7\u522b\u3002\u670d\u52a1\u5668\u4ece\u9ad8\u5230\u4f4e\u7ea7\u522b\u8bbe\u5b9a\u4e3a1 - 16\uff0c\u4e3a\u4e86\u51cf\u7f13\u8d1f\u8377\u548c\u7f51\u7edc\u5835\u585e\uff0c\u539f\u5219\u4e0a\u5efa\u8bae\u907f\u514d\u76f4\u63a5\u8fde\u63a5\u5230\u7ea7\u522b\u4e3a1\u7684\u670d\u52a1\u5668\u3002\nwhen\uff1a\u4e0a\u4e00\u6b21\u6210\u529f\u8bf7\u6c42\u4e4b\u540e\u5230\u73b0\u5728\u7684\u79d2\u6570\u3002\npoll\uff1a\u672c\u5730\u673a\u548c\u8fdc\u7a0b\u670d\u52a1\u5668\u591a\u5c11\u65f6\u95f4\u8fdb\u884c\u4e00\u6b21\u540c\u6b65\uff08\u5355\u4f4d\u4e3a\u79d2\uff09\u3002\u521d\u59cb\u8fd0\u884c NTP \u65f6\uff0cpoll \u503c\u4f1a\u6bd4\u8f83\u5c0f\uff0c\u548c\u670d\u52a1\u5668\u540c\u6b65\u7684\u9891\u7387\u589e\u52a0\uff0c\u5efa\u8bae\u5c3d\u5feb\u8c03\u6574\u5230\u6b63\u786e\u7684\u65f6\u95f4\u8303\u56f4\u3002\u8c03\u6574\u4e4b\u540e\uff0cpoll \u503c\u4f1a\u9010\u6e10\u589e\u5927\uff0c\u540c\u6b65\u7684\u9891\u7387\u4e5f\u5c06\u4f1a\u76f8\u5e94\u51cf\u5c0f\u3002\nreach\uff1a\u516b\u8fdb\u5236\u503c\uff0c\u7528\u6765\u6d4b\u8bd5\u80fd\u5426\u548c\u670d\u52a1\u5668\u8fde\u63a5\u3002\u6bcf\u6210\u529f\u8fde\u63a5\u4e00\u6b21\uff0creach \u7684\u503c\u5c06\u4f1a\u589e\u52a0\u3002\ndelay\uff1a\u4ece\u672c\u5730\u673a\u53d1\u9001\u540c\u6b65\u8981\u6c42\u5230 NTP \u670d\u52a1\u5668\u7684 round trip time\u3002\noffset\uff1a\u4e3b\u673a\u901a\u8fc7 NTP \u65f6\u949f\u540c\u6b65\u4e0e\u6240\u540c\u6b65\u65f6\u95f4\u6e90\u7684\u65f6\u95f4\u504f\u79fb\u91cf\uff0c\u5355\u4f4d\u4e3a\u6beb\u79d2\uff08ms\uff09\u3002offset \u8d8a\u63a5\u8fd1\u4e8e0\uff0c\u4e3b\u673a\u548c NTP \u670d\u52a1\u5668\u7684\u65f6\u95f4\u8d8a\u63a5\u8fd1\u3002\njitter\uff1a\u7528\u6765\u505a\u7edf\u8ba1\u7684\u503c\u3002\u7edf\u8ba1\u5728\u7279\u5b9a\u8fde\u7eed\u7684\u8fde\u63a5\u6570\u91cc offset \u7684\u5206\u5e03\u60c5\u51b5\u3002\u5373 jitter \u6570\u503c\u7684\u7edd\u5bf9\u503c\u8d8a\u5c0f\uff0c\u4e3b\u673a\u7684\u65f6\u95f4\u5c31\u8d8a\u7cbe\u786e\u3002\n\n### Windows \u5b9e\u4f8b\uff1a\u914d\u7f6e NTP \u670d\u52a1\n\n#### \u64cd\u4f5c\u573a\u666f\n\n\tWindows \u65f6\u95f4\u670d\u52a1\uff08Windows Time service\uff0cW32Time\uff09\u7528\u4e8e\u672c\u5730\u7cfb\u7edf\u4e0e\u65f6\u949f\u6e90\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u65f6\u95f4\u540c\u6b65\uff0c\u4f7f\u7528\u7f51\u7edc\u65f6\u95f4\u534f\u8bae\uff08NTP\uff09\u6765\u540c\u6b65\u7f51\u7edc\u4e0a\u7684\u8ba1\u7b97\u673a\u65f6\u949f\u3002\u672c\u6587\u6863\u4ee5 Windows Server 2012 \u64cd\u4f5c\u7cfb\u7edf\u4e91\u670d\u52a1\u5668\u4e3a\u4f8b\uff0c\u4ecb\u7ecd\u5982\u4f55\u5f00\u542f NTP \u670d\u52a1\u548c\u4fee\u6539\u65f6\u949f\u6e90\u670d\u52a1\u5668\u5730\u5740\u3002\n\n#### \u64cd\u4f5c\u6b65\u9aa4\n\n1.\u767b\u5f55 Windows \u4e91\u670d\u52a1\u5668\u3002\n2.\u5728\u64cd\u4f5c\u7cfb\u7edf\u754c\u9762\uff0c\u5355\u51fb\u00a0\u00a0>\u00a0\u7ba1\u7406\u5de5\u5177\u00a0>\u00a0\u670d\u52a1\uff0c\u6253\u5f00\u670d\u52a1\u7a97\u53e3\u3002\n3.\u5728\u201c\u670d\u52a1\u201d\u7a97\u53e3\u4e2d\uff0c\u53cc\u51fb\u6253\u5f00\u00a0Windows Time\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F6.png)\n\n4.\u5728\u6253\u5f00\u7684 \u201cWindows Time \u7684\u5c5e\u6027(\u672c\u5730\u8ba1\u7b97\u673a)\u201d \u7a97\u53e3\u4e2d\uff0c\u5c06\u201c\u542f\u52a8\u7c7b\u578b\u201d\u8bbe\u7f6e\u4e3a\u81ea\u52a8\uff0c\u5c06\u201c\u670d\u52a1\u72b6\u6001\u201d\u8bbe\u7f6e\u4e3a\u542f\u52a8\uff0c\u5e76\u5355\u51fb\u786e\u5b9a\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F7.png)\n\n5.\u5728\u64cd\u4f5c\u7cfb\u7edf\u754c\u9762\u7684\u4efb\u52a1\u680f\u4e2d\uff0c\u5355\u51fb\u53f3\u4e0b\u89d2\u7684\u65f6\u95f4 >\u00a0\u66f4\u6539\u65e5\u671f\u548c\u65f6\u95f4\u8bbe\u7f6e\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F8.png)\n\n6.\u5728\u5f39\u51fa\u7684\u201c\u65e5\u671f\u548c\u65f6\u95f4\u201d\u7a97\u53e3\u4e2d\uff0c\u9009\u62e9\u00a0Internet \u65f6\u95f4\u9875\u7b7e\uff0c\u5355\u51fb\u66f4\u6539\u8bbe\u7f6e\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F9.png)\n\n7.\u5728\u5f39\u51fa\u7684 \u201cInternet \u65f6\u95f4\u8bbe\u7f6e\u201d \u7a97\u53e3\u4e2d\uff0c\u5c06\u201c\u670d\u52a1\u5668\u201d\u8bbe\u7f6e\u4e3a\u76ee\u6807\u65f6\u949f\u6e90\u670d\u52a1\u5668\u57df\u540d\u6216\u8005 IP \u5730\u5740\u3002\n\n\u60a8\u53ef\u586b\u5199\u00a0\uff08\u53ef\u9009 time1\\time2\\time3\\time4\\time5\uff09.tencentyun.com\uff0c\u4f8b\u5982\u00a0time4.tencentyun.com\u3002\n\n8.\u5355\u51fb\u786e\u5b9a\uff0c\u5b8c\u6210\u8bbe\u7f6e\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a\n\n![](https:\/\/97yw3pix.hk03.1112oss.com\/TechnicalQA%2F%E6%96%87%E6%A1%A3%2Fweek7%2F%E9%85%8D%E7%BD%AENTP%E6%9C%8D%E5%8A%A1%2F10.png)"}