1. 程式人生 > 其它 >時間同步伺服器操作方法

時間同步伺服器操作方法

時間同步伺服器操作方法

方法一:NTP時間同步
NTP基於UDP報文進行傳輸,使用的UDP埠號為123
一、服務端:
假設ip是192.168.100.100
1、安裝ntp
外網:sudo apt install ntp (內網拷貝離線包安裝)
2、修改配置檔案:vim /etc/ntp.conf
註釋預設的時間同步源
#pool 127.0.0.1 iburst
#pool 1.debian.pool.ntp.org iburst
#pool 2.debian.pool.ntp.org iburst
#pool 3.debian.pool.ntp.org iburst
增加以下2行
server 127.127.1.0
fudge 127.127.1.0 stratum 8
修改後,儲存退出
3、啟動服務並設定服務開機自啟
systemctl start ntp && systemctl enable ntp
4、檢視偵聽埠
netstat -tunlp | grep ntp 或者ss -ntulp | grep ntp 一般是在123埠
timedatectl 檢視當前機器時間
ip a 檢視服務端ip
二、客戶端
客戶端需要安裝ntpdate的包,輸入 ntpdate serverip(服務端配置ntp的ip地址)去同步時間
結果顯示類似: 18 Aug 16:04:24 ntpdate[30646]: step time server 10.20.xx.xx offset 47606319.594686 sec
PS:
1、如果上述操作不成功,可以 ntpdate -d 192.168.100.100 檢視報錯詳情,然後再去ntpdate 服務端ip 同步時間
2、ntp客戶端用ntpdate -d serverip檢視,發現有192.168.100.100: Server dropped: strata too high
的錯誤,這是因為ntp server還沒有和其自身或者它的server同步上。可以用ntptrace 和ntpd -s -d 命令,再去ntpdate serverip即可。