centos7搭建时间服务器

时区概念

GMT、UTC、CST、DST
UTC:整个地球分为二十四个时区,每个时区都有自己的本地时间,在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时间(UTC:Universal Time Coordinated)。
GMT:格林威治标准时间(Greenwich Mean Time)位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的线经(UTC与GMT时间基本相同)
CST:中国标准时间(China Standard Time)
GMT + 8 = UTC + 8 = CST
DST:夏令时(Daylight Saving time)指在夏天太阳升起的比较早时,将时间拔快一小时,以提早日光的使用(中国不使用)。

服务器端

服务器端防火墙放行NTP服务

firewall-cmd --zone=public --add-service=ntp

安装程序包

yum install ntp ntpdate -y

编辑配置文件

#新增日志文件
logfile /var/log/ntpd.log
#允许本地网络到此服务器同步时间  
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
#从阿里云的时间服务器同步时间
server ntp.aliyun.com
server time.nist.gov
#避免客户端报错:Server dropped: strata too high 
server 127.127.1.0 fudge
127.127.1.0 stratum 8

启动服务

systemctl start ntpd
systemctl enable ntpd.service 设置开机启动

验证服务

[root@node72 log]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*203.107.6.88    10.165.84.13     2 u    1   64  377   29.922  -11.007   1.615
 time-b-wwv.nist .INIT.          16 u    -  256    0    0.000    0.000   0.000
 LOCAL(0)        .LOCL.           5 l  727   64    0    0.000    0.000   0.000

[root@node72 log]# date -R
Fri, 15 Feb 2019 10:47:07 +0800

客户端

远程同步测试

[root@master ~]# ntpdate -d 192.168.2.72
10 Feb 23:31:47 ntpdate[58114]: ntpdate 4.2.6p5@1.2349-o Fri Apr 13 12:52:28 UTC 2018 (1)
Looking for host 192.168.2.72 and service ntp
host found : node72.magedu.com
transmit(192.168.2.72)
receive(192.168.2.72)
transmit(192.168.2.72)
receive(192.168.2.72)
transmit(192.168.2.72)
receive(192.168.2.72)
transmit(192.168.2.72)
receive(192.168.2.72)
server 192.168.2.72, port 123
stratum 6, precision -23, leap 00, trust 000
refid [192.168.2.72], delay 0.02618, dispersion 0.00000
transmitted 4, in filter 4
reference time:    e010a2ef.1b1c4a77  Fri, Feb 15 2019 10:31:11.105
originate timestamp: e010a2f5.a34d1179  Fri, Feb 15 2019 10:31:17.637
transmit timestamp:  e00ac26a.072e828e  Sun, Feb 10 2019 23:31:54.028
filter delay:  0.02623  0.02618  0.02620  0.02618 
         0.00000  0.00000  0.00000  0.00000 
filter offset: 385164.0 385163.9 385163.7 385163.6
         0.000000 0.000000 0.000000 0.000000
delay 0.02618, dispersion 0.00000
offset 385163.916949

10 Feb 23:31:54 ntpdate[58114]: step time server 192.168.2.72 offset 385163.916949 sec
原文地址:https://www.cnblogs.com/feng-land/p/10382318.html