内网 Xen 和 Vmware 中的虚拟机器如何对时?

原创
运维 系统运维
Puppet自动化分布式环境对时间要求非常严格,内网 Xen 和 Vmware 中的虚拟机器如何同步?本文分享了具体的技术方案,希望能给大家带来帮助。

 【51CTO专稿】Puppet自动化分布式环境对时间要求非常严格,日常正常工作中很容易出现如下报错:

  1. Triggering test.cn7788.com 
  2. Host test.cn7788.com failed: certificate verify failed.   
  3. This is often because the time is out of sync on the server or client 
  4. test.cn7788.com finished with exit code 2 
  5. Failed: test.cn7788.com 

大家可以关注“This is often because the time is out of sync on the server or client”此行报错,一般来说,如果出现类似字样,基本都是由于时间不精准而引起的问题,大家用ntpdate自动对时即可解决。

工作中新增加了多组Xen虚拟机器也要求用Puppet服务器来进行自动化管理(初始化环境已经采用Xen的模板机来处理了),环境如下所示:

192.168.11.26 test1.cn7788.com  puppet-client  
192.168.11.27 test2.cn7788.com  puppet-client  
192.168.11.28 test3.cn7788.com  puppet-client  

发现一样出现了如上报错,原因如下:

Xen虚拟机器同宿主机硬件时钟同步,本来是很方便的嘛。不过因为软件模拟中断会在负载变化的时候出现延迟,所以会逐渐会比正常时间变慢,我们修改下xen虚拟机的内核文件/etc/sysctl.conf,添加代码如下:

xen.independent_wallclock = 1  

然后用如下命令使内核改动迅速生效,如下:

sysctl -p 

最后我们在这三台Xen机器上用ntpdate命令来同步时间,确保Xen虚拟机器不会因为时间问题报错,命令如下所示:

ntpdate ntp.api.bz  

另外,如果是内网的VMware机器也想采用ntpdate自动对时,应该如何操作呢?尝试了一些方法,个人感觉安装Vmware Tools工具是较为简单的方法,而且在测试中发现,最小化安装CentOS5.8 x86_64后再进行安装Vmware Tools还是有不少困难的,具体如下所示(这里以VMware Workstation5.5举例说明):

一、按照正常操作时,选择“install Vmware Tools”选项时,Vmware相关光盘应该就可以自动挂载上面了,但是就是没挂载成功,这个时候也不要着急,用别的方法就是,我们采取手动挂载的方法,我们选择在目录“C:\Program Files\VMware\VMware Workstation”下的linux.iso,手动挂载至Vmware Workstation下,然后:

mount /dev/cdrom /mnt/  
cp /mnt/VMwareTools-5.5.1-19175.tar.gz /usr/local/src  
tar xvf VMwareTools-5.5.1-19175.tar.gz  
cd  vmware-tools-distrib  
./ vmware-install.pl  

二、执行到下面步骤时会报错,原因是/mnt已经被占用了,如下:

Stopping VMware Tools services in the virtual machine:  
Guest operating system daemon:                       [  OK  ]  
Unable to create the directory /mnt/hgfs.  
Execution aborted.  

此时我们umount /mnt目录即可。

三、继续安装的话,会因为缺少gcc和C Hearder头继续报错,报错信息如下所示:

  1. None of the pre-built vmhgfs modules for VMware Tools is suitable for your running kernel.  
  2. Do you want this program to try to build the vmhgfs module for 
  3. your system (you need to have a C compiler installed on your system)? [yes] 
  4. Setup is unable to find the "gcc" program on your machine.  Please make sure it is installed.  
  5. Do you want to specify the location of this program by hand? [yes] 
  6. What is the location of the "gcc" program on your machine? 
  7. None of the pre-built vmhgfs modules for VMware Tools is suitable for your running kernel.  
  8. Do you want this program to try to build the vmhgfs module for  
  9. your system (you need to have a C compiler installed on your system)? [yes]  
  10. Using compiler "/usr/bin/gcc". Use environment variable CC to override. 
  11. What is the location of the directory of C header files that match your running  kernel? [/usr/src/linux/include]  
  12. The path "/usr/src/linux/include" is not an existing directory. 

