首页 > 其他分享 >chrony 时间同步服务

chrony 时间同步服务

时间:2024-06-04 21:01:58浏览次数:10  
标签:chronyc 同步 服务 ntp time chrony offset root localhost


centos 7 系统默认已安装chronyd时间同步服务&已开启(ntpd服务默认是关闭的)

 

[BEGIN] 2024/6/4 20:14:16
[tang@localhost ~]$ chronyc sources
210 Number of sources = 4
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- ntp7.flashdance.cx 2 6 7 43 -14ms[ -14ms] +/- 94ms
^* ntp1.flashdance.cx 2 6 177 107 -699us[+2836us] +/- 106ms
^- makaki.miuku.net 3 6 177 42 +174ms[ +174ms] +/- 313ms
^- 139.199.214.202 2 6 265 102 +165ms[ +165ms] +/- 248ms


[tang@localhost ~]$ systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-06-04 05:10:12 PDT; 5min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Process: 753 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
Process: 677 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 694 (chronyd)
Tasks: 1
CGroup: /system.slice/chronyd.service
└─694 /usr/sbin/chronyd

[tang@localhost ~]$ chronyc sources -v
210 Number of sources = 4

.-- 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
===============================================================================
^+ ntp7.flashdance.cx 2 6 377 4 +50ms[ +50ms] +/- 152ms
^+ ntp1.flashdance.cx 2 6 377 7 +128ms[ +128ms] +/- 237ms
^+ makaki.miuku.net 3 7 337 6 +95ms[ +95ms] +/- 193ms
^* 139.199.214.202 2 6 377 132 +2911us[-6360us] +/- 53ms


[tang@localhost ~]$ date
Tue Jun 4 05:26:59 PDT 2024


[tang@localhost ~]$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
Africa/Casablanca
.....

 

[root@localhost ~]# sudo timedatectl set-timezone Asia/Shanghai
[root@localhost ~]# timedatectl
Local time: Tue 2024-06-04 20:29:09 CST
Universal time: Tue 2024-06-04 12:29:09 UTC
RTC time: Tue 2024-06-04 12:29:09
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a


[root@localhost ~]# date
Tue Jun 4 20:29:19 CST 2024

[root@localhost ~]# cat /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
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

# 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
[root@localhost ~]# chronyc tracking
Reference ID : 8BC7D6CA (139.199.214.202)
Stratum : 3
Ref time (UTC) : Tue Jun 04 12:31:00 2024
System time : 0.000245490 seconds fast of NTP time
Last offset : +0.002240096 seconds
RMS offset : 0.017738925 seconds
Frequency : 7.964 ppm slow
Residual freq : +0.520 ppm
Skew : 18.742 ppm
Root delay : 0.087588310 seconds
Root dispersion : 0.026381345 seconds
Update interval : 64.2 seconds
Leap status : Normal



[root@localhost ~]# vim /etc/chrony.conf

[root@localhost ~]# systemctl restart chrony

[root@localhost ~]# chronyc tracking
Reference ID : 00000000 ()
Stratum : 0
Ref time (UTC) : Thu Jan 01 00:00:00 1970
System time : 0.000000000 seconds slow of NTP time
Last offset : +0.000000000 seconds
RMS offset : 0.000000000 seconds
Frequency : 2.040 ppm slow
Residual freq : +0.000 ppm
Skew : 0.000 ppm
Root delay : 1.000000000 seconds
Root dispersion : 1.000000000 seconds
Update interval : 0.0 seconds
Leap status : Not synchronised

server ntp1.aliyun.com


server ntp.tencent.com

