浏览模式: 标准 | 列表 [VMware]

[转]VMware下ESX常见命令

1:看你的esx版本
vmware -v
2:列出esx里知道的服务
esxcfg-firewall -s
3:查看具体服务的情况
esxcfg-firewall -q sshclinet
4:重新启动vmware服务
service mgmt-vmware restart
5: 修改root的密码
passwd root
6:列出你当前的虚拟交换机
esxcfg-vswitch -l
7:查看控制台的设置
esxcfg-vswif -l
8:列出系统的网卡
esxcfg-nics -l
9:添加一个虚拟交换机,名字叫(internal)连接到两块物理网卡,(重新启动服务,vi就能看见了)
esxcfg-vswitch -a vSwitch1
esxcfg-vswitch -A internal vSwitch1
esxcfg-vswitch -L vmnic1 vSwitch1
esxcfg-vswitch -L vmnic2 vSwitch1
10:删除交换机,(注意,别把控制台的交换机也删了)
esxcfg-vswitch -D vSwitch1
11:删除交换机上的网卡
esxcfg-vswitch -u vmnic1 vswitch2
12:删除portgroup
esxcfg-vswitch -D internel vswitch1
13:创建 vmkernel switch ,如果你希望使用vmotion,iscsi的这些功能,你必须创建( 通常是不需要添加网关的)
esxcfg-vswitch -l
esxcfg-vswitch -a vswitch2
esxcfg-vswitch -A "vm kernel" vswitch2
esxcfg-vswitch -L vmnic3 vswitch2
esxcfg-vmknic -a "vm kernel" -i 172.16.1.141 -n 255.255.252.0
esxcfg-route 172.16.0.254
14:打开防火墙ssh端口
esxcfg-firewall -e sshclient
esxcfg-firewall -d sshclient
15: 创建控制台
esxcfg-vswitch -a vSwitch0
esxcfg-vswitch -A "service console" vSwitch0
esxcfg-vswitch -L vmnic0 vSwitch0
esxcfg-vswif -a vswif0 -p "service console" -i 172.16.1.140 -n 255.255.252.0
16: 添加nas设备(a 添加标签,-o,是nas服务器的名字或ip,-s 是nas输入的共享名字)
esxcfg-nas -a isos -o nas.vmwar.cn -s isos
17:列出nas连接
esxcfg-nas -l
18: 强迫esx去连接nas服务器(用esxcfg-nas -l 来看看结果)
esxcfg-nas -r
esxcfg-nas -l
19:连接iscsi 设备(e:enable q:查询 d:disable s:强迫搜索)
esxcfg-swiscsi -e
20:设置targetip
vmkiscsi-tool -D -a 172.16.1.133 vmhba40
21:列出和target的连接
vmkiscsi-tool -l -T vmhba40
22:列出当前的磁盘
ls -l /vmfs/devices/disks 

(转自网络)

Tags: vmware, esx

ESX命令提示符:vmware-cmd

近日我所管理的一台vmware esx 4.0服务器出了点状况,一开始是服务器的物理硬盘无响应引发黄色警告,我多次用VC连接esx服务器均已失败告终。我把esx的SSH服务打开,准备在shell下将esx的服务重新启动,但是担心出现esx上的所有VM都挂了,那么正在运行的业务将影响很大,因为没有做虚拟机对等HA,所以只能等夜里没有业务量的时候再停机维护。而等到了晚上当我再次登陆ssh发现系统在我输入root用户回车之后就停止了响应。因为VM都活着,为了不让esx强制重启导致VM出问题,我便登陆到所有的VM中进行关机操作,然后对esx进行强制关机并重启,最后逐个启动VM。

本次案例中VM不死的原因是VM的存储都是在EMC存储中的……

下面介绍一下如果可以登录到esx服务器中,在shell下可以对VM进行的操作。vmware提供了一个vmware-cmd的工具,位于/usr/bin/下,在任意目录直接执行即可。vmware-cmd是VMWARE管理虚拟机的工具,包括启动、停止、注册、快照、配置等。我们可以在VMware vSphere Client或其他第三方管理软件无法使用的时候管理我们的ESX或ESXi主机上的虚拟机设备。

 

