VMWare Esxi 6.5(实际为5.x,6.x)时区问题

Esxi不支持修改时区,但是可以使用ESX或者Centos 6/7的localtime文件进行替换以实现时区修改,问题是,重启后文件会被还原。

详细的纠结过程就不说了,终级解决方案如下(给公司写的,现分享出来):

大概思路是:将centos 6中/usr/share/zoneinfo/Asia/Shanghai文件(如果是它国时区,请自行替换base64内容)进行base64编码,然后使用shell脚本生成python脚本并执行后进行解码。

将以下shell脚本代码段添加到ESXI的/etc/rc.local.d/local.sh文件中,贴在exit 0之前重启便可。

如果想立刻生效,只需将以下代码段贴到任意位置的将建shell脚本文件中(如:/tmp/set_time_zone.sh)后执行此脚本就行。

#Add script to /etc/rc.local.d/local.sh before 'exit 0' in VMWare esxi 5.x/6.x
#以下请设置临时文件路径/Set temp script file path
temp_shell_script_path="/tmp/set_timezone.sh"
#以下请设置localtime路径(如需测试请填写其它自定义路径,默认请填写/etc/localtime),Set localtime file path,e.g. "/etc/localtime"
sys_localtime_path="/etc/localtime"
#In python echo base64,because VMWare ESxi have no command "base64".
echo "#Beijing Joycore Technology Co., Ltd. " > $temp_shell_script_path
echo "#Set Timezone For VMWARE-ESXI 5.x/6.x" >> $temp_shell_script_path
echo "import base64" >> $temp_shell_script_path
echo "str_timezone = 'VFppZjIAAAAAAAAAAAAAAAAAAAAAAAADAAAAAwAAAAAAAAARAAAAAwAAAAyw/pqgyFwBgMj6J3DJ'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + '1Q6Aytta8B66NgAfaX9wIH5ogCFJYXAiXkqAIylDcCRHZwAlEl/wJidJACbyQfAoBysAKNIj8AIB'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + 'AgECAQIBAgECAQIBAgECAABx4AAAAAB+kAEEAABwgAAITE1UAENEVABDU1QAAAAAAAAAVFppZjIA'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + 'AAAAAAAAAAAAAAAAAAAAAAADAAAAAwAAAAAAAAARAAAAAwAAAAz/////sP6aoP/////IXAGA////'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + '/8j6J3D/////ydUOgP/////K21rwAAAAAB66NgAAAAAAH2l/cAAAAAAgfmiAAAAAACFJYXAAAAAA'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + 'Il5KgAAAAAAjKUNwAAAAACRHZwAAAAAAJRJf8AAAAAAmJ0kAAAAAACbyQfAAAAAAKAcrAAAAAAAo'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + '0iPwAgECAQIBAgECAQIBAgECAQIAAHHgAAAAAH6QAQQAAHCAAAhMTVQAQ0RUAENTVAAAAAAAAAAK'" >> $temp_shell_script_path
echo "str_timezone = str_timezone + 'Q1NULTgK'" >> $temp_shell_script_path
echo "#Print file /usr/share/zoneinfo/Asia/Shanghai source from Centos 6.x" >> $temp_shell_script_path
echo "fout = open(r'$sys_localtime_path', 'wb')" >> $temp_shell_script_path
echo "fout.write(base64.b64decode(str_timezone))" >> $temp_shell_script_path
echo "fout.close" >> $temp_shell_script_path
#delete old file who names localtime
rm -f $sys_localtime_path
#rebuild new file with localtime
python $temp_shell_script_path
#delete temp python script
rm -f $temp_shell_script_path
echo "JOYCORE:TIMEZONE UPDATED .......... OK"

在esxi /etc/rc.local.d/local.sh   exit 0 前添加
sh /vmfs/volumes/datastore1/set_time_zone.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.

exit 0
[root@localhost:/vmfs/volumes/509bfdd0-b00970e0-556e-90b11c9da899] vi /etc/rc.local.d/local.sh
[root@localhost:/vmfs/volumes/509bfdd0-b00970e0-556e-90b11c9da899] cat /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.
sh /vmfs/volumes/datastore1/set_time_zone.sh

exit 0

----------------------------------------------------------------------

原文地址:https://www.cnblogs.com/adolfmc/p/13461481.html