Centos7時間同步NTP

一、    實現功能
CDH集羣搭建的時候,通過NTP配置時鐘同步,從而可以使集羣時間一致,保證集羣運行基本條件。

二、    環境
Centos7.4

三、    配置ntp服務器
1.    查看系統是否安裝ntp

rpm -qa | grep ntp
2.    安裝ntp和ntpdate

yum -y install ntp ntpdate
3.    查看是否已安裝完成

rpm -qa | grep ntp
4.    配置ntp服務器

vim /etc/ntp.conf
註釋

#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
 
在下面再添加一行,代表本機作爲服務器

#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
server 127.127.1.0 iburst
6.啓動ntp服務並且設置開機啓動

systemctl start ntpd
systemctl enable ntpd
7.查看狀態

systemctl status ntpd
8. 查看是否同步

ntpq -p
備註:ntp服務器啓動後,可能要等3-5min,才能檢測到啓動服務
 

四、    客戶端配置
1.    查看系統是否安裝ntp

rpm -qa | grep ntp
2.    安裝ntp和ntpdate

yum -y install ntp ntpdate
3.    查看是否已安裝完成

rpm -qa | grep ntp
4.    配置ntp服務器

vim /etc/ntp.conf
修改

#註釋掉其他時間服務器
#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
server 10.2.31.25 #配置本地ntp服務器爲時間同步服務器
restrict 10.2.31.25 nomodify notrap noquery #允許本地時間服務器主動修改本機的時間
 
5.手動同步一下

systemctl stop ntpd
ntpdate 10.2.31.25
systemctl start ntpd
6.檢測與本地ntpd Server同步

ntpdate -u 10.2.31.25
7.啓動ntp並且設置開機啓動

systemctl start ntpd
systemctl enable ntpd
8.查看同步狀態

ntpq -p
備註:服務器初次啓動,大概要等3-5min,然後時間會自動同步,偏差會逐漸縮小
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章