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"


已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页