文章标题图片 :来自 Pexels 上的图片
1.环境介绍
- CentOS Linux release 7.7.1908 (Core)
- 通信协议:UDP Port:123
-
- 防火墙放行 UDP 123端口
- firewall-cmd --zone=public --add-port=123/udp --permanent
- firewall-cmd --reload
- 服务端:10.60.60.1
- 客户端:10.60.70.1
2.服务端
代码语言:javascript复制# 10.60.60.1
# 停止chronyd服务,否则ntpd开机无法自启动
systemctl stop chronyd
systemctl disable chronyd
# 安装ntp服务
yum install -y ntp
# 修改公共ntp服务器地址
sed -i 's/server 0.centos.pool.ntp.org iburst/server ntp.ntsc.ac.cn iburst/g' /etc/ntp.conf
sed -i 's/server 1.centos.pool.ntp.org iburst/server ntp.tencent.com iburst/g' /etc/ntp.conf
sed -i 's/server 2.centos.pool.ntp.org iburst/server ntp.aliyun.com iburst/g' /etc/ntp.conf
sed -i 's/server 3.centos.pool.ntp.org iburst/server time.edu.cn iburst iburst/g' /etc/ntp.conf
# 启动ntpd服务
systemctl start ntpd
# 开机自动启动
systemctl enable ntpd
# 查看ntp是否有同步状态,如果没有,等5分钟再看
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
139.199.215.251 100.122.36.196 2 u 143 256 377 20.753 -7.559 9.998
203.107.6.88 10.137.55.181 2 u 250 256 377 43.939 -1.862 5.165
202.112.0.38 .INIT. 16 u - 1024 0 0.000 0.000 0.000
*114.118.7.161 .OLEG. 1 u 316 256 316 35.822 -12.091 6.762
# remote:本机和上层ntp的ip或主机名,“ ”表示优先,“*”表示次优先
# refid:参考上一层ntp主机地址
# st:stratum阶层
# when:多少秒前曾经同步过时间
# poll:下次更新在多少秒后
# reach:已经向上层ntp服务器要求更新的次数
# delay:网络延迟
# offset:时间补偿
# jitter:系统时间与bios时间差
3.客户端
代码语言:javascript复制# 10.60.70.1
# 停止chronyd服务,否则ntpd开机无法自启动
systemctl stop chronyd
systemctl disable chronyd
# 安装ntp服务
yum install -y ntp
# 修改ntp服务器地址为服务端
sed -i 's/server 0.centos.pool.ntp.org iburst/server 10.60.60.1 iburst/g' /etc/ntp.conf
# 启动ntpd服务
systemctl start ntpd
# 开机自动启动
systemctl enable ntpd
# 查看ntp是否有同步状态,如果没有,等20秒再看
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
10.60.60.1 ntp.ntsc.ac.cn 2 u 1 64 1 0.903 -38.559 0.134