1.條件:
1)centos自帶有ntp服務
2)局域網的ip假設如下:
192.168.184.11(ntp本地服務器)
192.168.184.12
192.168.184.13
3)目的:因為沒網,但又要時間同步,所以只能在本地服務器上設置好時間(與北京時間差不多),然后其他主機與該本地服務器時間同步即可。
2.做法
1)在192.168.184.11(即本地服務器)中的做法如下:
①data -s "具體年月日時分秒"
②vim /etc/ntp.conf
③在該文件下添加如下內容並保存:
# 允許內網其他機器同步時間 restrict 192.168.184.0 mask 255.255.255.0 nomodify notrap # 外部時間服務器不可用時,以本地時間作為時間服務 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 8
④啟動ntp服務
cd /usr/lib/systemd/system
systemctl start ntpd #啟動
systemctl enable ntpd.service #設置開機啟動服務
2)在其他節點(比如這邊的:192.168.184.12,192.168.184.13)的做法如下:
①執行vim /etc/ntp.conf,加入一下內容:
restrict 127.0.0.1 restrict -6 ::1 # 配置時間服務器為本地的時間服務器 server 192.168.184.11 restrict 192.168.184.11 nomodify notrap noquery server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 8
②手動ntpdate同步:ntpdate -u 192.168.184.11