目录
前言
在Linux系统中,时间服务器确保系统时间的准确和一致性,这对于日志记录、安全性、调度任务等至关重要。通过NTP或Chrony等工具,系统可以定期与可信的时间源同步,避免时间差异导致的数据不一致和调试困难,特别在分布式系统中尤为重要。
一、Chrony安装
#sudo yum -y install chrony
二、服务配置
#vi /etc/chrony.conf
pool pool.ntp.org iburst #配置ntp服务器地址
# 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.
makestep 1.0 3
# Enable kernel synchronization of the real-time clock (RTC).
rtcsync
# Allow NTP client access from local network.
allow 35.123.0.0/16 #如需放通所有则是 allow all
# Serve time even if not synchronized to a time source.
local stratum 10 #允许其他客户端从本机进行同步
#修改配置后需重启服务
systemctl restart chronyd && systemctl enable chronyd
三、测试
# chronyc sources -v
210 Number of sources = 1
.-- 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
===============================================================================
^* 114.118.7.161 1 6 61 19 -1141us[ +36ms] +/- 51ms
^* 表示连接服务器成功,通常修改地址后需要等待2-3分钟生效
四、稳定的国内外NTP服务器地址
国家授时中心 NTP 服务器(NTSC NTP Server)
ntp.ntsc.ac.cn
中国 NTP 快速授时服务(NTP ORG CN)
cn.ntp.org.cn
edu.ntp.org.cn #教育网
国际 NTP 快速授时服务(Pool NTP ORG)
pool.ntp.org
0.pool.ntp.org
1.pool.ntp.org
2.pool.ntp.org
3.pool.ntp.org
asia.pool.ntp.org
总结
Chrony时间服务器配置完成后,系统将能够可靠地与外部时间源同步,确保系统时间的准确性和稳定性,即使在网络连接不稳定的环境中,也能有效地维持时间一致性。
1121

被折叠的 条评论
为什么被折叠?



