chrony服务器
时间有什么作用?约定干什么事情,会出问题,双方约定会达成一旦有一方的时间不准确,约定都会达不成不联网,计算机运行一个月,你的计算机就会和标准的时间差一两分钟通常情况下,硬件时间的运行,依赖于 BIOS 上的实时时钟( RTC )芯片。但是这种时钟芯片由于内部精度限制,每跳 一秒就会产生微小的偏差,长时间运行后,这些微小偏差会累积,导致肉眼可见的时间偏差。在系统开机时,会自动从BIOS中获取硬件时间,并将其设置为系统时间。然而,如果公司内部的各个设备时间不一致,就会导致数据记录混乱、监控时间、系统日志不准确等问题软件和软件之间沟通用网络协议 NTP

一、原理
Chrony 由两个程序组成,分别是 chronyd 和 chronyc 。
chronyd 是一个后台运行的守护进程,用于调整内核中运行的系统时钟和时钟服务器同步。它确定计算机 增减时间的比率,并对此进行补偿。chronyc 提供了一个用户界面,用于监控性能并进行多样化的配置。它可以在 chronyd 实例控制的计算机 上工作,也可以在一台不同的远程计算机上工作。
传输层协议 应用层协议 端口号 --- 抓包
date
timedatectl
[root@localhost ~]# date -s "12:00 2012-05-12"
2012年 05月 12日 星期六 12:00:00 CST
[root@localhost ~]# date
2012年 05月 12日 星期六 12:00:04 CST
[root@localhost ~]# timedatectl
Local time: 六 2012-05-12 12:00:16 CST
Universal time: 六 2012-05-12 04:00:16 UTC
RTC time: 一 2024-10-14 11:04:36
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
[root@localhost ~]# systemctl restart chronyd
[root@localhost ~]# chronyc sources
二、安装与配置
[root@localhost ~]# yum install -y chrony
[root@localhost ~]# systemctl enable --now chronyd
[root@server1 ~]# cat /etc/chrony.conf
#设置时间服务器的服务端名字
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
# Allow NTP client access from local network.
#设置允许哪个客户端可以访问该服务器
#allow 192.168.0.0/16
三、实验
1、同步公共时间服务器
[root@openEuler-2 ~]# vim /etc/chrony.conf
#此处服务器可以写国内的
server ntp.aliyun.com iburst
[root@openEuler-2 ~]# systemctl restart chronyd#两种验证方式
[root@openEuler-2 ~]# chronyc sources -v
[root@openEuler-2 ~]# timedatectl
下图表示系统时钟已同步
^表示是时间服务器(server ),*表示是当前最佳时间源
2、同步局域网时间服务器
#客户端操作:
0、安装软件
1、配置
2、使配置生效
3、查看验证
#服务端操作
1、配置时间服务器:允许谁来同步
2、使配置生效:重启服务
3、配置防火墙:放行对应时间服务的防火墙123端口号 或者 关闭防火墙
#需要两个服务器,一个服务端(服务端ip:192.168.168.253),一个客户端测试(客户端主机ip网段为
192.168.168.0/24)#服务端(192.168.183.11)的配置
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]#vim /etc/chrony.conf
server ntp.aliyun.com iburst
allow 192.168.183.12/24
#allow 0.0.0.0/0
[root@localhost ~]# systemctl restart chronyd#客户端(192.168.183.12)访问,先ping时间服务器
[root@localhost ~]# ping 192.168.183.11
[root@localhost ~]# vim /etc/chrony.conf
server 192.168.168.11 iburst
[root@localhost ~]# systemctl restart chronyd
[root@localhost ~]# chronyc sources -v