实验:Chrony时间同步

椰子ya Linux 2020-09-12

chrony 是网络时间协议 NTP 的客户端和服务器软件

作者:橡皮24
链接:https://www.jianshu.com/p/81b1408ffafd
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

server端
1、安装Chrony

rpm -qa | grep Chrony
yum search Chrony
yum -y install chrony.x86_64

2、查看主配置文件

cat /etc/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).
pool 2.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

# Get TAI-UTC offset and leap seconds from the system tz database.
leapsectz right/UTC

# 指定日志文件的目录。
# Specify directory for log files.
logdir /var/log/chrony

# 选择日志文件要记录的信息。
# Select which information is logged.
#log measurements statistics tracking

3、修改配置文件

# 使用 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 1.time.ustc.edu.cn      #仅修改两行
server 2.ntp.aliyun.com

4、开启同步

systemctl enable chronyd
systemctl restart chronyd

chronyd是一个在系统后台运行的守护进程
chronyc是用来监控chronyd性能和配置其参数程序

chronyc 用法
chronyc:进入设置
accheck: 检查NTP访问是否对特定主机可用
activity: 该命令会显示有多少NTP源在线/离线
add server: 手动添加一台新的NTP服务器。
clients: 在客户端报告已访问到服务器
delete: 手动移除NTP服务器或对等服务器
settime: 手动设置守护进程时间
tracking: 显示系统时间信息
help:显示帮助


查看 ntp_servers

chronyc sources -v

查看 ntp_servers 状态

chronyc sourcestats -v

查看 ntp_servers 是否在线

chronyc activity -v

查看 ntp 详细信息

chronyc tracking -v

PREV
实验:NTP时钟服务器
NEXT
samba配置文件smb.conf搬运