[root@pcs zjsrueducn-web]# vmware-cmd

Invalid operation specified.

usage: vmware-cmd [options]

options:

  -h, --help         show this help message and exit

  -v                 Verbose.

  -q                 Quiet. Minimal output.

  Connection Options:

    -H <host>        specifies an alternative host (if set, -U and -P must

                     also be set)

    -O <port>        specifies an alternative port

    -U <username>    specifies a user

    -P <password>    specifies a password

  Server Operations:

    /usr/bin/vmware-cmd -l

    /usr/bin/vmware-cmd -s listvms

    /usr/bin/vmware-cmd -s register <config_file_path>

    /usr/bin/vmware-cmd -s unregister <config_file_path>

  VM Operations:

    /usr/bin/vmware-cmd <cfg> getstate

    /usr/bin/vmware-cmd <cfg> start <powerOpMode='soft'>

    /usr/bin/vmware-cmd <cfg> stop <powerOpMode='soft'>

    /usr/bin/vmware-cmd <cfg> reset <powerOpMode='soft'>

    /usr/bin/vmware-cmd <cfg> suspend <powerOpMode='soft'>

    /usr/bin/vmware-cmd <cfg> getconfig <variable>

    /usr/bin/vmware-cmd <cfg> setguestinfo <variable> <value>

    /usr/bin/vmware-cmd <cfg> getguestinfo <variable>

    /usr/bin/vmware-cmd <cfg> getproductinfo <product_info>

    /usr/bin/vmware-cmd <cfg> connectdevice <device_name>

    /usr/bin/vmware-cmd <cfg> disconnectdevice <device_name>

    /usr/bin/vmware-cmd <cfg> getid

    /usr/bin/vmware-cmd <cfg> getconfigfile

    /usr/bin/vmware-cmd <cfg> getheartbeat

    /usr/bin/vmware-cmd <cfg> getuptime

    /usr/bin/vmware-cmd <cfg> gettoolslastactive

    /usr/bin/vmware-cmd <cfg> hassnapshot

    /usr/bin/vmware-cmd <cfg> createsnapshot <name> <description> <quiesce> <memory>

    /usr/bin/vmware-cmd <cfg> revertsnapshot

    /usr/bin/vmware-cmd <cfg> removesnapshots

    /usr/bin/vmware-cmd <cfg> answer

Invalid operation specified.

下面介绍下主要的几个参数,其他自行测试。

vmware下的存储卷都是放在/vmfs/volumes/下,换言之,所有的虚拟机都是在这下面的。本例中约定一台red hat 5的虚拟机存储目录为/vmfs/volumes/cx4-240/rhel5-server/,rhel5-server.vmx是虚拟机的“配置文件”,配置信息都在里面,可以用编辑器打开。而我们对虚拟机的操作其实就是对配置文件的操作,配置文件如同一个“入口”。

约定:下方的xx代表rhel5-server.vmx

  • vmware-cmd -l 显示注册的计算机
  • vmware-cmd xx getstate 获得虚拟机的状态
  • vmware-cmd xx start  启动或从暂停状态恢复
  • vmware-cmd xx suspend 暂停虚拟机
  • vmware-cmd xx reset trysoft 重置虚拟机
  • vmware-cmd xx stop trysoft 关闭虚拟机
  • vmware-cmd xx hassnapshot 查询虚拟机快照
  • vmware-cmd xx creatsnapshot 创建虚拟机快照
  • vmware-cmd xx revertsnapshot 恢复快照
  • vmware-cmd -s register xx 注册虚拟机(添加到清单)
  • vmware-cmd -s unregister xx 反注册虚拟机 (从清单中移除)
  • vmware-cmd xx answer 回答提示

注意:在进行reset以及stop操作时候可选trysoft、soft以及hard方式,个人建议选择trysoft,这个可以先软性操作,如果不成功才会使用“暴力”操作,对保护VM是有好处的。

以上操作必须是在VM所在的ESX上进行,不然是无法成功执行的(除了将VM注册到当前ESX中)。因为执行权永远是在VM跑的宿主主机上的。

Tags: vmware, esx

如何检测VPS的虚拟化技术

