所有節點都要確保已安裝ntpd(在步驟4已安裝)
1.首先選擇一台服務器作為時間服務器。
假設選定為node1.sunny.cn服務器為時間服務器。
2.ntp服務器的配置
修改ntp.conf文件:
vi /etc/ntp.conf
一共修改三處內容,將#去掉,並且將網段修改正確。
restrict 192.168.2.2 mask 192.168.2.255 nomodify notrap
將以下4個server進行#注釋掉。
#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 #local clock fudge 127.127.1.0 stratum 10
3.編輯/etc/sysconfig/ntpd文件,替換為以下內容
vim /etc/sysconfig/ntpd # Drop root to id 'ntp:ntp' by default. SYNC_HWCLOCK=yes OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
4.設置正確時間,啟動ntpd服務,並且設置開機啟動
可以忽略這步
date -s ‘2017-01-01 01:01:01’
啟動服務
service ntpd start
在/etc/rc.local中添加如下ntp服務器的啟動命令行
/etc/init.d/ntpd start
5.root賬戶下在每個需要同步的子節點編寫crontab任務。
命令:
crontab -e
輸入以下內容:
0-59/10 * * * * /usr/sbin/ntpdate node1.sunny.cn
這個任務的意義就是每10分鍾和node1同步時間。
6.執行/usr/sbin/ntpdate node1.sunny.cn立刻同步服務器時間。