chrony服务部署配置
chrony的服务,在centos上是chronyd,在ubuntu上是chrony
环境信息
操作系统系统 | Server | Client | 外网NTP服务器 |
---|---|---|---|
ubuntu20 | 192.168.100.21 | 192.168.100.22 | ntp.aliyun.com |
安装
sudo apt install chrony
关闭systemd-timesyncd服务
sudo systemctl stop systemd-timesyncd sudo systemctl disable systemd-timesyncd sudo systemctl mask systemd-timesyncd
ntp服务互相冲突
启动服务
sudo systemctl enable chrony sudo systemctl start chrony
配置服务端
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #pool 2.centos.pool.ntp.org iburst # ntp server server ntp.aliyun.com iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. # offset13 makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). # RTC rtcsync # Enable hardware timestamping on all interfaces that support it. # hwtimestamp #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 允许所有客户端同步当前服务端 allow all # Serve time even if not synchronized to a time source. local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. leapsectz right/UTC logdir /var/log/chrony bindcmdaddress 0.0.0.0
配置客户端
只需要写一行server 192.168.100.21 iburst
重启chrony服务
防火墙服务放开
firewall-cmd --add-service=ntp --permanent firewall-cmd --reload
设置时区
确认当前时区
#timedatectl show Timezone=Asia/Shanghai LocalRTC=no CanNTP=yes NTP=yes NTPSynchronized=yes TimeUSec=Wed 2020-07-15 17:06:51 CST RTCTimeUSec=Wed 2020-07-15 17:06:51 CST
如果时区不对,则需将时区修改为东八区 Asia/Shanghai
timedatectl set-timezone Asia/Shanghai
配置UTC硬件时间
# timedatectl status Local time: Wed 2020-07-15 17:07:58 CST Universal time: Wed 2020-07-15 09:07:58 UTC RTC time: Wed 2020-07-15 09:07:58 Time zone: Asia/Shanghai (CST, +0800) System clock synchronized: yes NTP service: active RTC in local TZ: yes Warning: The system is configured to read the RTC time in the local time zone. This mode cannot be fully supported. It will create various problems with time zone changes and daylight saving time adjustments. The RTC time is never updated, it relies on external facilities to maintain it. If at all possible, use RTC in UTC by calling 'timedatectl set-local-rtc 0'.
timedatectl set-local-rtc 0
服务检测命令
chronyc sources -v
chronyc sourcestats -v
chronyc -a makestep
chronyc tracking
chronyc activity
chronyc [-n] clients # -n IP
chronyc accheck $hostname
注: chronyc sources是列不出来server的话,可能是没配置dns解析(/etc/resolve.conf),或者/etc/hosts没有解析ntp服务器的域名; 如果server是ip地址 还是列不出来,那就是resolve里的nameserver连不上, 即不能连接外网,此时需注释掉nameserver
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类