終于還是要搭建ntp伺服器,我的架構是一台伺服器可以上公網,其他内網伺服器不能。
ntp伺服器是C/S架構的時間同步伺服器。
方案:
公網伺服器搭建ntp伺服器端
其他伺服器為用戶端
公網伺服器:
[root@localhost ~]# yum install ntp
配置/etc/ntp.conf
[root@localhost ~]# more /etc/ntp.conf |grep -v ^$|grep -v ^#
driftfile /var/lib/ntp/drift
restrict default ignore nomodify notrap nopeer noquery # ignore表示拒絕所有主機
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
# 允許内網其他機器同步時間
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# 中國這邊最活躍的時間伺服器 : http://www.pool.ntp.org/zone/cn
server 210.72.145.44 perfer # 中國國家受時中心
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
# 允許上層時間伺服器主動修改本機時間
restrict 210.72.145.44 nomodify notrap noquery
restrict 202.112.10.36 nomodify notrap noquery
restrict 59.124.196.83 nomodify notrap noquery
# 外部時間伺服器不可用時,以本地時間作為時間服務
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
客戶機:
ntpdate -u 192.168.1.1(伺服器内網位址)
計劃任務:
0 13 * * * ntpdate -u 192.168.1.1