替代 Ntp ! Centos7 时间同步服务 Chrony 详解

戳下方名片,关注并星标

回复“1024”获取2TB学习资源!

👉体系化学习:运维工程师打怪升级进阶之路 4.0

—   特色专栏  —

MySQL / PostgreSQL / MongoDB

ElasticSearch / Hadoop / Redis

Kubernetes / Docker / DevOps

Kafka / RabbitMQ / Zookeeper 

监控平台 / 应用与服务 / 集群管理

Nginx / Git / Tools OpenStack

大家好,我是民工哥!

chrony 是网络时间协议(NTP)的通用实现。

22bad3517d2d7bfeeefc962f82ccebca.jpeg

chrony 包含两个程序:

  • chronyd 是一个可以在启动时启动的守护程序。

  • chronyc 是一个命令行界面程序,用于监视 chronyd 的性能并在运行时更改各种操作参数。

与其它时间同步软件的对比:

4be6c9952f2a123ed97f4a94596cc2c7.png

安装与配置

yum -y install chrony

systemctl enable chronyd
systemctl start chronyd
vim /etc/chrony.conf

#chrony.conf 默认配置

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

# 如果系统时钟的偏移量大于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

使用

服务端配置
#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.
allow 192.168.8.0/24

开启同步

systemctl enable chronyd
systemctl restart chronyd

# 查看时间同步状态
timedatectl status
# 开启网络时间同步
timedatectl set-ntp true
客户端配置
#chrony.conf 修改两处

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 192.168.8.5 iburst

# Allow NTP client access from local network.
allow 192.168.8.5

开启同步

systemctl enable chronyd
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

修改时区

# 查看日期时间、时区及 NTP 状态
timedatectl

# 查看时区列表
timedatectl list-timezones
timedatectl list-timezones |  grep  -E "Asia/S.*"

# 修改时区
timedatectl set-timezone Asia/Shanghai

# 修改日期时间(可以只修改其中一个)
timedatectl set-time "2019-09-19 15:50:20"

# 开启 NTP
timedatectl set-ntp true/flase
4ba863403ff14ec9d4f31e9ddb8989e6.png

链接:https://cnblogs.com/zhangmingcheng/p/14135919.html

👍 如果你喜欢这篇文章,请点赞并分享给你的朋友!

公众号读者专属技术群

构建高质量的技术交流社群,欢迎从事后端开发、运维技术进群(备注岗位,已在技术交流群的请勿重复添加微信好友)。主要以技术交流、内推、行业探讨为主,请文明发言。广告人士勿入,切勿轻信私聊,防止被骗。

扫码加我好友,拉你进群

357d6f2c44f9f587d9c066e2d5bf5577.jpeg

60dee6cd59533ee58a43ad8cc677304f.gif

大规模裁员:人数超过千人,两栋大厦几乎被搬空

卸载VMware、VirtualBox,来试试这款虚拟机软件

微软总裁确认!将 700 多名中国员工移居海外

Windows爆出核弹级漏洞!Win7-Win11全沦陷

突发!OpenAI宣布终止对中国提供API服务

Nginx 服务器 Linux 内核参数优化详解

网传喜马拉雅将裁员20%,或为冲刺IPO

团队准备解散了。。。

聊一聊当今 IT 行业的乱象!

2024 年华为正式员工薪酬待遇、年终奖曝光!

CentOS 大限将至!你的替代方案准备好了吗?

ed19b4500797c9fddddcefc89e1ef8b6.png

PS:因为公众号平台更改了推送规则,如果不想错过内容,记得读完点一下在看,加个星标,这样每次新文章推送才会第一时间出现在你的订阅列表里。点在看支持我们吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值