天天看點

區域網路同步時鐘ntp

搭了個cdh環境,無法連接配接外網,時間不同步,就選了一台機器作為NTP伺服器,其它節點同步到此伺服器

紅字改為自己的伺服器端的IP

伺服器端(node1)

1、yum install ntp -y  安裝ntp

2、chkconfig ntpd on  開機自啟動

3、vi /etc/ntp.conf

4、從上到下改動的地方有

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

restrict 192.168.21.0 mask 255.255.255.0 nomodify notrap
           
注釋掉
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
           
# 允許上層時間伺服器主動修改本機時間
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery
restrict 3.cn.pool.ntp.org nomodify notrap noquery

# 外部時間伺服器不可用時,以本地時間作為時間服務
server  127.127.1.0
fudge   127.127.1.0 stratum 10
           

6、ntpd -s node1 手動同步時間

7、service ntpd start 啟動node01的ntpd服務

8、netstat -unlnp | grep ntpd  檢查ntp端口是否已經開啟  

udp        0      0 192.168.21.0:123        0.0.0.0:*                           424820/ntpd   

9、ntpq -p   檢視網絡中的NTP伺服器,顯示用戶端和每個伺服器的關系

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 LOCAL(0)        .LOCL.          10 l    -   64    0    0.000    0.000   0.000

各節點

1、vi 

/etc/ntp.conf

2、自上到下改動有

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
           
# 預設的伺服器清單注釋掉
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

# 從node01中同步時間
server 192.168.21.101

# 允許node01修改本地時間
restrict 192.168.21.101 nomodify notrap noquery

# 如果node01不可用,用本地的時間服務
server 127.127.1.0
fudge 127.127.1.0 stratum 10
           

3、ntpdate -u node01 每台用戶端在啟動ntpd服務之前,手動同步一下時間

4、service ntpd start

5、ntpq -p 

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 node01         LOCAL(0)        11 u    6   64    1    0.152    0.025   0.000

*LOCAL(0)        .LOCL.          10 l    5   64    1    0.000    0.000   0.000

參考自https://cloud.tencent.com/developer/article/1336679,親測有用,感謝

繼續閱讀