本文转自:http://www.dmo.ca/blog/detecting-virtualization-on-linux/

Update: You may be interested in [[the perl module|perl-module-for-virtualization-detection]] implementing these tricks.

Frequently, our customers want to install our software in a virtual machine. This can be OK, but frequently they hit a CPU, memory, or IO limit caused by running in a constrained virtual environment. When this happens, we really like to know if they're running under virtualization when we try to support them. Here's some tricks to detect, from a shell, if the system is virtualized.

The first thing to check is dmesg. On a recently-booted system, checking the 'dmesg' command output may be sufficient. Otherwise, try "cat /var/log/dmesg" instead of "dmesg"

  • VMWare:

     # dmesg | grep -i virtual  VMware vmxnet virtual NIC driver    Vendor: VMware    Model: Virtual disk      Rev: 1.0   hda: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive 
  • QEmu or KVM:

    If the "-cpu host" option has not been used, QEmu and KVM will identify themselves as:

     # dmesg | grep -i virtual  CPU: AMD QEMU Virtual CPU version 0.9.1 stepping 03 

    otherwise, the host's CPU information will be used both in dmesg, or in /proc/cpuinfo.

    However, you should see something like:

     $ dmesg | grep -i virtual  [    0.000000] Booting paravirtualized kernel on KVM 

    on newer kernels that understand that they're running under paravirtualization. (Thanks to René Pfeiffer for pointing this out)

  • Microsoft VirtualPC:

     # dmesg | grep -i virtual  hda: Virtual HD, ATA DISK drive  hdc: Virtual CD, ATAPI CD/DVD-ROM drive 
  • Xen (thanks, wardi and others)

    # dmesg | grep -i xen Xen virtual console successfully installed as tty1 
  • Virtuozzo

    # dmesg (returns no output)   # cat /var/log/dmesg (returns no output)   # ls -al /proc/vz veinfo  veinfo_redir  veredir  vestat  vzaquota  vzdata 

On longer-running systems, you may need to grep /var/log/dmesg instead.

If that doesn't produce anything useful, try using dmidecode to look at the BIOS information. Frequently, there will be at least one component identifying itself as virtualized:

  • VMWare:

     # dmidecode | egrep -i 'manufacturer|product'  Manufacturer: VMware, Inc.  Product Name: VMware Virtual Platform 
  • Microsoft VirtualPC:

     # dmidecode | egrep -i 'manufacturer|product'  Manufacturer: Microsoft Corporation  Product Name: Virtual Machine 
  • QEMU or KVM:

     # dmidecode | egrep -i 'vendor'  Vendor: QEMU 
  • Virtuozzo:

     # dmidecode  /dev/mem: Permission denied 
  • Xen:

     # dmidecode | grep -i domU        Product Name: HVM domU 

You should just examine the output of dmidecode directly rather than trying to grep as above, in case the output changes. QEMU, for example, doesn't report the vendor in all versions.

Next, check disk devices for identification as virtualized:

  • VMWare:

    # cat /proc/ide/hd*/model VMware Virtual IDE CDROM Drive # cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00   Vendor: VMware   Model: Virtual disk     Rev: 1.0    Type:   Direct-Access                    ANSI SCSI revision: 02 
  • Microsoft VirtualPC:

    # cat /proc/ide/hd*/model Virtual HD Virtual CD 
  • QEMU, KVM, or Xen:

    # cat /proc/ide/hd*/model QEMU HARDDISK QEMU DVD-ROM 
  • Virtuozzo:

    # ls -al /dev/vzfs b-----x--- 1 root root 0, 19 2009-04-06 15:04 /dev/vzfs 

If you've got tips for other virtualized environments, let me know and I'll add them to the list.

Tags: 虚拟化, vps

解决the NTP socket is in use, exiting问题

机房中的ESX4的服务器时间不对,ESX Server的时间准确比较重要,因为其上的VM(虚拟主机)的时间与其同步。在ESX4上使用NTP服务器同步时间,却遇到了“the NTP socket is in use, exiting”的问题,操作过程命令如下:

[root@esx4 ~]# ntpdate ntp.api.bz
21 Sep 14:39:09 ntpdate[24744]: the NTP socket is in use, exiting