[root@localhost ~]# chronyc tracking
Reference ID : 00000000 ()
Stratum : 0
Ref time (UTC) : Thu Jan 01 00:00:00 1970
System time : 0.000000000 seconds slow of NTP time
Last offset : +0.000000000 seconds
RMS offset : 0.000000000 seconds
Frequency : 2.040 ppm slow
Residual freq : +0.000 ppm
Skew : 0.000 ppm
Root delay : 1.000000000 seconds
Root dispersion : 1.000000000 seconds
Update interval : 0.0 seconds
Leap status : Not synchronised
[root@localhost ~]# 如果System time和Last offset的值为0,表示时间同步成功。
bash: 如果System: command not found...
[root@localhost ~]# ntpdate ntp.tencent.com
4 Jun 20:42:17 ntpdate[2590]: adjust time server 106.55.184.199 offset -0.040531 sec
[root@localhost ~]# ntpdate ntp.tencent.com
4 Jun 20:42:30 ntpdate[2599]: adjust time server 106.55.184.199 offset -0.000609 sec
[root@localhost ~]# chronyc tracking
Reference ID : 6A37B8C7 (106.55.184.199)
Stratum : 3
Ref time (UTC) : Tue Jun 04 12:42:29 2024
System time : 0.000001776 seconds slow of NTP time
Last offset : +0.151495337 seconds
RMS offset : 0.151495337 seconds
Frequency : 2.040 ppm slow
Residual freq : +963.269 ppm
Skew : 12.738 ppm
Root delay : 0.403705478 seconds
Root dispersion : 0.034737572 seconds
Update interval : 0.0 seconds
Leap status : Normal
[root@localhost ~]# systemctl restart chronyd
[root@localhost ~]# chronyc tracking
Reference ID : 00000000 ()
Stratum : 0
Ref time (UTC) : Thu Jan 01 00:00:00 1970
System time : 0.000000000 seconds slow of NTP time
Last offset : +0.000000000 seconds
RMS offset : 0.000000000 seconds
Frequency : 2.040 ppm slow
Residual freq : +0.000 ppm
Skew : 0.000 ppm
Root delay : 1.000000000 seconds
Root dispersion : 1.000000000 seconds
Update interval : 0.0 seconds
Leap status : Not synchronised
[root@localhost ~]# systemctl is-enabled ntpd
disabled

[END] 2024/6/4 20:48:31

如果要配置为时间服务器
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

chronyc 命令
查看 ntp_servers
chronyc sources -v
查看 ntp_servers 状态
chronyc sourcestats -v
查看 ntp_servers 是否在线
chronyc activity -v
查看 ntp 详细信息
chronyc tracking -v
强制同步下系统时钟
chronyc -a makestep

常见时区
(1)UTC 整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2)GMT 格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的×××格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3)CST 中国标准时间 (China Standard Time)
GMT + 8 = UTC + 8 = CST
(4)DST夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时间拨快一小时,以提早日光的使用。(中国不使用)
chronyc sources 输出结果解析

M
这表示信号源的模式。^表示服务器,=表示对等方,#表示本地连接的参考时钟。
S
此列指示源的状态。
• * 表示chronyd当前同步到的源。
• + 表示可接受的信号源,与选定的信号源组合在一起。
• - 表示被合并算法排除的可接受源。
• ? 指示已失去连接性或其数据包未通过所有测试的源。它也显示在启动时,直到从中至少收集了3个样本为止。
• x 表示chronyd认为是虚假行情的时钟(即,其时间与大多数其他来源不一致)。
• 〜 表示时间似乎具有太多可变性的来源。
Name/IP address
这显示了源的名称或IP地址,或参考时钟的参考ID。
Stratum
这显示了来源的层,如其最近收到的样本中所报告的那样。层1表示一台具有本地连接的参考时钟的计算机。与第1层计算机同步的计算机位于第2层。与第2层计算机同步的计算机位于第3层,依此类推。
Poll
这显示轮询源的速率,以秒为单位的时间间隔的以2为底的对数。因此,值为6表示每64秒进行一次测量。chronyd会根据当前情况自动更改轮询速率。
Reach
这显示了源的可达性寄存器以八进制数字打印。寄存器有8位,并在每个从源接收或丢失的数据包上更新。值377表示从最后八次传输中收到了对所有用户的有效答复。
LastRx
此列显示多长时间前从来源接收到了最后一个好的样本(在下一列中显示)。未通过某些测试的测量将被忽略。通常以秒为单位。字母m,h,d或y表示分钟,小时,天或年。
Last sample
此列显示上次测量时本地时钟与源之间的偏移。方括号中的数字表示实际测得的偏移量。可以用ns(表示纳秒),us (表示微秒),ms(表示毫秒)或s(表示秒)作为后缀。方括号左侧的数字表示原始测量值,已调整为允许此后施加于本地时钟的任何摆度。
+/-指示器后面的数字表示测量中的误差范围。正偏移表示本地时钟位于源时钟之前。
[[email protected] ~]# chronyc add server 10.210.57.78
200 OK
[[email protected] ~]# 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
^- ntp1.ams1.nl.leaseweb.net 3 10 377 651 -4572us[-4572us] +/- 227ms
^- 119.29.13.98 2 9 377 17 +2553us[+2553us] +/- 26ms
^* 203.107.6.88 2 10 377 656 -1432us[-1106us] +/- 19ms
^- tock.ntp.infomaniak.ch 1 9 377 52m -16ms[ -16ms] +/- 103ms
^? 10.211.57.78 3 6 1 10 +1089us[+1089us] +/- 34ms
[[email protected] ~]# 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
^- ntp1.ams1.nl.leaseweb.net 3 10 377 843 -4572us[-4572us] +/- 227ms
^- 119.29.13.98 2 9 377 208 +2553us[+2553us] +/- 26ms
^* 203.107.6.88 2 10 377 847 -1432us[-1106us] +/- 19ms
^- tock.ntp.infomaniak.ch 1 9 377 56m -16ms[ -16ms] +/- 103ms
^- 10.211.57.78 3 6 17 6 +1225us[+1225us] +/- 37ms
上面示例中刚加入的NTP部分显示是 ?即不可达的,过了两分钟再查看状态变成了 -
————————————————

