设为首页 收藏本站
查看: 1323|回复: 0

[经验分享] VMware ESXi 5.5无法与Windows 2012 NTP Server同步时间

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-4 09:51:47 | 显示全部楼层 |阅读模式
  这次笔者需要面对的环境对时间的同步有比较高的要求, 而虚拟化的环境中时间是比较容易出问题的, 您可以参考上一篇博文为什么Domain controller上的time synchronization非常重要? 笔者的环境里, 经过亲自观察, 如果没有时间同步, 虚拟机与标准时间差距在短短的两个小时之内竟然就偏差了近半个小时!
  
  按照VMware KB 1003063的说法, ESXi 5.5只要在vCenter的vSphere里配好NTP client就可以了.
  
     Note: For ESX 3.5 and above, NTP can be configured from vSphere Client and no longer requires manual configuration.
    然而, 这不是真的.
  
  问题描述
  ===============================================
  先介绍笔者的环境:
  
       
  • 一台安装了Windows 2012的实体机, 它并不是Domain Controller.   
  • 三台ESXi 5.5.   
  • 一台安装了vCenter 5.5的Windows 2008 R2虚拟机, 运行在上面的一台ESXi上.
    
  按照文档Configuring Windows Time service to use an internal hardware clock的步骤,我将Windows 2012实体机配置成了使用内部硬件时钟的NTP server. 注意, 微软的文章如何在 Windows Server 中配置权威时间服务器是不work的.
  按照VMware KB 1003736的步骤, 将三台ESXi 5.5 配置成了与Windows 实体机NTP server 同步时间.
  
  结果如图:
  NTP Server的时间
DSC0000.png
  一台ESXi的时间
DSC0001.png
  懂行的你一定会说, ESXi上只存UTC的时间, 你在vCenter vSphere中看到的时间是convert过了的. 那我就补充一句, 我的vSphere所在的机器的时区已经被设置为与NTP server一样的时区, 而且时间是一样的.
  其结论就是, 这个ESXi的NTP有问题, 时间没有同步.
  
  问题排查
  ==============================================
  首先, 需要verify我们的NTP server是否是好的.
  于是笔者挑选了一台安装在其中一台ESXi上的虚拟机. 注意, 默认情况下只要安装了VMware Tools, 那么即使你没有开启VMware tools的timesync, 虚拟机也会在某些情况下和其宿主去sync时间的, 详见Configure Time Synchronization Between Guest and Host Operating Systems.
  这台ESXi的虚拟机的时间是错误的, 因为ESXi的时间是错误的. –_-||
  笔者运行了如下的命令, 使这台虚拟机的时间正确了.
  
     net start w32tm
  w32tm /config /manualpeerlist:10.110.69.124 /syncfromflags:manual /reliable:yes /update
  w32tm /resync /rediscover
    由此, 我们证明了NTP server是正常工作的. 笔者把NTP Server的时间设置的与标准时间相差了几分钟, 所以, 可以避免混淆.
  
  下一步, 笔者在vSphere里尝试了界面能操作的所有相关东西, 都没能让NTP client正常工作.
  笔者按照文章Troubleshooting NTP on ESX and ESXi 4.x / 5.x (1005092)所讲的去排查, 没有结果. 直到, 笔者找到这篇文章.
  详细步骤不介绍了, 大家可以自己去看, 我只简单说一下:
  1. 在/etc/ntp.conf的最后一行添加一行tos maxdist 30.
  2. 修改/etc/likewise/lsassd.conf文件, 取消掉#sync-system-time的注释, 显式地设置sync-system-time = yes
  3. 重启lsassd服务和ntpd服务.
  
  困扰了笔者好几天的问题终于解决了!
  
  另外, 文章ntpd - Network Time Protocol (NTP) daemon有如下的介绍:
  
     Most operating systems and hardware of today incorporate a time-of-year (TOY) chip to maintain the time during periods when the power is off. When the machine is booted, the chip is used to initialize the operating system time. After the machine has synchronized to a NTP server, the operating system corrects the chip from time to time. In case there is no TOY chip or for some reason its time is more than 1000s from the server time, ntpd assumes something must be terribly wrong and the only reliable action is for the operator to intervene and set the clock by hand. This causes ntpd to exit with a panic message to the system log. The -g option overrides this check and the clock will be set to the server time regardless of the chip time. However, and to protect against broken hardware, such as when the CMOS battery fails or the clock counter becomes defective, once the clock has been set, an error greater than 1000s will causentpd to exit anyway.
    注意粗体的部分, 说如果NTP client的时间与server的时间相差超过1000秒, 那么NTPD就会假设发生了严重的错误, 从而只能手动进行时间调整. 笔者在测试时, 时间差超过了1000秒, 也成功同步了.
  
  命令列表
  ==============================
  
     cp /etc/ntp.conf /etc/ntp.conf.bak
  vi /etc/ntp.conf
  “tos maxdist 30”
  cp /etc/likewise/lsassd.conf /etc/likewise/lsassd.conf.bak
  chmod +w /etc/likewise/lsassd.conf
  vi /etc/likewise/lsassd.conf
  “sync-system-time = yes”
  /sbin/auto-backup.sh
  ./etc/init.d/lsassd restart
  ./etc/init.d/ntpd restart
    
  参考资料
  ==============================
  Configuring Windows Time service to use an internal hardware clock
  http://www.denningelectronics.com/wp-content/uploads/2010/04/TimeService.pdf
  VMware ESXi 5.1 will not sync time with Windows 2008 R2 NTP Domain Controller
  http://www.virtxpert.com/vmware-esxi-5-1-will-not-sync-time-with-windows-2008-r2-ntp-domain-controller/
  Guide to configure NTP on ESX servers (1003063)
  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003063
  Configuring the Windows Time Service
  http://blogs.msmvps.com/acefekay/2014/04/26/configuring-the-windows-time-service/
  Verifying time synchronization across an ESX/ESXi host environment(1003736)
  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003736
  Troubleshooting NTP on ESX and ESXi 4.x / 5.x (1005092)
  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1005092
  W32tm
  http://technet.microsoft.com/en-us/library/w32tm.aspx
  Windows Time Service Tools and Settings
  http://technet.microsoft.com/en-us/library/cc773263(v=ws.10).aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-53711-1-1.html 上篇帖子: 【vmware vsphere 5.5】 下篇帖子: Python如何操作VMware Workstation/Esxi
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表