chrony简介
官网:https://chrony.tuxfamily.org
从CentOS 8开始,ntpd 正式被 chrony 取代,与前代 ntpd 相比,chrony 性能更好,安装配置更方便。
常用命令
# 安装chrony
yum install -y chrony
# 启用chrony
systemctl enable chronyd.service
systemctl disable chronyd.service
# 重启chrony
systemctl start chronyd.service
systemctl restart chronyd.service
# 防火墙规则
# 系统默认ntp端口为 123/udp
firewall-cmd --add-service=ntp --permanent && firewall-cmd --reload
配置
Chrony 分为两部分:
- Chronyd:即NTP服务端
- Chronyc:即NTP客户端
配置文件
vim /etc/chrony.conf
最重要的3个属性
第一是你需要同步的ntp服务器地址
具体的NTP服务器地址,可查询https://www.ntppool.org/en/
# These servers were defined in the installation:
pool 0.asia.pool.ntp.org iburst
pool 1.asia.pool.ntp.org iburst
pool 2.asia.pool.ntp.org iburst
pool 3.asia.pool.ntp.org iburst
# pool 2.centos.pool.ntp.org iburst
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
第二个是允许访问该服务器的网段
# Allow NTP client access from local network.
allow 10.10.2.0/24
allow 10.10.3.0/24
第三个即使服务器无法连接ntp服务器,也可以同步本地时间。
# Serve time even if not synchronized to a time source.
local stratum 10
配置好以后,记得保存,重启ntp