快速了解chrony服务器

1.1chrony的简单介绍

Chrony是一个开源自由的网络时间协议 NTP 的客户端和服务器软软件。它能让计算机保持系统时钟与时钟服务器(NTP)同步,因此让你的计算机保持精确的时间,Chrony也可以作为服务端软件为其他计算机提供时间同步服务。

Chrony由两个程序组成,分别是chronyd和chronyc

chronyd是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机增减时间的比率,并对此进行补偿。

chronyc提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在chronyd实例控制的计算机上工作,也可以在一台不同的远程计算机上工作。

NTP 是网络时间协议(Network Time Protocol)的简称,通过 udp 123 端口进行网络时钟同步。

RHEL7中默认使用chrony作为时间服务器,也支持NTP,需要额外安装。

NTP与chrony不能同时存在,只能用其中一个

1.2安装与配置

#yum -y install chrony

#systemctl enable chronyd

#systemctl start chronyd

Chrony的配置文件是/etc/chrony.conf

# 使用 pool.ntp.org 项目中的公共服务器。以server开,理论上想添加多少时间服务器都可以。

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.pool.ntp.org iburst

server 3.centos.pool.ntp.org iburst

# 根据实际时间计算出服务器增减时间的比率,然后记录到一个文件中,在系统重启后为系统做出最佳时间补偿调整。

driftfile /var/lib/chrony/drift

# 如果系统时钟的偏移量大于1秒,则允许系统时钟在前三次更新中步进。

# Allow the system clock to be stepped in the first three updates if its offset is larger than 1 second.

makestep 1.0 3

# 启用实时时钟(RTC)的内核同步。

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

rtcsync

# 通过使用 hwtimestamp 指令启用硬件时间戳

# 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

# 指定 NTP 客户端地址,以允许或拒绝连接到扮演时钟服务器的机器

# 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

# 指定包含 NTP 身份验证密钥的文件。

# 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

1.3同步网络时间服务器

授时中心

210.72.145.44 国家授时中心

ntp.aliyun.com 阿里云

s1a.time.edu.cn 北京邮电大学

s1b.time.edu.cn 清华大学

s1c.time.edu.cn 北京大学

s1d.time.edu.cn 东南大学

s1e.time.edu.cn 清华大学

s2a.time.edu.cn 清华大学

s2b.time.edu.cn 清华大学

s2c.time.edu.cn 北京邮电大学

s2d.time.edu.cn 西南地区网络中心

s2e.time.edu.cn 西北地区网络中心

s2f.time.edu.cn 东北地区网络中心

s2g.time.edu.cn 华东南地区网络中心

s2h.time.edu.cn 四川大学网络管理中心

s2j.time.edu.cn 大连理工大学网络中心

s2k.time.edu.cn CERNET桂林主节点

s2m.time.edu.cn 北京大学

ntp.sjtu.edu.cn 202.120.2.101 上海交通大学

chrony.conf 修改两处

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

server s1a.time.edu.cn iburst

server ntp.aliyun.com iburst

# Allow NTP client access from local network.

设置开机启动,重启服务

systemctl enable chronyd

systemctl restart chronyd

# 查看时间同步状态

timedatectl status

# 开启网络时间同步

timedatectl set-ntp true

1.4 配置时间服务器

chrony.conf 修改两处

allow 192.168.143.0/24

local stratum 10

设置开机启动,重启服务

systemctl enable chronyd

systemctl restart chronyd

客户端主机查看时间同步状态

vim /etc/chrony.conf

server 192.168.143.111

systemctl restart chronyd

#timedatectl status

开启网络时间同步

timedatectl set-ntp true

1.5 chronyc 命令

查看 ntp_servers

chronyc sources -v

查看 ntp_servers 状态

chronyc sourcestats -v

查看 ntp_servers 是否在线

chronyc activity -v

查看 ntp 详细信息

chronyc tracking -v

强制同步下系统时钟

chronyc -a makestep

1.6练习

a: 第一台机器从阿里云同步时间

第二台机器从第一台机器同步时间

b: 第一台服务器使用系统时间作为第二台服务器的时钟源, 第一台服务器层级设置为6,

a.第一台机器

打开chrony服务器配置文件

进入/etc/chrony.conf文件

vim /etc/chrony.conf

对/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

server ntp.aliyun.com iburst //阿里云授时服务器

# Record the rate at which the system clock gains/losses time.

driftfile /var/lib/chrony/drift

......

第二台机器

