ntp和chrony
chrony 简介
chrony 是 RedHat 开发的,它是网络时间协议(NTP)的另一种实现;
RHEL/CentOS 7.x 的默认时间同步工具,在 CentOS 6.8之后也添加上了这个工具;
chrony 可以同时做为 ntp 服务的客户端和服务端;安装完后有两个程序 chronyd、chronyc:
chronyd 是一个 daemon 守护进程,chronyc 是用来监控 chronyd 性能和配置参数的命令行工具。
ntp pool
ntp 配置文件
/etc/ntp.conf 复制driftfile /var/lib/ntp/drift pidfile /var/run/ntpd.pid logfile /var/log/ntp.log # Access Control Support restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap nopeer noquery restrict 172.16.0.0 mask 255.240.0.0 nomodify notrap nopeer noquery restrict 100.64.0.0 mask 255.192.0.0 nomodify notrap nopeer noquery restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap nopeer noquery # local clock server 127.127.1.0 fudge 127.127.1.0 stratum 10
chrony 配置文件
/etc/chrony.conf 复制# 时钟服务器地址 server ntp1.aliyun.com # 指定包含 NTP 身份验证密钥的文件。 local stratum 8 # 指令设置当chronyd从可用源中选择同步源时,每个层应该添加多少距离到同步距离。 # 默认情况下,CentOS中设置为0,让chronyd在选择源时忽略源的层级 stratumweight 0 # chronyd程序的主要行为之一,就是根据实际时间计算出计算机增减时间的比率,将它记录到一个文件中是最合理的,它会在重启后为系统时钟作出补偿。 # 甚至可能的话,会从时钟服务器获得较好的估值。 driftfile /var/lib/chrony/drift # rtcsync指令将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。 rtcsync # 如果系统时钟的偏移量大于10秒,则允许系统时钟在前三次更新中步进。 makestep 10 3 # allow / deny - 这里你可以指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器。 allow all # 指定包含 NTP 身份验证密钥的文件。 keyfile /etc/chrony.keys # noclientlog logchange 0.5 logdir /var/log/chrony log measurements statistics tracking
chronyc 命令行工具
复制# 检查NTP访问是否对特定主机可用
chronyc accheck
# 查看 ntp_servers
chronyc sources
# 查看 ntp_servers 状态
chronyc sourcestats
# 查看 ntp_servers 是否在线
chronyc activity
# 查看 ntp 详细信息
chronyc tracking
# 报告已访问到服务器的客户端
chronyc clients:
修改时区
复制# 查看日期时间、时区及 NTP 状态 timedatectl # 查看时区列表 timedatectl list-timezones timedatectl list-timezones | grep -E "Asia/Shanghai" # 修改时区 timedatectl set-timezone Asia/Shanghai # 修改日期时间(可以只修改其中一个) timedatectl set-time "2020-04-11 16:51:10" # 开启 NTP timedatectl set-ntp true/flase
来自:https://www.cnblogs.com/hiyang/p/12682234.html#chrony-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6
分类:
linux 运维
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构