9
6月
2020
“ Linux中的Baith时间,NTP协议上计算机时钟的同步”
10:18

“ Linux中的Baith时间,NTP协议上计算机时钟的同步”

9 6月 2020 10:18

安装分配时,选择系统的小时腰带。 将来,您可以将时间(NTP协议)的同步配置为更准确的时间,并组织有关其他时区的信息。 例如,在莫斯科早晨,在美国中部,一个深夜。 本文介绍了如何改善时间同步,设置一个小时的皮带,并在每个屏幕上占用其他时区。

介绍

在Linux中的时间服务的工作是可以在两个版本中彼此排除的两个版本中进行的:

  • 客户端(将该PC的时间与其他精确的时间服务器同步)
  • 服务器(用于向本地网络中的其他计算机分发准确的时间)。

我正在考虑当时的客户服务。

目标:
a)在本地计算机上获得很高的时间精度(小于0.5秒)
b)在各个时区的时间屏幕上实现输出。

行动计划:

  1. 安装
  2. 发射
  3. 考试

包括NTP客户端

为了花时间通过网络同步,您需要安装NTP客户端和NTPDATE实用程序:

su -
apt-get update
apt install ntp

手表皮带的指示

首先,您需要检查系统中设置哪个时区。

ls -l /etc/localtime

对于莫斯科,圣彼得堡和俄罗斯联邦的欧洲部分,将显示一个链接:

/etc/localtime -> /usr/share/zoneinfo/Europe/Moscow

这是对的。 但是,您可以将计算机重新配置为另一个时区(如果PC已移至另一个区域)。

在Linux Mint中,时钟程序称为 time-admin (必须以超级用户权限运行 su )。 另外,此程序在“开始”菜单 - “参数” - “日期和时间”中可用。
TI程序me-adm在

可以使用命令行执行时钟腰带的更改。 首先,我们发现例如在欧洲存在什么时区:

ls /usr/share/zoneinfo/Europe/

Amsterdam Busingen Kiev Monaco Sarajevo Vaduz
Andorra Chisinau Kirov Moscow Saratov Vatican
Astrakhan Copenhagen Kyiv Nicosia Simferopol Vienna
Athens Dublin Lisbon Oslo Skopje Vilnius
Belfast Gibraltar Ljubljana Paris Sofia Volgograd
Belgrade Guernsey London Podgorica Stockholm Warsaw
Berlin Helsinki Luxembourg Prague Tallinn Zagreb
_Bratislava Isle_ofMan Madrid Riga Tirane Zaporozhye
Brussels Istanbul Malta Rome Tiraspol Zurich
Bucharest Jersey Mariehamn Samara Ulyanovsk
_Budapest Kaliningrad Minsk SanMarino Uzhgorod

请点击明斯克的软符号链接(底漆):

让我们看看当前时区

ls -l /etc/localtime

查找文本“/etc/localtime -> /usr/share/zoneinfo/Europe/Moscow

男士手表带,底漆,明斯克(底漆的一部分):

sudo ln -sf /usr/share/zoneinfo/Europe/Minsk /etc/localtime

时间设置

对于客户端NTP的工作,需要条件:配置文件的存在/ETC/NTP.CONF
启动客户端NTP并直接启动客户端的权限。

  1. 配置文件/etc/ntp.conf

    driftfile /var/lib/ntp/ntp.drift
    leapfile /usr/share/zoneinfo/leap-seconds.list
    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable
    pool 0.ubuntu.pool.ntp.org iburst
    pool 1.ubuntu.pool.ntp.org iburst
    pool 2.ubuntu.pool.ntp.org iburst
    pool 3.ubuntu.pool.ntp.org iburst
    pool ntp.ubuntu.com
    restrict -4 default kod notrap nomodify nopeer noquery limited
    restrict -6 default kod notrap nomodify nopeer noquery limited
    restrict 127.0.0.1
    restrict ::1
    restrict source notrap nomodify noquery

  2. 默认情况下允许启动NTP客户端服务。

您可以,但不一定给出命令

 systemctl enable ntp
 systemctl start ntp
 systemctl status ntp

为了使服务重新阅读更新的配置(如果您编辑/etc/ntp.conf文件),则需要执行

sudo systemctl restart ntp

观察时间同步客户

ntpq -pw

将显示一个NTP服务器列表,客户端执行时间同步。 (我们必须等待程序的输出结束)。

如何找出本地计算机和远程时间服务器的时间的偏差

使用NTPQ实用程序。

或时钟

su -
apt-get update
apt install iputils-clockdiff

我们了解时间与另一台计算机-NTP服务器的偏差:

sudo clockdiff 130.149.17.21

或者

sudo clockdiff 1.ru.pool.ntp.org

可以看出,偏差,即PC的不准确性为34毫秒:

..................................................
host=130.149.17.21 rtt=34(0)ms/34ms delta=-1ms/-1ms Tue Jun 9 11:38:44 2020

与另一台服务器进行比较时,情况是相同的,偏差为35毫秒:

clockdiff 91.206.16.3

..................................................
host=91.206.16.3 rtt=35(0)ms/35ms delta=0ms/0ms Tue Jun 9 11:44:57 2020

需要注意的是,clockdiff 不考虑网络延迟(ping),它只允许您与另一台计算机比较时间,而不考虑网络中数据包的延迟。

命令显示偏差的更准确值

ntpq -p

或者
ntpq -pw

在几毫秒中已经看到差异的地方(偏移 + - 抖动)。

找出时间偏差的另一种方法

https://time.is

世界时间输出到屏幕

Xfce 桌面环境中的 Global Time 应用程序可让您创建一个包含多个时区时间的时钟。
安装 GlobalTime 应用程序:

sudo apt install xfce4-datetime-plugin

资料来源:



相关出版物