日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NTP服务器时间同步

發(fā)布時(shí)間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NTP服务器时间同步 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


一、簡要說明
二、安裝步驟
三、配置文件
四、常用命令
五、注意事項(xiàng)
六、運(yùn)行截圖
七、參考資料


一、簡要說明
????????? 搭建Kubernetes環(huán)境,需要幾臺(tái)、幾十臺(tái)機(jī)器配合運(yùn)作,許多集群服務(wù)比如Etcd等都依賴系統(tǒng)的時(shí)間,如果機(jī)器的系統(tǒng)時(shí)間不一致,可能會(huì)出現(xiàn)各種問題。因此有必要統(tǒng)一集群內(nèi)所有服務(wù)器的系統(tǒng)時(shí)間。

????????? NTP(Network Time Protocol)可以很方便的解決服務(wù)器之間的時(shí)間同步問題,Ubuntu系統(tǒng)下NTP安裝也很方便,經(jīng)過測試,在Ubuntu 16.04環(huán)境下,直接安裝NTP服務(wù),使用Ubuntu系統(tǒng)自帶的pool ntp.ubuntu.com 時(shí)間服務(wù)器地址池,就可以實(shí)現(xiàn)時(shí)間同步。用戶也可以選擇NTP官方網(wǎng)站推薦的pool pool.ntp.org地址池,或者選擇中國區(qū)的pool cn.pool.ntp.org地址池,都會(huì)生效的。

????????? 用戶還可以選擇集群中的1臺(tái)作為主授時(shí)服務(wù)器(NTP 服務(wù)器角色),通過配置文件中的pool 地址池與上層的服務(wù)器同步時(shí)間,集群內(nèi)所有其他機(jī)器(NTP客戶端角色)的NTP配置文件中,使用Server xx.xx.xx.xx形式,明確指向主授時(shí)服務(wù)器IP地址,也可以實(shí)現(xiàn)為集群提供統(tǒng)一的時(shí)間服務(wù)。如果考慮高可靠性,還可以將多臺(tái)服務(wù)器作為集群的授時(shí)服務(wù)器。

???????? 也可以到www.ntp.org網(wǎng)站中查找中國區(qū)的服務(wù)器地址,直接在NTP配置文件中使用這些地址,比如 server? xx.xx.xx.xx 。

???????? 下面的例子中,我們使用到的服務(wù)器信息:
?????????? 服務(wù)器名?? IP地址???????????????? 角色
?????????? rancher2?? 192.168.3.220?? NTP 服務(wù)器
?????????? node221??? 192.168.3.221?? NTP 客戶端
????
二、安裝步驟
#在集群的所有機(jī)器上安裝NTP相關(guān)程序即可
sudo apt install ntp ntpdate ntpstat

三、配置文件
#3.1 NTP 主授時(shí)服務(wù)器(192.168.3.220)配置文件/etc/ntp.conf去除注釋后的內(nèi)容:
driftfile /var/lib/ntp/ntp.drift

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server 1.networktime.org iburst
server 2.networktime.org iburst
server ntp.synet.edu.cn iburst
server ntp.neu6.edu.cn iburst
server ntp.gwadar.cn iburst
server ntp.neu.edu.cn iburst

restrict -4 default kod notrap nomodify nopeer limited
restrict -6 default kod notrap nomodify nopeer limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery

#3.2 NTP 客戶端服務(wù)器(192.168.3.221)配置文件/etc/ntp.conf去除注釋后的內(nèi)容:
driftfile /var/lib/ntp/ntp.drift

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

server 192.168.3.220 iburst

restrict -4 default kod notrap nomodify nopeer limited
restrict -6 default kod notrap nomodify nopeer limited
restrict 127.0.0.1
restrict ::1
restrict source notrap nomodify noquery

#3.3 其他地址池和授時(shí)服務(wù)器地址參考
#3.3.1===Ubuntu 16.04系統(tǒng)默認(rèn)的地址池===

pool ntp.ubuntu.com

pool 0.ubuntu.pool.ntp.org
pool 1.ubuntu.pool.ntp.org
pool 2.ubuntu.pool.ntp.org
pool 3.ubuntu.pool.ntp.org

#3.3.2===www.pool.ntp.org官網(wǎng)上推薦的地址池===
pool pool.ntp.org

pool 0.pool.ntp.org
pool 1.pool.ntp.org
pool 2.pool.ntp.org
pool 3.pool.ntp.org

#3.3.3===中國區(qū)地址池===
pool cn.pool.ntp.org

pool 0.cn.pool.ntp.org
pool 1.cn.pool.ntp.org
pool 2.cn.pool.ntp.org
pool 3.cn.pool.ntp.org

#3.3.4===www.ntp.org官網(wǎng)上提供的中國區(qū)服務(wù)器地址===

server 1.networktime.org
server 2.networktime.org
server ntp.synet.edu.cn
server ntp.neu6.edu.cn
server ntp.gwadar.cn
server ntp.neu.edu.cn


四、常用命令

#停止NTP服務(wù)
sudo service ntp stop

#只查詢、不更新本機(jī)系統(tǒng)時(shí)間
sudo ntpdate -q pool.ntp.org

