Linux通过chrony进行时间同步

本文介绍了如何在最新版Linux中用Chrony替代ntpdate进行时间同步。首先,通过apt安装Chrony,然后配置文件以使用腾讯云的时间服务器。接着,设置时区为亚洲/上海,并启用ntp同步。最后,重启服务并使用chronyc sources命令验证时间同步。

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

1、简单介绍

在最新的Linux中,已经将ntpdate抛弃,转向了chrony,本篇就对这个新的chrony时间服务进行简单的演示操作

2、服务安装

2.1、安装服务

安装命令无脑install即可

apt install chrony

2.2、参数配置

安装完成之后,会有默认的时间服务器地址,但是由于你懂的,所以我们要更换一下,方法如下:
依次执行下面的命令即可

sed -i 's@server@#server@g' /etc/chrony.conf
echo -e "server ntpupdate.tencentyun.com iburst" >> /etc/chrony.conf

由于我的本身就是腾讯云的时间服务器,所以就不改了,配置如下:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# servers
server ntpupdate.tencentyun.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

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

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

3、开始同步

3.1、设置时区

timedatectl set-timezone Asia/Shanghai

3.2、开启ntp同步

timedatectl set-ntp yes

3.3、开始同步

先重启服务

systemctl restart chrony

然后同步

chronyc sources

过程:

root@l:/data/liu/git/zgj_toutiao# systemctl restart chrony
root@l:/data/liu/git/zgj_toutiao# chronyc sources
210 Number of sources = 5
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^? 169.254.0.79                  2   6     1     2    -26us[  -26us] +/-   22ms
^? 169.254.0.80                  2   6     1     1  +1309ns[+1309ns] +/-   26ms
^? 169.254.0.81                  2   6     1     1   -103us[ -103us] +/-   28ms
^? 169.254.0.82                  2   6     1     1    +62us[  +62us] +/-   39ms
^? 169.254.0.83                  2   6     1     1   -356us[ -356us] +/-   37ms
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值