系统配置:CentOS8时间同步

本文介绍如何在CentOS8中使用Chrony进行时间同步配置。由于CentOS8不再支持ntpd,故采用Chrony作为替代方案。文章详细介绍了Chrony的安装、配置及验证过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述

最近在CentOs8操作时间同步,却发现在CentOS8中默认已经不再支持ntpd软件包,同时也无法通过官方软件仓库安装, CentOS8上使用Chrony配置NTP服务器,用于同步时间。 它有两个程序,chrony和chronyd, chronyd是守护进程 ,chrony是一个命令行界面程序,可以用来监控chronyd的性能,并修改各种操作参数。

安装chrony

系统会默认安装并启动,如果系统不存在则需要安装此工具库。

  • 仓库中直接安装
dnf -y install chrony
  • 启动守护进程
systemctl enable –now chronyd

时间同步配置

设置时区

  • 联网的情况下一般设置时区后会通过网络同步时间
timedatectl set-timezone "Asia/Shanghai"

配置chrony.conf

  • 修改配置加入aliyun pool网络时间,也可以加入多个pool服务器
vim /etc/chrony.conf

# 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

pool 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.
makestep 1.0 3

# Enable kernel synchronization of the real-time clock (RTC).
rtcsync

# Enable hardware timestamping on all interfaces that support it.
#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

# 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

# Specify directory for log files.
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

  • 重新加载配置
systemctl restart chronyd.service

时间同步

  • 执行时间同步命令
chronyc sources -v

[root@k8smaster ~]# chronyc sources -v
210 Number of sources = 5

.-- 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

^- ntp5.flashdance.cx 2 6 377 6 +8255us[+8255us] +/- 139ms
^- 185.216.231.25 2 7 13 6 +10ms[ +10ms] +/- 98ms
^- 119.28.206.193 2 6 377 9 +1016us[+1001us] +/- 62ms
^* dns1.synet.edu.cn 2 6 377 8 -1423us[-1438us] +/- 9294us
^+ 203.107.6.88 2 6 377 7 +2107us[+2107us] +/- 17ms

验证查看时间

  • 查看当前系统时间
date
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值