解决方法如下所示:

yum -y install gcc  kernel-devel  

很多朋友在VMware Workstation下面安装其它版本时容易出现如下错误, 很容易卡在下面,图示如下:

其实只需要yum install或apt-get install kernel-devel即可。

四、安装完成以后我们继续安装,安装信息如下所示:

It looks like you are trying to run this program in a remote session. This  
program will temporarily shut down your network connection, so you should only  
run it from a local console session. Are you SURE you want to continue? [no] yes  
Stopping VMware Tools services in the virtual machine:  
Guest operating system daemon:                          [  OK  ]  
Trying to find a suitable vmhgfs module for your running kernel.  
None of the pre-built vmhgfs modules for VMware Tools is suitable for your  
running kernel.  Do you want this program to try to build the vmhgfs module for  
your system (you need to have a C compiler installed on your system)? [yes] no  
The filesystem driver (vmhgfs module) is used only for the shared folder  
feature. The rest of the software provided by VMware Tools is designed to work  
independently of this feature.  
If you wish to have the shared folders feature, you can install the driver by  
running vmware-config-tools.pl again after making sure that gcc, binutils, make  
and the kernel sources for your running kernel are installed on your machine.  
These packages are available on your distribution's installation CD.  
[ Press Enter key to continue ]  
No X install found.  
Starting VMware Tools services in the virtual machine:  
Switching to guest configuration:                       [  OK  ]  
DMA setup:                                              [  OK  ]  
Guest operating system daemon:                          [  OK  ]  
The configuration of VMware Tools 5.5.1 build-19175 for Linux for this running  
kernel completed successfully.  
You must restart your X session before any mouse or graphics changes take  
effect.  
You can now run VMware Tools by invoking the following command:  
"/usr/bin/vmware-toolbox" during an XFree86 session.  
Enjoy,  
--the VMware team  

注意结尾的几段信息,特别是这段“The configuration of VMware Tools 5.5.1 build-19175 for Linux for this running kernel completed successfully.”

一般来说,此时VMware Tools应该是成功安装上去了,我们检查下/mnt目录,看到共享目录hgfs已经成功生成了。

此时我们可以用ntpdate命令自动对时了,如下:

ntpdate ntp.api.bz  

个人博客:http://andrewyu.blog.51cto.com

微博地址:http://weibo.com/yuhongchun027

【声明】本文作者:余洪春(抚琴煮酒),英文名Andrew.Yu。本文在51CTO系统频道首发,转载请注明作者和出处。

 

责任编辑:黄丹 来源: 51CTO.com
相关推荐

2014-02-21 11:20:34

KVMXen虚拟机

2010-01-21 11:17:36

xen虚拟机

2017-03-21 16:48:38

2011-03-15 13:12:59

2017-08-15 15:36:41

VMwareLinux虚拟机

2012-05-18 10:07:34

虚拟化

2009-09-04 08:33:25

VirtualBox虚

2010-10-13 10:16:44

备份VMware vS虚拟机

2009-07-27 08:46:22

2009-09-15 09:56:13

VMwareXen

2010-08-30 10:11:25

XenKVM虚拟机迁移

2012-10-11 14:18:25

CentosVMware

2012-08-27 09:24:02

虚拟化

2021-01-04 05:49:34

VMwareLinux虚拟机

2012-03-19 21:19:14

vmwarekvm

2009-08-07 10:49:57

虚拟机故障监控

2009-01-12 17:52:10

服务器虚拟化VMware

2014-12-23 10:06:14

VLAN

2016-12-19 13:49:33

2009-08-06 10:36:10

VMware上网设置VMware故障排查
点赞
收藏

51CTO技术栈公众号