【51CTO专稿】Puppet自动化分布式环境对时间要求非常严格,日常正常工作中很容易出现如下报错:
- Triggering test.cn7788.com
- Host test.cn7788.com failed: certificate verify failed.
- This is often because the time is out of sync on the server or client
- test.cn7788.com finished with exit code 2
- 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头继续报错,报错信息如下所示:
- 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]
- Setup is unable to find the "gcc" program on your machine. Please make sure it is installed.
- Do you want to specify the location of this program by hand? [yes]
- What is the location of the "gcc" program on your machine?
- 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]
- Using compiler "/usr/bin/gcc". Use environment variable CC to override.
- What is the location of the directory of C header files that match your running kernel? [/usr/src/linux/include]
- 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系统频道首发,转载请注明作者和出处。