服务器时间同步校准

我有两台服务器分别为:

机器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
相关推荐
阿里云大数据AI技术14 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
你好潘先生20 小时前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221612 天前
Linux驱动编译与加载
linux·嵌入式
程序员老赵2 天前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位2 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术2 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式