服务器时间同步校准

我有两台服务器分别为:

机器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
相关推荐
mftang21 小时前
现代互联网安全的基石: SSL/TLS技术介绍
服务器·网络·ssl
坐怀不乱杯魂21 小时前
Linux网络 - 网络层
linux·服务器·网络
j_xxx404_21 小时前
Linux:命令行参数与环境变量
linux·运维·服务器
j_xxx404_1 天前
Linux:进程虚拟地址空间|虚拟内存管理
linux·运维·服务器
江畔何人初1 天前
pod的定义以及创建过程
linux·运维·云原生
德尔塔大雨淋1 天前
VLLM 中的module PASS 和FUN PASS
linux·服务器·vllm
末日汐1 天前
linux线程
linux·运维
玉梅小洋1 天前
CentOS :yum源配置及验证指南
linux·运维·centos·yum
zxsz_com_cn1 天前
设备预测性维护算法核心功能有哪些?六大模块拆解智能运维的“技术骨架”
运维·算法
自可乐1 天前
n8n全面学习教程:从入门到精通的自动化工作流引擎实践指南
运维·人工智能·学习·自动化