內(nèi)網(wǎng) Xen 和 Vmware 中的虛擬機(jī)器如何對(duì)時(shí)?
原創(chuàng)【51CTO專稿】Puppet自動(dòng)化分布式環(huán)境對(duì)時(shí)間要求非常嚴(yán)格,日常正常工作中很容易出現(xiàn)如下報(bào)錯(cuò):
- 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
大家可以關(guān)注“This is often because the time is out of sync on the server or client”此行報(bào)錯(cuò),一般來說,如果出現(xiàn)類似字樣,基本都是由于時(shí)間不精準(zhǔn)而引起的問題,大家用ntpdate自動(dòng)對(duì)時(shí)即可解決。
工作中新增加了多組Xen虛擬機(jī)器也要求用Puppet服務(wù)器來進(jìn)行自動(dòng)化管理(初始化環(huán)境已經(jīng)采用Xen的模板機(jī)來處理了),環(huán)境如下所示:
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
發(fā)現(xiàn)一樣出現(xiàn)了如上報(bào)錯(cuò),原因如下:
Xen虛擬機(jī)器同宿主機(jī)硬件時(shí)鐘同步,本來是很方便的嘛。不過因?yàn)檐浖M中斷會(huì)在負(fù)載變化的時(shí)候出現(xiàn)延遲,所以會(huì)逐漸會(huì)比正常時(shí)間變慢,我們修改下xen虛擬機(jī)的內(nèi)核文件/etc/sysctl.conf,添加代碼如下:
xen.independent_wallclock = 1
然后用如下命令使內(nèi)核改動(dòng)迅速生效,如下:
sysctl -p
最后我們?cè)谶@三臺(tái)Xen機(jī)器上用ntpdate命令來同步時(shí)間,確保Xen虛擬機(jī)器不會(huì)因?yàn)闀r(shí)間問題報(bào)錯(cuò),命令如下所示:
ntpdate ntp.api.bz
另外,如果是內(nèi)網(wǎng)的VMware機(jī)器也想采用ntpdate自動(dòng)對(duì)時(shí),應(yīng)該如何操作呢?嘗試了一些方法,個(gè)人感覺安裝Vmware Tools工具是較為簡(jiǎn)單的方法,而且在測(cè)試中發(fā)現(xiàn),最小化安裝CentOS5.8 x86_64后再進(jìn)行安裝Vmware Tools還是有不少困難的,具體如下所示(這里以VMware Workstation5.5舉例說明):
一、按照正常操作時(shí),選擇“install Vmware Tools”選項(xiàng)時(shí),Vmware相關(guān)光盤應(yīng)該就可以自動(dòng)掛載上面了,但是就是沒掛載成功,這個(gè)時(shí)候也不要著急,用別的方法就是,我們采取手動(dòng)掛載的方法,我們選擇在目錄“C:\Program Files\VMware\VMware Workstation”下的linux.iso,手動(dòng)掛載至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
二、執(zhí)行到下面步驟時(shí)會(huì)報(bào)錯(cuò),原因是/mnt已經(jīng)被占用了,如下:
Stopping VMware Tools services in the virtual machine: Guest operating system daemon: [ OK ] Unable to create the directory /mnt/hgfs. Execution aborted.
此時(shí)我們umount /mnt目錄即可。
三、繼續(xù)安裝的話,會(huì)因?yàn)槿鄙賕cc和C Hearder頭繼續(xù)報(bào)錯(cuò),報(bào)錯(cuò)信息如下所示:
- 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下面安裝其它版本時(shí)容易出現(xiàn)如下錯(cuò)誤, 很容易卡在下面,圖示如下:
其實(shí)只需要yum install或apt-get install kernel-devel即可。
四、安裝完成以后我們繼續(xù)安裝,安裝信息如下所示:
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
注意結(jié)尾的幾段信息,特別是這段“The configuration of VMware Tools 5.5.1 build-19175 for Linux for this running kernel completed successfully.”
一般來說,此時(shí)VMware Tools應(yīng)該是成功安裝上去了,我們檢查下/mnt目錄,看到共享目錄hgfs已經(jīng)成功生成了。
此時(shí)我們可以用ntpdate命令自動(dòng)對(duì)時(shí)了,如下:
ntpdate ntp.api.bz
個(gè)人博客:http://andrewyu.blog.51cto.com
微博地址:http://weibo.com/yuhongchun027
【聲明】本文作者:余洪春(撫琴煮酒),英文名Andrew.Yu。本文在51CTO系統(tǒng)頻道首發(fā),轉(zhuǎn)載請(qǐng)注明作者和出處。






