温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux中怎么使用Chrony进行时间同步

发布时间:2022-01-26 17:40:17 来源:亿速云 阅读:586 作者:iii 栏目:开发技术

这篇文章主要介绍了Linux中怎么使用Chrony进行时间同步的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Linux中怎么使用Chrony进行时间同步文章都会有所收获,下面我们一起来看看吧。

Chrony简介:

Chrony是NTP(Network Time Protocol,网络时间协议,服务器时间同步的一种协议)的另一种实现,与ntpd不同,它可以更快且更准确地同步系统时钟,最大程度的减少时间和频率误差。

在CentOS6中,默认是使用ntpd来同步时间的,但ntpd同步时间并不理想,有可能需要数小时来同步时间。而且ntp也已经很老了。所以在Centos7中换成了chrony来实现时间同步。chrony并且兼容ntpd监听在udp123端口上,自己则监听在udp的323端口上。

如果在chrony配置文件中指定了ntp服务器的地址,那么chrony就是一台客户端,会去同步ntp服务器的时间,如果在chrony配置了允许某些客户端来向自己同步时间,则chrony也充当了一台服务器,所以,安装了chrony即可充当客户端也可以充当服务端。一般我们只需要做客户端就好,不需要对外提供时间同步功能。

使用方式

1)系统默认已经安装,如未安装,请执行以下命令安装:yum install chrony -y

2)启动并加入开机自启动systemctl enable chronyd.servicesystemctl start chronyd.service

3)查看状态systemctl status chronyd.service

4)配置文件详解cat /etc/chrony.conf

# 使用pool.ntp.org项目中的公共服务器。以server开始,理论上你想添加多少时间服务器都可以。# Please consider joining the pool (http://www.pool.ntp.org/join.html).server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburst

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

# chronyd根据需求减慢或加速时间调整,# 在某些情况下系统时钟可能漂移过快,导致时间调整用时过长。# 该指令强制chronyd调整时期,大于某个阀值时步进调整系统时钟。# 只有在因chronyd启动时间超过指定的限制时(可使用负值来禁用限制)没有更多时钟更新时才生效。makestep 1.0 3

# 将启用一个内核模式,在该模式中,系统时间每11分钟会拷贝到实时时钟(RTC)。rtcsync

# Enable hardware timestamping on all interfaces that support it.# 通过使用hwtimestamp指令启用硬件时间戳#hwtimestamp eth0#hwtimestamp eth2#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust# the system clock.#minsources 2

# 指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器#allow 192.168.0.0/16#deny 192.168/16

# Serve time even if not synchronized to a time source.local stratum 10

# 指定包含NTP验证密钥的文件。#keyfile /etc/chrony.keys

# 指定日志文件的目录。logdir /var/log/chrony

# Select which information is logged.#log measurements statistics tracking

5)设置时区查看当前系统时区$ timedatectlLocal time: Fri 2018-2-29 13:31:04 CSTUniversal time: Fri 2018-2-29 05:31:04 UTCRTC time: Fri 2018-2-29 08:17:20Time zone: Asia/Shanghai (CST, +0800)NTP enabled: yesNTP synchronized: yesRTC in local TZ: noDST active: n/a

如果你当前的时区不正确,请按照以下操作设置。

查看所有可用的时区:

$ timedatectl list-timezones筛选式查看在亚洲S开的上海可用时区:

$ timedatectl list-timezones | grep -E “Asia/S.*”Asia/SakhalinAsia/SamarkandAsia/SeoulAsia/ShanghaiAsia/SingaporeAsia/Srednekolymsk

设置当前系统为Asia/Shanghai上海时区:$ timedatectl set-timezone Asia/Shanghai

设置完时区后,强制同步下系统时钟:$ chronyc -a makestep200 OK

服务器端和客户端修改/etc/chrony.conf配置文件,添加server xxxx.xx.xx.xx iburst

6)在客户端执行chronyc sources //刷新一下同步情况chronyc sources -v //查看时间同步源的状态netstat -antpul | grep chron //查看该服务端口,并开通相应端口

关于“Linux中怎么使用Chrony进行时间同步”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Linux中怎么使用Chrony进行时间同步”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI