NTP時間服務器搭建部署

一.NTP介紹
NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。
NTP服務器就是利用NTP協議提供時間同步服務的
二.NTP服務器安裝
1.查看本機系統版本
cat /etc/redhat-release
2.查看本機NTP軟件包
rpm -qa ntp
三.NTP服務器配置
1.備份ntp服務器配置文件
cp /etc/ntp.conf /etc/ntp.conf.bak
ll /etc/ntp.conf*
2.精簡優化配置文件
egrep -v "^$|#" /etc/ntp.conf.bak >/etc/ntp.conf
3.編輯配置文件
vim /etc/ntp.conf
NTP時間服務器搭建部署

配置文件文本:

driftfile /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

四.啓動NTP服務器
Centos6: /etc/init.d/ntpd start centos7: systemctl start ntpd
ntpq -p 顯示節點列表
NTP時間服務器搭建部署

五.客戶端時間同步測試
ntpdate 10.0.0.111(ntp服務器)
NTP時間服務器搭建部署

轉載於:https://blog.51cto.com/13520779/2089570