ESXI设置时区,时间校准

发布时间 2023-07-31 11:59:01作者: 06

相信会考虑这个问题的人,都是因为要设置虚拟机的调度任务吧:)

一开始我还是想着打开NTP服务,通过NTP服务校准时间,不过后来经过了解,NTP漏洞也比较多,如果在物理机上开放NTP服务和端口,风险比较大

权衡之后,还是觉得:1.修改物理机ESXI系统时区,2修改物理机ESXI为正确时间即可

废话不多说,直接上操作

1.拷贝一份时区正常的虚拟机的文件

/usr/share/zoneinfo/Asia/Shanghai

date命令查看时间和时区
CST即为中国时区

 

2.上传Shanghai文件至要配置的物理机上的/vmfs/volumes/磁盘目录下

注意:一定要上传到数据存储目录,其它目录ESXI重启系统都会还原,文件也会丢失

我这里上传的目录如下

 

3.重命名/etc/localtime,并给/etc/localtime建立软连接

mv /etc/localtime /etc/localtime_bak
ln -s /vmfs/volumes/5be449f9-281acc6a-2bf4-20040fec50ba/zoneinfo/Asia/Shanghai  /etc/localtime

4.把以上步骤加入开机启动脚本

/etc/rc.local.d/local.sh

#!/bin/sh

# local configuration options

# Note: modify at your own risk!  If you do/use anything in this
# script that is not part of a stable API (relying on files to be in
# specific places, specific tools, specific output, etc) there is a
# possibility you will end up with a broken system after patching or
# upgrading.  Changes are not supported unless under direction of
# VMware support.

# Note: This script will not be run when UEFI secure boot is enabled.


mv /etc/localtime /etc/localtime_bak
ln -s /vmfs/volumes/5be449f9-281acc6a-2bf4-20040fec50ba/zoneinfo/Asia/Shanghai  /etc/localtime



exit 0

 

5.校准物理机时间

可以在物理机控制台操作

配置>时间配置>编辑>编辑时间配置

 

 也可以直接命令行操作

esxcli system time set -d 08 -H 16 -m 01 -M 03 -y 2016

我是直接界面操作的

6.检查修改结果

 重启物理机后,时间依旧正常

 

参考文档:

https://blog.51cto.com/jdonghong/1957118

https://www.pianshen.com/article/42901992875/