NTP(网络时间协议)是用于网络设备时间同步的核心协议,通过客户端 - 服务器架构,使分布式系统中所有设备的时钟保持一致。它基于 UTC 时间基准,通过多级时间服务器层级(Stratum)传递高精度时间,支持毫秒级甚至微秒级同步精度。广泛应用于服务器、物联网设备、金融系统等场景,保障日志审计、数据时序、业务交互的时间一致性。协议轻量且容错性强,可通过加密认证机制防止时间篡改,是保障系统稳定运行的基础支撑技术。
修改时区
通过 timedatectl 命令修改系统时区为 亚洲/上海
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai使用 ntp 同步
配置 NTP 服务器地址
[root@localhost ~]# cat >> /etc/chrony.conf << EOF
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server ntp.ntsc.ac.cn iburst
server time.hicloud.com iburst
EOF添加系统服务
设置服务随系统启动
[root@localhost ~]# systemctl enable chronyd.service重启服务
一定要重启 chronyd 服务
[root@localhost ~]# systemctl restart chronyd.service同步时间
[root@localhost ~]# chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current best, '+' = combined, '-' = not combined,
| / 'x' = may be in error, '~' = too variable, '?' = unusable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp.ams1.nl.leaseweb.net 2 6 375 119 -12ms[-8514us] +/- 178ms
^+ ntp.wdc2.us.leaseweb.net 2 6 277 48 -1607us[-1607us] +/- 263ms
^- 114.118.7.163 2 6 15 62 -72ms[ -72ms] +/- 701ms