标签:chronyc,同步,服务,ntp,time,chrony,offset,root,localhost
From: https://www.cnblogs.com/arirang/p/18231701

相关文章

  • 自宿主web服务器搭建记录
    建立3个项目,分别是类库WebSite、控制台TestWebSite、win服务WinService,目标框架均为.NETFramework4.8.1。其中控制台方便开发调试,win服务作为宿主服务,类库为自定义webservice的主体代码。TestWebSite和WinService引用nuget包 Microsoft.Owin.Host.HttpListener 4.2.2,不然......
  • 服务器安装centos系统报错
    安装centos报错:dracut-initqueue:warning:dracut-initqueuetimeout-startingtimeoutscripts解决方法U盘启动报错信息 查看U盘的对应分区 重启电脑按e进入编辑模式将:vmlinuzinitrd=initrd.imginst.stage2=hd:LABEL=CentOS\x207\x20x86_64rd.live.checkquiet改......
  • UDP练习题——实现将自己加入到多播组中并等待服务器发送数据包
    设计程序,要求程序可以加入到一个多播组中并等待服务器发送,数据包,并且程序还需要具有发送功能,如果收到数据包则把消息内容输出到终端,消息内容格,式「消息来源IP消息时间1:消息内容多播地址和端口号/*************************************************************************......
  • Linux服务器磁盘清理与Inode节点清理指南
    Linux服务器磁盘清理与Inode节点清理指南在管理Linux服务器时,定期清理磁盘空间和inode节点是维护系统性能和稳定性的重要任务。磁盘空间清理可确保系统不会因为空间不足而出现问题,而inode节点清理则有助于避免系统因过多小文件而性能下降。本指南将介绍如何执行这些清理操......
  • 通用漏洞-crlf&url重定向&拒绝服务攻击
    1.crlf注入1.1原理crlf是在数据包头头部采取一些回车加换行的操作,把自己的其他代码放到数据包中去覆盖掉原本的数据的方法,常配合xss漏洞使用,这个漏洞本身的造成危害并不严重,CRLFInjection又叫HTTP响应拆分/截断(HTTPResponseSplitting)简称HRS。CRLF是CR和LF两个字符的拼接......
  • docker启动后端服务
    docker启动后端服务1.创建项目文件夹一般情况下项目文件夹创建是在home文件夹下建立。如果项目中存在需要进行查看的文件,可以通过docker中挂载的形式将文件挂载到宿主机对应文件夹中2.编写DockerFile文件#设置基础镜像(只需要java运行时环境,如果镜像中无此镜像,则会......
  • adapter1.1.5不能同步数据到ES6
    问题:如果修改数据库某张表的某个字段时出现如下日志:2024-06-0415:32:18.177[pool-2-thread-1]DEBUGc.a.o.canal.client.adapter.es.core.service.ESSyncService-DML:{"data":null,"database":"aws","destination":"CANAL_GOODS","e......
  • 2024年公共事务管理与社会服务国际会议(ICPAMSS2024)
    2024年公共事务管理与社会服务国际会议(ICPAMSS2024)会议简介2024国际公共事务管理与社会服务会议(ICPAMSS2024)将在广州隆重举行。本次盛会诚挚邀请来自世界各地的公共事务管理和社会服务领域的专家、学者和从业者齐聚一堂,探索行业发展前沿,分享实践经验,推动理论创新。会议将......
  • 操作系统·同步问题
    经典同步问题1.生产者消费者问题一组生产者进程(Producer)一组消费者进程(Consumer)共享初始为空大小为n的缓冲区(Buffer)semaphoremutex=1;//mutexsemaphoreempty=n;//buffersemaphorefull=0;//fullProducer(){ while(1){ Produce(); P(m......
  • 基于JSP的农产品供销服务系统
    你好呀,我是计算机学长猫哥!如果有需求可以文末加我。开发语言:Java数据库:MySQL技术:JSP技术工具:IDEA/Eclipse、Navicat、Maven系统展示首页用户注册农产品管理订单管理摘要本文主要介绍了农产品供销服务系统的设计和实现。系统采用JSP技术,基于B/S结构,使用MySQL......