前言

在Proxmox VE(PVE)虚拟化集群中,时间的偏差可能引发连锁性故障——从Ceph存储一致性错误到虚拟机热迁移异常,甚至分布式系统日志的时间错位都会显著增加运维复杂度。尽管现代服务器内置硬件时钟,但温度漂移和系统负载仍会导致节点间日均2-5秒的时间偏移。

本文将通过实践案例,详解在PVE环境中部署高可靠NTP服务,用于给集群各个节点进行时间同步,以确保集群节点时间的一致性。


1. 创建虚拟机用于部署NTP服务

image-20250516135444043

2. 选择要安装的镜像文件

image-20250516135546947

3. 选择 ceph Pool 存储池和虚拟机磁盘大小

4. 系统安装完成后,配置静态IP地址

$ vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=b2d48b5b-03c3-4c11-b171-ef268725981c
DEVICE=eth0
ONBOOT=yes

IPADDR=192.168.253.10
GATEWAY=192.168.253.2
NETMASK=255.255.255.0
DNS1=114.114.114.114
DNS2=223.5.5.5

5. 更换为国内源

$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
$ curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
$ yum clean all
$ yum makecache

6. 安装NTP服务

$ yum install ntp ntpdate -y
$ vi /etc/ntp.conf
...
# 把时间误差记录下来写入driftfile,这样即使重新开机以后之前的计算结果也就不会丢失了
driftfile /var/lib/ntp/drift
# 新增日志目录
logfile /var/log/ntpd.log
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1

# 只允许本网段获取
restrict 192.168.253.0 mask 255.255.255.0 nomodify notrap

# 设置NTP服务器的时间源
server ntp.ntsc.ac.cn iburst
server 210.72.145.44 iburst
server ntp.aliyun.com iburst
server s2m.time.edu.cn iburst

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
...

7. 重启ntp服务并设置开机自启

$ systemctl restart ntpd
$ systemctl enable ntpd

8. 将系统时间写入硬件时间

$ hwclock -w
$ echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd

9. 查看时间同步信息

$ ntpq -p

10. 各PVE节点配置NTP服务器

10.1 修改chronyd配置文件指定NTP服务器

$ vim /etc/chrony/chrony.conf
...
#pool 2.debian.pool.ntp.org iburst
server 192.168.253.10 iburst
...

10.2 重启chronyd服务

$ systemctl restart chronyd

10.3 检查时间同步状态

$ chronyc tracking

image-20250517141331174

文章作者: hzbb
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 运维小记
PVE 虚拟化 PVE
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