进入/etc/chrony.conf文件

vim /etc/chrony.conf

对/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.rhel.pool.ntp.org iburst

server 192.168.25.138 iburst

# Record the rate at which the system clock gains/losses time.

driftfile /var/lib/chrony/drift

重启服务:

查看

第一台机器

第二台机器

b

两台机器进入/etc/chrony.conf文件

vim /etc/chrony.conf

进入文件后修改红色字体部分

# Serve time even if not synchronized to a time source.

local stratum 6

在第二台机器上查看

[root@node1 ~]# chronyc tracking

Reference ID : C0A8198A (192.168.25.138)

Stratum : 7 //第一台机器的层数为6,则来到第二台就+1

Ref time (UTC) : Thu Jan 05 13:25:46 2023

System time : 0.000456727 seconds slow of NTP time

Last offset : -0.000529833 seconds

RMS offset : 0.000635103 seconds

Frequency : 2.840 ppm slow

Residual freq : -0.529 ppm

Skew : 10.166 ppm

Root delay : 0.000889935 seconds

Root dispersion : 0.000300327 seconds

Update interval : 64.3 seconds

Leap status : Normal

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 我可以回答这个问题。测试chrony服务器的连通性需要使用chronyc命令,通过输入"chronyc tracking"命令来查看chrony服务器的状态和连通性信息。如果显示结果中的状态为"Unreach"或"Timeout",则表示无法连接到chrony服务器。可以尝试通过检查网络连接或者修改chrony服务器设置来解决连接问题。 ### 回答2: Chrony是一种用于网络时间同步的开源软件,它可以作为NTP(网络时间协议)的客户端或服务器。为了测试Chrony服务器的连通性,我们可以执行以下步骤: 首先,确保Chrony服务器已经安装和配置。可以使用以下命令检查Chrony是否已安装: ``` chronyc --version ``` 如果Chrony未安装,则可以使用适合您操作系统的包管理器进行安装。 接下来,我们需要确认Chrony服务器正在运行。可以使用以下命令检查Chrony是否正在运行: ``` systemctl status chronyd ``` 如果Chrony未运行,则可以使用以下命令启动Chrony服务器: ``` systemctl start chronyd ``` 一旦确认Chrony服务器正在运行,我们可以使用以下命令测试其连通性: ``` chronyc sources -v ``` 该命令将向Chrony服务器发送查询请求,并显示与服务器进行同步的时间源。如果能够成功连接到Chrony服务器,并显示同步的时间源,那么表示Chrony服务器的连通性正常。 除了使用命令行工具进行测试之外,我们还可以通过检查Chrony服务器的配置文件来确认其连通性。Chrony服务器的配置文件通常位于`/etc/chrony.conf`,我们可以打开该文件并查看其中的服务器配置,确认是否正确配置了可访问和同步时间的服务器地址。 总之,要测试Chrony服务器的连通性,我们可以使用命令行工具或检查配置文件来确认服务器是否正在运行,并能够与时间源进行同步。 ### 回答3: Chrony是一款精确的网络时间同步工具,可以帮助服务器保持时间的精确性。为了测试一个可用的Chrony服务器的连通性,我们可以采取以下步骤: 首先,在要测试的服务器上安装Chrony软件。 然后,使用`chronyc sources -v`命令查看Chrony服务器的源列表,确认可用的时间服务器。该命令还将提供服务器的IP地址以及与服务器的连接状态。 接下来,使用`ping`命令测试服务器的IP地址,以确保网络连接正常。 连接到Chrony服务器。在命令行中输入`chronyc sources -v -a`。此命令将显示所有已连接到Chrony服务器的时间源,并且每个时间源都有不同的标识符和状态。 通过查看每个时间源的状态,我们可以确定与Chrony服务器的连接是否成功。状态的不同标志着连接的状态,如INIT、AUTH、CANDIDATE、SELECT和ACTIVE。 我们还可以查看时间源的纪录来判断它们的稳定性。这可以通过`chronyc sourcestats`命令来实现,该命令将显示每个时间源的性能统计数据,如延迟、偏差和钟差。 最后,我们可以使用`chronyc tracking`命令来查看与Chrony服务器同步的情况。该命令将提供与系统时钟的比较,显示当前的偏差和频率调整。 通过以上步骤,我们可以测试Chrony服务器的连通性,并确保它能够提供准确和稳定的时间。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

殇ベ生

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

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

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

打赏作者

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

抵扣说明:

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

余额充值