1、描述
NTP:
來自百度百科:
NTP服務器【Network Time Protocol(NTP)】是用來使計算機時間同步化的一種協議,它可以使計算機對其服務器或時鍾源
(如石英鍾,GPS等等)做同步化,它可以提供高精准度的時間校正(LAN上與標准間差小於1毫秒,WAN上幾十毫秒),且可
介由加密確認的方式來防止惡毒的協議攻擊。時間按NTP服務器的等級傳播。按照離外部UTC源的遠近把所有服務器歸入不同
的Stratum(層)中。
環境描述:
系統:
centos7
集群:
server1
server2
server3
讓server1作為時間源,server2和server3向server1同步時間;
2、安裝ntp
查看當前服務器時區&列出時區並設置時區(如已是正確時區,請略過):
timedatectl
timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
安裝(所有主機):
yum -y install ntp
3、硬件時間問題
同步硬件時間:
date #查看系統時間
hwclock --show #查看硬件時間
timedatectl set-timezone Asia/Shanghai #調整時區
hwclock --systohc --localtime #將硬件時間調整為和系統時間一樣
clock -w #將日期寫入CMOS
4、配置
server1
-----/etc/ntp.conf-----
#以server1的硬件時間作為時間源
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
#注釋掉其他時間源
#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
#授權192.168.1.*網段可以同步
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server2和server3
-----/etc/ntp.conf-----
#配置server1作為同步時間源
server server1
#注釋掉其他時間源
#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
5、啟動
systemctl start ntpd
6、查看
查看與時間源的偏差:
ntpdc -c loopinfo
查看同步的時間源:
ntpq -p