Linux通过chrony进行时间同步

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
### 回答1: Linux中的chrony时间同步命令是"chronyc"。它可以用来管理和监控chrony时间同步服务,包括手动同步时间、查看同步状态、修改配置等操作。常用的chronyc命令包括:chronyc sources、chronyc tracking、chronyc makestep等。 ### 回答2: Chrony是一款用于Linux操作系统的时间同步软件。它使用以太网,无线电(wifi),PPPoE和IPv6等多种协议来同步系统和本地时钟,从而保证系统的时间准确性。下面我们将详细介绍使用Chrony进行时间同步的操作步骤。 首先,需要安装Chrony软件。不同发行版的Linux安装命令略有不同,这里以Debian/Ubuntu为例: ``` sudo apt-get install chrony ``` 安装完成后,打开Chrony配置文件/etc/chrony/chrony.conf。如果要同步到局域网内的时间服务器,可以将以下内容添加到配置文件中: ``` server time.server.com iburst ``` 其中"time.server.com"为你要同步的时间服务器的地址,"iburst"是用于快速同步的标志。 如果Chrony作为系统的唯一时间同步软件,在配置文件中将以下内容打开: ``` # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #pool 2.debian.pool.ntp.org offline iburst ``` 在启动Chrony前,需要先关闭系统自带的时间同步服务。不同发行版的关闭命令略有不同,这里以Debian/Ubuntu为例: ``` sudo timedatectl set-ntp off ``` 最后,重新启动Chrony服务: ``` sudo systemctl restart chrony ``` 稍等片刻,系统的时间就会被同步到上面设置的时间服务器时间了。如果需要检查Chrony是否正在运行和同步,可以运行以下命令: ``` sudo chronyc tracking ``` 需要注意的是,Chrony需要在/root/.chrony-keys文件中记录每个远程时间服务器的密钥,以保护同步信息的安全性。如果需要更多的Chrony配置选项,可以查看Chrony官方文档。 ### 回答3: Linux系统中,时间同步是非常关键的操作,如果系统时间不准确,会导致很多问题,比如日志记录不准确、排查问题困难等。为了保证系统时间的准确性,Linux系统提供了多种时间同步工具,其中 chrony 是一种非常常用的时间同步工具。 chrony 是一种实现 NTP 协议的时间同步软件,它与传统的 NTP(Network Time Protocol)相比,其优点是更加适合被部署于当今广泛存在的不同类型的网络中。它具有快速同步、稳定性和安全等特点。 使用 chrony 进行时间同步的步骤如下: 1. 安装 chrony 在大多数 Linux 发行版中,chrony 已经预装了,如果没有,则需要使用系统包管理器进行安装。 2. 配置 chrony chrony 的默认配置文件位于 /etc/chrony.conf。在该文件中,你可以修改多种设置,如要使用的 NTP 服务器等。修改完成后,保存并关闭该文件。 3. 启动 chrony 在大多数 Linux 发行版中,chrony 已经完成了自动启动,如果没有,则需要手动启动。可以使用以下命令完成启动: sudo systemctl start chronyd 4. 验证同步情况 可以使用以下命令验证 chrony 是否正在同步系统时间chronyc tracking 该命令会显示系统时间与 NTP 服务器时间之间的偏差以及同步状态。 使用 chrony 进行时间同步,可以使系统时间更加准确,从而保证系统功能的正常运行。另外,在某些特殊场景下,比如高并发的服务环境下,时间同步更是关键。因此,我们必须保证在 Linux 系统中使用时间同步软件的正确性,并进行配置调整和监测跟踪,保证服务应用的数据一致性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

坐公交也用券

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

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

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

打赏作者

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

抵扣说明:

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

余额充值