[root@esx4 ~]# service ntpd stop
Shutting down ntpd:                                        [  OK  ]

[root@esx4 ~]# ntpdate ntp.api.bz
21 Sep 15:22:43 ntpdate[25723]: step time server 114.80.81.1 offset 2312.159684 sec

时间误差将近1小时,如果这是银行业务,那是多么可怕。

获得Linux系统的位数(64 or 32)

今天一个朋友问我ESX作为一个以Linux为核心的系统,它的系统位数到底是32位还是64位,而我的实际机房生产环境中所跑的ESX为4.0系统,硬件平台为纯64位计算的HP DL380 G6与DL580 G5。

获取Linux的系统位数如下:

一、采用最常用uname -a命令,得到类似如下2个结果(来自一个32位CentOS与64位ESX)

  • CentOS:Linux centos.is36.com 2.6.18.8 #2 Thu Sep 24 14:29:28 GMT 2009 i686 i686 i386 GNU/Linux
  • ESX:Linux esx.is36.com 2.6.18-128.ESX #1 Fri Apr 10 00:08:17 PDT 2009 x86_64 x86_64 x86_64 GNU/Linux

从上面会看到较为明显的区别,一个是i386,另外一个是x86_64。

二、采用"getconf WORD_BIT"和"getconf LONG_BIT"获得word和long的位数,这2个类型的长度可以决定系统的位数,具体如下:

  • CentOS:执行如上2个命令,均返回32。
  • ESX:执行如上2个命令,分别返回32与64。
  1. 32位的系统中int类型和long类型一般都是4字节的。如果你的C语言教材里写的不是这样,劝你们老师换换教材吧。
  2. 64位的系统中int类型还是4字节的,但是long已变成了8字节的啦。这个教材里没写没关系,写了说明编者追踪最新的技术。

三、在shell下执行“echo $HOSTTYPE”获得系统位数信息。

  • CentOS:返回i686
  • ESX:返回x86_64

因为测试的ESX为4.0版,之前测试过的3.5版应该为32位系统(未经测试)。

解决windows2003下无法使用VMware vSphere Client

20100826更新:有些朋友遇到此问题可能是微软的某补丁造成的,解决这个补丁问题,请查看本文下半部分!卸载该补丁见下图:

kb980773.jpg

大小: 88.9 K
尺寸: 300 x 168
浏览: 306 次
点击打开新窗口浏览全图

记得将系统更新补丁功能调整为非自动,不然卸载后很快又会自动安装回去(经测试发现卸载后2天自动安装了),具体调整为:右键点击“我的电脑”->“属性”->“自动更新”->选择第三个选项->确认完成。


最近几天在我indows2003服务器上登陆安装在本机的VC(VirtualCenter server)总是遇到如下问题:

  1. 先弹出无法连接的错误框:“分析服务器"clients.xml"文件时出错。登录将继续,请联系系统管理员”。
  2. 点击确定继续弹出错误框:“VirtualInfrastructure.Utils.HttpWebRequestProxy的类型初始值设定项引发异常。”
  3. 再次点击“确定”后返回登录窗口:显示“连接失败”。

而安装在本机(windows 2008)的VMware vSphere Client却可以顺利登陆VC,这让我想起来之前遇到过在服务器上无法登陆,却可以在别的电脑上安装客户端登陆。那么问题应该出在客户端身上才是。我将现有的客户端进行了卸载,然后重新安装,无法解决。(这里我要告诉各位:windows服务器有个很大的特点,那就是遇到问题先重启试试看,或许就有效,而我却没第一时间去重启,囧~或许我重启一下,问题解决也不用走下面这么多弯路,当然,如果你重启后没效果,请继续往下看!)

上google查阅了错误信息,都是一篇在windows7下的解决方案的复制再复制。如果有朋友用windows7安装客户端遇到无法连接的问题,可以点击此处去看解决方案。

回到问题,虽然网上的资料没给我直接的解决之道,但是却给了我启发,问题很大程度上应该出在.net上。客户端是依赖微软的.net架构运行的,而现在的.net可能出问题了。我下载了清除之前.net版本的工具将本机的.net进行清除以便于我重新安装.net 2.0

