天天看點

Linux配置ntp時間伺服器

一、基礎環境

1、作業系統:CentOS 7.3

2、ntp:4.2.6

3、機器,服務端(192.168.0.101)用戶端(192.168.0.102)

二、安裝ntp

yum -y install ntp
           

三、服務端配置(192.168.0.101)

vim /etc/ntp.conf

restrict 192.168.0.101 nomodify notrap nopeer noquery          //目前節點IP位址
restrict 192.168.0.2 mask 255.255.255.0 nomodify notrap      //叢集所在網段的網關(Gateway),子網路遮罩(Genmask)

# 在server部分添加以下部分,并注釋掉server 0 ~ n
server 127.127.1.0
fudge 127.127.1.0 stratum 10
           
Linux配置ntp時間伺服器

四、用戶端配置(192.168.0.102)

vim /etc/ntp.conf

restrict 192.168.0.102 nomodify notrap nopeer noquery          //目前節點IP位址
restrict 192.168.0.2 mask 255.255.255.0 nomodify notrap      //叢集所在網段的網關(Gateway),子網路遮罩(Genmask)

# 在server部分添加如下語句,将server指向主節點。
server 192.168.0.102
fudge 192.168.0.102 stratum 10
           
Linux配置ntp時間伺服器

五、驗證并配置定時任務

1、驗證

分開開啟服務端及用戶端的ntp服務,并配置開機自啟

service ntpd start
chkconfig ntpd on
           

用戶端運作如下指令,與服務端實作同步

ntpdate -u 192.168.0.101
           
Linux配置ntp時間伺服器

2、配置定時任務

我們可以在用戶端配置crontab定時任務使用戶端每隔一段時間自動與伺服器端同步時間,如,在每星期一的晚上十點同步一次時間

crontab -e

00 22 * * 1 ntpdate -u 192.168.0.101
           

繼續閱讀