安裝ntp

#檢查服務是否安裝
    1. rpm -q ntp
#安裝ntp伺服器
    1. yum -y install ntp

修改配置檔案:/etc/ntp.conf

內容如下:
    1. restrict default kod nomodify notrap nopeer noquery
    1. restrict -6 default kod nomodify notrap nopeer noquery
    1. restrict 127.0.0.1 
    1. restrict -6 ::1
    1. fudge 127.127.1.0 stratum 10
    1. driftfile /var/lib/ntp/drift
    1. keys /etc/ntp/keys
    1. logfile /var/log/ntp.log
    1. includefile /etc/ntp/crypto/pw
    1. server 128.199.84.169


設定ntpd為系統服務,並開機自啟動

    1. systemctl enable ntpd
    1. systemctl restart ntpd

測試Ntpd服務

1. 修改系統時間

    1. date -s "2016-03-09 07:00:00"


2. 使用tcpdump抓包測試

在一個終端執行:
    1. tcpdump -i eth0 -s 0 -vvvvv udp port 123
說明:ntpd是使用udp 123埠來傳輸資料的

3. 重啟ntpd服務,檢視時間同步結果

    1. systemctl restart ntpd

此時看看tcpdump抓包情況



手動同步時間

ntpdate 128.199.84.169  
(若報錯,可參考:https://linux.cn/blog-6599-5989.html  )

其他命令

1. ntpq -p 
檢視本機和上層伺服器的時間同步結果
2. ntptrace
可以用來追蹤某臺時間伺服器的時間對應關係 
3. ntpdate IP ,如:ntpdate 128.199.84.169    
  客戶端與NTP server進行時鐘同步。
4. tail -f /var/log/ntp.log
檢視ntp日誌

systemctl stop ntpd.service
ntpdate 128.199.84.169     #手動同步