时间同步软件实现:
ntp
chrony
ntp:
将系统时钟和世界协调时UTC同步,精度在局域网内可达0.1ms,在互联网上绝大多数的地方精度可以达到1-50ms
项目官网:http://www.ntp.org
chrony: 安装的化 yum -y install chrony
实现NTP协议的的自由软件。可使系统时钟与NTP服务器,通过Internet同步的两台机器之间的典型精度在几毫秒之内,在LAN上,精度通常为几十微秒。利用硬
件时间戳或硬件参考时钟,可实现亚微秒的精度
监听端口: 服务端: 123/udp,客户端: 323/udp
配置文件: /etc/chrony.conf
ntpdate命令 目前用的比较少了,但是会立即同步时间,但是需要联网
1、安装:yum install ntpdate
ntpdate简单用法:
# ntpdate ip
# ntpdate 210.72.145.44
也可以用一些NTP服务地址,例如 ntpdate ntp.ailiyun.com 下面是国内的一些ntp 服务器
阿里云公共NTP服务器
Unix/linux类:ntp.aliyun.com,ntp1-7.aliyun.com
windows类: time.pool.aliyun.com
腾讯公共NTP
time1-5.cloud.tencent.com
大学ntp服务
s1a.time.edu.cn 北京邮电大学
s1b.time.edu.cn 清华大学
s1c.time.edu.cn 北京大学
国家授时中心服务器:210.72.145.44
美国标准技术院: time.nist.gov
chrony 命令(重点)
1、安装 yum -y intall chrony
chrony 组成
两个主要程序:chronyd和chronyc
服务unit 文件: /usr/lib/systemd/system/chronyd.service
监听端口: 服务端: 123/udp,客户端: 323/udp
配置文件: /etc/chrony.conf
举例,实现企业私有时间服务器,一台主机连接外网当服务器,然后其他内网主机去连这台主机
服务器
1、[root@centos7 ~]# yum -y install chrony #安装
2、修改配置文件 [root@centos7 ~]# vim /etc/chrony.conf
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
可以改成国内地址
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
iburst 是为了加快速度,最好加上
# Allow NTP client access from local network.
#allow 192.168.0.0/16 #需要放开 否则客户端的机器无法访问该服务器的端口
allow 10.0.0.0/24 #这是允许10网段的机器都能访问
# Serve time even if not synchronized to a time source.
#local stratum 10 #这个也需要放开
local stratum 10 #删除此行注释,当互联网无法连接,仍然可以为客户端提供时间同步服务
保存退出
[root@centos7 ~]# systemctl restart chronyd #重启一下chronyd 服务
客户端配置
1、[root@centos7 ~]# yum -y install chrony #安装
2、修改配置文件 [root@centos7 ~]# vim /etc/chrony.conf
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
可以改成国内地址
server 10.0.0.150 iburst #这是上面服务端的地址
退出保存 然后重启,命令如下
[root@centos7 ~]#systemctl restart chronyd.service
#确认同步成功可以使用下面命令
[root@centos7 ~]#chronyc sources -v
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- 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
===============================================================================
^* 10.0.0.150 3 6 77 29 -229us[-1154us] +/- 17ms
出现* 代表同步成功,出现 ? 代表还未成功,这个一般等一会就会成功
如果想立即同步就用 ntpdate 10.0.0.150
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?