#使用debug(-d)模式查詢?cè)敿?xì)更新信息
sudo ntpdate -d pool.ntp.org

#直接與pool.ntp.org中的服務(wù)器同步本機(jī)系統(tǒng)時(shí)間
sudo ntpdate pool.ntp.org

#查詢NTP連接上層授時(shí)服務(wù)器的狀態(tài)
nptq -p

#啟動(dòng)NTP服務(wù)
sudo service ntp start

#查詢ntp運(yùn)行狀態(tài)
sudo ntpstat

#查看系統(tǒng)時(shí)間
date
#設(shè)置系統(tǒng)時(shí)間的日期為2018年07月09日08點(diǎn)44分30秒
sudo date -s "2018/07/09 08:44:30"

#查看硬件時(shí)間
sudo hwclock? --show
#設(shè)置硬件時(shí)間
sudo hwclock --set --date="07/09/18 14:55:30"

#使用硬件時(shí)間同步系統(tǒng)時(shí)間
sudo hwclock --hctosys
#使用系統(tǒng)時(shí)間同步硬件時(shí)間
sudo hwclock --systohc


五、注意事項(xiàng)
????? 1、NTP服務(wù)和ntpdate命令不可同時(shí)使用。使用ntpdate之前,一定要先停止NTP服務(wù)。啟用NTP服務(wù)之前,應(yīng)先使用ntpdate命令 同步一下服務(wù)器時(shí)間,或者直接使用date命令設(shè)置系統(tǒng)時(shí)間,以免服務(wù)器時(shí)間相差太大,NTP服務(wù)不起作用。
????? 2、注意互聯(lián)網(wǎng)授時(shí)服務(wù)器地址是否可用?正式使用之前,可以使用ntpdate 驗(yàn)證一下,是否可以同步時(shí)間。
????? 3、除了Linux自帶的防火墻要打開UDP123端口外,網(wǎng)絡(luò)出口防火墻也要打開UDP123端口!這樣運(yùn)行ntpdate同步時(shí)間時(shí),才不會(huì)出現(xiàn)“no server suitable for synchronization found”錯(cuò)誤。

六、運(yùn)行截圖

圖01-Rancher2主授時(shí)服務(wù)器配置文件-與上層的中國區(qū)的服務(wù)器地址進(jìn)行同步

圖02-Rancher2主授時(shí)服務(wù)器同步結(jié)果

圖03-NTP客戶端服務(wù)器node221,配置文件指向主授時(shí)服務(wù)器

圖04-NTP客戶端服務(wù)器node221時(shí)間同步結(jié)果

圖05-使用Ubuntu系統(tǒng)自帶的NTP地址池pool,能夠正常同步時(shí)間

圖06-使用pool.ntp.org地址池也是能正常同步時(shí)間的

圖07-使用中國區(qū)的地址池cn.pool.ntp.org 也是可以同步時(shí)間的

圖08-使用nslookup查詢cn.pool.ntp.org地址池域名的地址信息

圖09-NTP相關(guān)配置文件位置


七、參考資料

Linux NTP配置詳解 (Network Time Protocol)
https://blog.csdn.net/iloli/article/details/6431757

Linux的NTP配置總結(jié)
https://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html

部署NTP服務(wù)器進(jìn)行時(shí)間同步
https://www.cnblogs.com/linypwb/p/5532535.html

NTP服務(wù)配置
http://blog.sina.com.cn/s/blog_4612ed51010124e2.html

NTP時(shí)間同步問題
https://blog.csdn.net/sinat_36384705/article/details/73826408

How to Configure NTP for Use in the NTP Pool Project on Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-configure-ntp-for-use-in-the-ntp-pool-project-on-ubuntu-16-04

查找中國區(qū)授時(shí)服務(wù)器
http://support.ntp.org/bin/view/Servers/StratumOneTimeServers
http://support.ntp.org/bin/view/Servers/PublicTimeServer000934
http://support.ntp.org/bin/view/Servers/PublicTimeServer001036
http://support.ntp.org/bin/view/Servers/PublicTimeServer000893
http://support.ntp.org/bin/view/Servers/StratumTwoTimeServers
http://support.ntp.org/bin/view/Servers/PublicTimeServer001465
http://support.ntp.org/bin/view/Servers/PublicTimeServer000794
http://support.ntp.org/bin/view/Servers/PublicTimeServer001466
http://support.ntp.org/bin/view/Servers/PublicTimeServer000781
http://support.ntp.org/bin/view/Servers/PublicTimeServer000782
http://support.ntp.org/bin/view/Servers/PublicTimeServer001237

How do I use pool.ntp.org
http://www.pool.ntp.org/zh/use.html

關(guān)于ntp時(shí)間同步理論及配置參數(shù)
https://blog.csdn.net/qq_32748887/article/details/76690944

NTP的配置總結(jié)(整理+轉(zhuǎn)載)
https://blog.csdn.net/gycool21/article/details/51746174

解決ntp的錯(cuò)誤 no server suitable for synchronization found
http://www.blogjava.net/spray/archive/2008/07/10/213964.html






轉(zhuǎn)載于:https://www.cnblogs.com/rancher-maomao/p/9309990.html

總結(jié)

以上是生活随笔為你收集整理的NTP服务器时间同步的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。