服务器时间同步校准

我有两台服务器分别为:

机器1-172.24.223.28(没有外网)

机器2-172.24.218.154(有外网)

方案一:将机器2配置为NTP服务器

1.将机器2-172.24.218.154配置为NTP服务器

复制代码
# 安装chrony(如果还没安装)
yum install -y chrony

# 备份原配置
cp /etc/chrony.conf /etc/chrony.conf.bak

# 编辑配置文件
vi /etc/chrony.conf

在配置文件中添加/修改以下内容:

复制代码
# 允许内网网段访问(根据您的实际网段调整)
allow 172.24.0.0/16
# 或者允许所有内网访问
allow 172.24.218.0/24

# 使用外网可靠时间源
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst

# 如果无法访问外网,可以使用本地硬件时钟作为备份
# local stratum 10

重启chronyd服务:

复制代码
systemctl restart chronyd
systemctl enable chronyd

# 开放防火墙端口
firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload
# 或者直接开放UDP 123端口
firewall-cmd --add-port=123/udp --permanent
firewall-cmd --reload

2.在没有外网的机器1-172.24.223.28上配置NTP客户端

复制代码
# 停止chronyd服务
systemctl stop chronyd

# 备份原配置
cp /etc/chrony.conf /etc/chrony.conf.bak

# 编辑配置文件
vi /etc/chrony.conf

清空原有server行,添加:

复制代码
# 使用内网NTP服务器
server 172.24.218.154 iburst

# 注释掉其他所有server行
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

3.测试和同步

复制代码
# 重启chronyd服务
systemctl start chronyd

# 立即同步时间
chronyc makestep

# 检查同步状态
chronyc sources -v
chronyc tracking

# 查看时间
date

方案二:使用ntpdate手动同步(临时方案)

复制代码
# 安装ntpdate(如果没安装)
yum install -y ntpdate

# 从172.24.218.154同步时间
ntpdate -u 172.24.218.154

# 将系统时间写入硬件时钟
hwclock -w
相关推荐
未济5 天前
linux 配置环境变量
linux
傲世仙尊5 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.5 天前
进程间通信
linux
AI职业加油站5 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-055 天前
Linux IO编程——静态库、动态库
linux
此冬歌咏5 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz5 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅5 天前
linux(8) 软硬链接
linux·运维·服务器
Wang's Blog5 天前
Java 项目实战: 外卖平台-文件下载与ServletOutputStream回写浏览器
服务器·项目开发