【同步時間】Linux設置時間同步


所有節點都要確保已安裝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立刻同步服務器時間。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM