菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
216
0

ntp和chrony

原创
05/13 14:22
阅读数 87194

17-29-33-YqZSWW

chrony 简介

chrony 是 RedHat 开发的,它是网络时间协议(NTP)的另一种实现;
RHEL/CentOS 7.x 的默认时间同步工具,在 CentOS 6.8之后也添加上了这个工具;
chrony 可以同时做为 ntp 服务的客户端和服务端;安装完后有两个程序 chronyd、chronyc:
chronyd 是一个 daemon 守护进程,chronyc 是用来监控 chronyd 性能和配置参数的命令行工具。

ntp pool

?pool.ntp.org

ntp 配置文件

/etc/ntp.conf

driftfile  /var/lib/ntp/drift
pidfile    /var/run/ntpd.pid
logfile    /var/log/ntp.log

# Access Control Support
restrict    default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap nopeer noquery
restrict 172.16.0.0 mask 255.240.0.0 nomodify notrap nopeer noquery
restrict 100.64.0.0 mask 255.192.0.0 nomodify notrap nopeer noquery
restrict 10.0.0.0 mask 255.0.0.0 nomodify notrap nopeer noquery


# local clock
server 127.127.1.0
fudge  127.127.1.0 stratum 10

chrony 配置文件

/etc/chrony.conf

# 时钟服务器地址
server ntp1.aliyun.com

# 指定包含 NTP 身份验证密钥的文件。
local stratum 8

# 指令设置当chronyd从可用源中选择同步源时,每个层应该添加多少距离到同步距离。
# 默认情况下,CentOS中设置为0,让chronyd在选择源时忽略源的层级
stratumweight 0

# chronyd程序的主要行为之一,就是根据实际时间计算出计算机增减时间的比率,将它记录到一个文件中是最合理的,它会在重启后为系统时钟作出补偿。
# 甚至可能的话,会从时钟服务器获得较好的估值。
driftfile /var/lib/chrony/drift

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

# 如果系统时钟的偏移量大于10秒,则允许系统时钟在前三次更新中步进。
makestep 10 3

# allow / deny - 这里你可以指定一台主机、子网,或者网络以允许或拒绝NTP连接到扮演时钟服务器的机器。
allow all

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

# noclientlog

logchange 0.5

logdir /var/log/chrony
log measurements statistics tracking

chronyc 命令行工具

# 检查NTP访问是否对特定主机可用
chronyc accheck

# 查看 ntp_servers
chronyc sources

# 查看 ntp_servers 状态
chronyc sourcestats

# 查看 ntp_servers 是否在线
chronyc activity

# 查看 ntp 详细信息
chronyc tracking

# 报告已访问到服务器的客户端
chronyc clients: 

修改时区

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

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

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

# 修改日期时间(可以只修改其中一个)
timedatectl set-time "2020-04-11 16:51:10"

# 开启 NTP
timedatectl set-ntp true/flase

发表评论

0/200
216 点赞
0 评论
收藏
为你推荐 换一批