服务器时间同步校准

我有两台服务器分别为:

机器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
相关推荐
chlk1231 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑1 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件1 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒1 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash2 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行3 天前
Linux和window共享文件夹
linux
Sinclair3 天前
简单几步,安卓手机秒变服务器,安装 CMS 程序
android·服务器
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux