ntp時間伺服器搭建

2021-10-03 09:48:57 字數 2100 閱讀 8982

我在學習過程中經常遇到伺服器時間不一致導致很多故障,經過了很多次麻煩的經歷之後決定寫出來,以便於自己以後需要再來拿出來用,也希望可以幫到需要的人

yum install -y ntp ntpdate
備份配置檔案

cp /etc/ntp.conf /etc/ntp.conf.bak
將注釋掉的去掉,新建配置文章

egrep -v "^$|#" /etc/ntp.conf.bak >/etc/ntp.conf
編輯配置檔案

ftfile /var/lib/ntp/drift

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict -6 ::1

#允許內網其他機器同步時間

restrict 172.16.1.0 mask 255.255.255.0 nomodify notr

#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

#定義使用的上游 ntp伺服器,將原來的注釋

server ntp1.aliyun.com

server time1.aliyun.com

#允許上層時間伺服器主動修改本機時間

restrict time1.aliyun.com nomodify notrap noquery

restrict ntp1.aliyun.com nomodify notrap noquery

#外部時間伺服器不可用時,以本地時間作為時間服務

server 127.127.1.0

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

啟動時間伺服器並測試

systemctl start ntpd

ntpq -p

remote refid st t when poll reach delay offset jitter

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

== 120.25.115.20 10.137.53.7 2 u 8 64 1 32.515 2.672 0.000

203.107.6.88 10.137.38.86 2 u 7 64 1 24.061 4.179 0.000

*local(0) .locl. 10 l 6 64 1 0.000 0.000 0.000

最後進行客戶端測試

[root@web01 ~]

# date -s 20190825 #更改時間

sun aug 25 00:00:00 cst 2019

[root@web01 ~]

# ntpdate 172.16.1.61 #同步測試

2 oct 09:22:40 ntpdate[1606]: adjust time server 172.16.1.61 offset 0.001950 sec

Ntp時間伺服器搭建

1 服務端配置 yum y install ntp cp etc ntp.conf etc ntp.conf.bak egrep v etc ntp.conf.bak etc ntp.conf vim etc ntp.conf driftfile var lib ntp drift restrict...

NTP時間同步伺服器搭建

搭建hadoop集群需要同步時間。自己瞎鼓搗了半天也沒整好ntp時間伺服器,早晨無意中找到這篇文章果然好使,發現與ntp伺服器的配置檔案有區別 導致ntp客戶端訪問ntp伺服器失敗,這是已經修改後的配置檔案 一 ntp介紹 ntp network time protocol,網路時間協議 是用來使網...

ntp時間伺服器搭建詳解

ntp 伺服器是用於區域網伺服器時間同步使用的,可以保證局域網所有的伺服器與時間伺服器的時間保持一致,某些應用對時間實時 性要求高的必須統一時間。復旦大學免費ntp ntp.fudan.edu.cn 阿里雲免費ntp ntp1.aliyun.com 1.本地防火牆開啟123埠 ntp 伺服器監聽埠為...