ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2020-08-09 06:31:34  阅读:480  来源: 互联网

标签:pathecho shell temp script Esxi 6.5 str timezone VMWare


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

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

 

标签:pathecho,shell,temp,script,Esxi,6.5,str,timezone,VMWare
来源: https://www.cnblogs.com/adolfmc/p/13461481.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有