清理完成后重启,新的问题出现了。服务中的VMware VirtualCenter Management Webservices服务却没有启动,之前也出现过这个问题,每次手动启动即可。而这次多次尝试后依然没法启动,我变查看日志,查看与该服务相关的服务是否有问题。

与VMware相关的服务如下:

  1. SQL Server (SQLEXP_VIM)
  2. VMware vCenter Converter
  3. VMware vCenter Orchestrator Configuration
  4. VMware VirtualCenter Management Webservices
  5. VMware VirtualCenter Server
  6. VMwareVCMSDS

我依次启动了1、5服后,成功启动了4服务,也就说明,VC服务依赖数据库,而VC管理服务依赖于VC服务。

完成服务启动,我顺手打开VMware vSphere Client却弹出来初始化失败,忘记装.net 2.0了。将.net 2.0安装好后,再次登陆,稍等片刻,登陆成功!问题解决。


下半部分 来源:http://thinklog.blog.163.com/blog/static/71896182201061295159614/

使用vsphere 客户端连接vpshere 服务器时,跳出窗口,提示:分析服务器“X.X.X.X”的“clients.xml”文件时出错。从网上看到,是由于.NET 自动升级造成的。修改方法是删除升级的补丁(980773),然后将自动升级更改为“安装时提示我”,然后在升级时忽略掉这个升级包。

vSphere Client does not open on any Windows operating systems with the error: parsing the server "<servername>" "clients.xml" file
注:2010.6.9 微软更新了.net framework。可能是load .net framework的工作机制改变了,
Symptoms
·        When trying to launch the vSphere Client you receive errors similar to:
Error parsing the server "<servername>" "clients.xml" file.
The type initializer for VirtualInfrastructure.Utils.HttpWebRequestProxy' threw an exception.
Resolution
You cannot use vSphere Clients prior to the Update 1 release, to access the vCenter Server or ESX hosts because of a Microsoft update that targets the .NET Framework (980773), released on June 9th 2010.  
 
Perform one of these two options to correct the issue:
1.    Download and install vSphere Client 4.0 Update 1 (build 208111) or Update 2 (build 258672) using method a or b below, depending on your environment.
a.    To download and install the vSphere Client for ESX, ESXi (paid version), and vCenter Server:
                                       i.        Go the downloads site.
Note: The vSphere Client .exe is part of the ESX, ESXi, or vCenter Server download binaries.
                                      ii.        Click Download next to your ESX, ESXi, or vCenter Server edition.
                                     iii.        Log in with your VMware Account credentials.
                                     iv.        Click Yes to agree to the EULA.
                                      v.        Click the .exe link next to vSphere Client and Host Update Utility.
Note: You do not need to download the entire vSphere suite, only the vSphere Client.
                                     vi.        Follow the on-screen instructions to install the updated vSphere Client.
b.    To download and install the vSphere Client Update 1 for ESXi (free version):
                                       i.        Go to the ESXi download site.
                                      ii.        Click Download.
                                     iii.        Log in with your account credentials, or register for free.
                                     iv.        Click Download next to vSphere Client and Host Update Utility.
                                      v.        Follow the on-screen instructions to install the updated vSphere Client.
2.    Remove the MS update from your Windows operating system. The vSphere Client works after the update is removed.
Note: This affects Windows XP, Windows 2003, Windows 2008, Windows Vista, and Windows 7.
 If the build number for your vSphere Client is 208111 or higher, then you have vSphere Client Update 1 or later, and should not be affected by this issue.
 
You can determine the version of vSphere Client by reviewing the build number located in the first line of a viclient.log file, located in %USERPROFILE%\Local Settings\Application Data\VMware\vpx on the system running the vSphere Client if the OS is Windows XP or 2003 and %USERPROFILE%\AppData\Local\VMware\vpx in 64 bit Windows 7 or 2008. Build 208111 or higher indicates you are using vSphere Client 4.0 Update 1 or later.
For example:
2010-05-19 03:08:58.508  Log for vSphere Client Launcher, pid=4756, version=4.0.0, build=build-208111, option=release
-------------------------------------------------------------------------------------------------------
 当然如果你不想升级vSphere Client也不是没有其他办法。见下面方法,同样来自官方。
