例:如果CentOS 上永久地设置时间为 "2020-01-01 10:10:30"
1. 禁用 NTP 服务
如果服务器正在使用 Network Time Protocol (NTP) 或 chronyd 服务来同步时间,首先需要停止并禁用这些服务,否则它们可能会覆盖手动设置的时间。
如果使用的是 ntpd:
sudo systemctl stop ntpd
sudo systemctl disable ntpd如果使用的是 chronyd (在新的 CentOS 版本中更常见):
sudo systemctl stop chronyd
sudo systemctl disable chronyd2. 手动设置时间
使用 date 命令来手动设置时间:
sudo date --set="2020-01-01 10:10:30"3. 将当前系统时间写入硬件时钟
这一步是为了确保在重启后时间设置依然保持不变:
sudo hwclock --systohc4. 禁用 VMware 时间同步
为了防止 VMware 工具自动同步时间,需要禁用 VMware 时间同步功能。
sudo vmware-toolbox-cmd timesync disable5. 在虚拟机的配置文件中禁用时间同步:
关闭虚拟机,并编辑虚拟机的配置文件 (.vmx文件)。在此文件中,添加或修改以下条目以禁用时间同步:
time.synchronize.continue = "FALSE"
time.synchronize.restore = "FALSE"
time.synchronize.resume.disk = "FALSE"
time.synchronize.shrink = "FALSE"
time.synchronize.tools.startup = "FALSE"
time.synchronize.resume.host = "FALSE"
保存文件并重新启动虚拟机。