一.简介

时间同步服务器是计算机网络中用于提供高精度时间服务的专用设备,通过接收卫星信号(如北斗、GPS)或地面时间源,利用NTP/SNTP/PTP等协议为全网设备提供统一时间基准。

二.授时中心

210.72.145.44 国家授时中心 
ntp.aliyun.com 阿里云 
s1a.time.edu.cn 北京邮电大学 
s1b.time.edu.cn 清华大学 
s1c.time.edu.cn 北京大学 
s1d.time.edu.cn 东南大学 
s1e.time.edu.cn 清华大学 
s2a.time.edu.cn 清华大学 
s2b.time.edu.cn 清华大学 
s2c.time.edu.cn 北京邮电大学 
s2d.time.edu.cn 西南地区网络中心 
s2e.time.edu.cn 西北地区网络中心 
s2f.time.edu.cn 东北地区网络中心 
s2g.time.edu.cn 华东南地区网络中心 
s2h.time.edu.cn 四川大学网络管理中心

s2j.time.edu.cn 大连理工大学网络中心 
s2k.time.edu.cn CERNET桂林主节点 
s2m.time.edu.cn 北京大学 
ntp.sjtu.edu.cn 202.120.2.101 上海交通大学

使用最广泛的NTP服务器集中在国家授时中心、阿里云、高校及区域网络中心,其中 ntp.aliyun.com(阿里云)和ntp.sjtu.edu.cn(上海交通大学) 因高可用性和稳定性成为主流选择

三.chrony服务器

第一步:编制chrony的配置文件

在编辑chrony配置文件之前,须先安装chrony服务器(chrony由两个程序组成,分别是chronyd和chronyc )

  • chronyd:是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。

  • chronyc:提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作

    [root@server ~]# yum  install  chrony  -y   (安装chrony)
    
    ​[root@server ~]# systemctl start  chronyd​    (重启服务)
    
    [root@server ~]# systemctl enable  chronyd

    第二步:chrony配置文件分析

  • 主配置文件: /etc/chrony.conf

  • [root@server ~]# vim  /etc/chrony.conf
    
    # 使用 pool.ntp.org 项目中的公共服务器。
    # 或者使用server开头的服务器,理论上想添加多少时间服务器都可以
    # iburst表示的是首次同步的时候快速同步
    pool pool.ntp.org iburst
    
    # 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间 补偿调整。 
    driftfile /var/lib/chrony/drift 
    
    # 如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。 
    # Allow the system clock to be stepped in the first three updates if its offset is larger than 1 second. 
    makestep 1.0 3 
    
    # 启用实时时钟(RTC)的内核同步。 
    # Enable kernel synchronization of the real-time clock (RTC). 
    rtcsync 
    
    # 通过使用 hwtimestamp 指令启用硬件时间戳 
    # Enable hardware timestamping on all interfaces that support it. 
    #hwtimestamp * 
    # Increase the minimum number of selectable sources required to adjust the system clock. 
    #minsources 2 
    
    # 指定 NTP 客户端地址,以允许或拒绝连接到扮演时钟服务器的机器 
    # Allow NTP client access from local network. 
    #allow 192.168.48.0/24
    
    # Serve time even if not synchronized to a time source. 
    # local stratum 10 
    
    # 指定包含 NTP 身份验证密钥的文件。 
    # Specify file containing keys for NTP authentication. 
    # keyfile /etc/chrony.keys 
    
    # 指定日志文件的目录。 
    # Specify directory for log files. 
    logdir /var/log/chrony 
    
    # 选择日志文件要记录的信息。 
    # Select which information is logged. 
    # log measurements statistics tracking

    四.同步时间

第一步:先将正确的时间修改错误

第二步:编辑chrony的配置文件

[root@server ~]# vim  /etc/chrony.conf 
# 定位第3行,删除后添加阿里的时间同步服务地址
server   ntp.aliyun.com   iburst

# 注意:也可以先清空chrony.conf内容,将阿里开源提供的时间服务器推荐配置复制粘贴到该文件中
server ntp.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony

第三步:重启服务

[root@server ~]# systemctl restart  chronyd

第四步:时间同步

[root@server ~]# chronyc  sources

五.练习时间同步

搭建本地时间同步服务

架构

性质 IP地址 同步对象
服务端master 192.168.72.132 ntp.aliyum.com
客户端node 192.168.72.130 192.168.72.132

要求

  • 服务端server向阿里时间服务器进行时间同步

  • 客户端node1向服务端server进行时间同步

第一步:定位服务端

点击i键,便可以修改里面内容,修改完后点击Esc键,冒号+wq保存并退出

重启服务器

设置允许客户端时间同步

点击Esc,冒号+wq保存并退出

重启服务器

第二步:定位客户端node

# 编辑配置文件
[root@node1 ~]# vim  /etc/chrony.conf     # 修改第3行为server的地址
server  192.168.48.130  iburst

# 重启服务
[root@node1 ~]# systemctl restart  chronyd

六.chrony  sources输出分析

  • M:这表示信号源的模式。^表示服务器,=表示对等方,表示本地连接的参考时钟。

  • S:此列指示源的状态

*

**chronyd当前同步到的源**

+ 表示可接受的信号源,与选定的信号源组合在一起
- 表示被合并算法排除的可接受源
表示已失去连接的源
X 表示chronyd认为是虚假行情的时钟(即,其时间与大多数其他来源不一致)
~ 表示时间似乎具有太多可变性的来源

七.chrony的其他命令

查看时间服务器的状态

[root@server ~]# chronyc  sourcestats  -v

查看时间服务器是否在线

[root@server ~]# chronyc  activity  -v

同步系统时钟

[root@server ~]# chronyc  -a  makestep

Logo

openEuler 是由开放原子开源基金会孵化的全场景开源操作系统项目,面向数字基础设施四大核心场景(服务器、云计算、边缘计算、嵌入式),全面支持 ARM、x86、RISC-V、loongArch、PowerPC、SW-64 等多样性计算架构

更多推荐