This issue is resolved in VMware vSphere 4.0 Update 1. Prior to this update, the vSphere Client is not supported in Windows 7 or Windows 2008 R2 and it does not run in Compatibility Mode. This issue may occur because of the .NET loading mechanism change in Windows 2008 R2 and Windows 7.
 
You can download and install the VMware vSphere 4.0 Update 1 from the download page.
 
If you cannot upgrade to VMware vSphere 4.0 Update 1, there are 2 possible workarounds. Perform one of these options:
·        Using VMware Player or VMware Workstation, install a Windows XP virtual machine in Windows 7 or Windows 2008 R2.
·        Bypass the normal .NET Framework loading mechanism.
Warning: This workaround is unsupported.
To bypass the normal .NET Framework loading mechanism:
1.     Download the file system.dll. This file is typically located in  %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\ directory of a non-Windows 7 or Windows 2008 R2 machine with .NET v3.5 SP1 installed.
2.     Copy the file to C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\lib.
Note: If the lib directory does not exist, create it.
 
3.     Open VpxClient.exe.config in a text editor. The file is located at C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher.
4.     Add the following three lines to VpxClient.exe.config, just before </configuration>:
<runtime>
<developmentMode developerInstallation="true"/>
</runtime>
 
5.     From Windows 2008 R2 or Windows 7 System Properties, click the Advanced tab > Environment Variables
6.     Create a new System variable called DEVPATH and assign the value:
C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\Lib
Note: For 32bit operating systems, replace Program Files (x86)with Program Files.
You can now launch vSphere Client from a Windows 7 or Windows 2008 R2 machine. You may have to right-click on the vSphere Client icon and choose 
Run as administrator.

 

Tags: vmware, vsphere

解决安装VMware vSphere Client 4.0遇到的.net 3.0...

最近环境里的vCenter Server抽筋了,打开控制台后一直连不上虚拟机,具体解决方案请见解决vc中unable to connect to the MKS:Internal error.问题

在另外一台安装好的windows 2003 企业版上安装VC(vCenter Server)和VMware vSphere Client 4.0,而在安装VC时候遇到了如下图所示的问题:

.net 3.0 sp1 1603 error.jpg

大小: 9.5 K
尺寸: 300 x 76
浏览: 53 次
点击打开新窗口浏览全图

解决方法:

用dotnetfx_cleanup_tool(.net 清理工具将之前的.net版本给清理了)

dotnetfx_cleanup_tool_1.jpg

大小: 40.86 K
尺寸: 300 x 187
浏览: 42 次
点击打开新窗口浏览全图
dotnetfx_cleanup_tool_2.jpg

大小: 42.07 K
尺寸: 300 x 186
浏览: 39 次
点击打开新窗口浏览全图

下载 cleanup_tool.rar

解决vc中unable to connect to the MKS:Intern...

环境中的VC(vCenter Server)4.0 抽筋了,启动虚拟机控制台就显示如下错误:unable to connect to the MKS:Internal error. (GG译:无法连接到MKS的:内部错误。)这里的MKS实在不清楚到底指的是什么,搜索不到合理的解释,估计就是链路问题。如图所示

unable to connect to the mks:internal error..jpg

大小: 15.04 K
尺寸: 272 x 109
浏览: 70 次
点击打开新窗口浏览全图

询另外一个技术人员,被告知尝试以下解决方案:

  1. service mgmt-vmware restart
  2. /etc/ vmware/config  增加 vmauthd.server.alwaysProxy = "TRUE"
  3. 查看client端902端口是否被占用

在1与2方案均告失败后,我在一台PC上重新安装了VC(vCenter Server)和VMware vSphere Client 4.0,然后用后者连接前者并把环境中的一台ESX4.0主机加入到管理端,至此,启动虚拟控制台后一切正常了。

结论:可能是第3点所示的问题,但在我将环境中的那台VC重启之后,居然神奇地正常了。百思不得其解,建议遇到此问题的朋友,可以尝试先重启VC主机,如果不奏效,请再以此尝试以上方案。当然,再不行,重装一次试试看也未尝不可(无奈之举)。

Total:1012Next ›