NTP协议工作原理
NTP协议采用层级式时间同步架构,通过客户端与服务器间的UDP 123端口通信实现时间校准。典型配置包含3-5个上游时间源,系统会自动选择延迟最低且最稳定的服务器进行同步。时区设置建议优先采用Asia/Shanghai
时区,可通过timedatectl set-timezone
命令完成配置。
安装与基础配置
主流Linux发行版安装命令:
# Ubuntu/Debian
sudo apt update && sudo apt install ntp
# CentOS/RHEL
sudo yum install chrony
配置文件路径及核心参数:
/etc/ntp.conf
(NTP服务)/etc/chrony.conf
(Chrony服务)
server 0.cn.pool.ntp.org iburst
server 1.asia.pool.ntp.org iburst
restrict 192.168.1.0/24 nomodify
时钟校准操作命令
手动校准操作流程:
- 停止时间服务:
systemctl stop ntpd
- 强制同步时间:
ntpdate pool.ntp.org
- 写入硬件时钟:
hwclock --systohc
防火墙与权限设置
必须放行UDP 123端口:
firewall-cmd --permanent --add-service=ntp
firewall-cmd --reload
通过restrict
指令控制访问权限,例如restrict 10.0.0.0/8 nomodify
允许指定网段查询时间但禁止修改配置。
同步状态验证方法
常用诊断命令:
ntpq -pn
显示NTP对等节点状态chronyc tracking
查看Chrony同步详情timedatectl status
显示当前时区与时钟状态
本文由阿里云优惠网发布。发布者:编辑员。禁止采集与转载行为,违者必究。出处:https://aliyunyh.com/521704.html
其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。