Wednesday, September 29, 2010

VMware ESX command line essentials PART #1

[1] Overview of the methods to manage Vmware ESX/ESXi Host

1.1 ESX host native commands
1) Basic commands:
/usr/sbin/esxcfg-* commands ,  vmware-cmd, vmkfstools etc
2) Advanced command:
/usr/bin/vimsh:  an interactive shell to peform almost any task that can be done in vCenter

1.2 External management tools to manage ESX/ESXi Host
VMware vSphere PowerCLI
"SDK"  for  Windows  to perform any task that can be done in vCenter.
Interactive shell with 200+ PowerShell cmdlets, easy to use
Supported OS: Windows
Supported Target: ESX/ESXi or vCenter Server

http://honglus.blogspot.com/2009/12/vsphere-powercli-quick-start.html
Vmware  vSphere SDK for Perl SDK for Perl to perform any task that can be done in vCenter
Supported OS: Windows/Linux
Supported Target: ESX/ESXi host or vCenter Server

VI Perl Toolkit
Based on Perl SDK, Some scripts  to perform common administration tasks (vmclone.pl vmcontrol.pl ... etc)
VI Perl Tookit only has 10+ utilities compared to PowerCLI  200+  cmdlets.

VMware vSphere  vCLI
Based on Perl SDK, port most ESX host native commands (esxcfg*,vmware-cmd...) to external management host. It is commonly used for ESXi host which doesn't have service console.
Supported OS: Windows/Linux
Supported Target: ESX/ESXi host or vCenter Server

[2] VMware basic concepts

Memory management
[Memory Size] This is the amount of memory we assign to the vm and is also the amount of memory the guest OS will see as its physical memory. This is a HARD LIMIT  and the vm cannot exceed this limit if it demands more memory.
[Reservation]  A guaranteed amount of memory assigned to the vm. This is a way of ensuring that the vm gets a minimal amount of memory assigned
[Limit] SOFT LIMIT  controlled by VMkernel,  SOFT LIMIT<=HARD LIMIT (Memory size),  The default value is unlimited which is VM Configured Size
Maximum allocation target = min{ VM’s memory size, VM’s limit }
[Share]  the priority/weight when requesting resource, High:normal:low = 4:2:1

Memory management key points
1) Allocation rule: Reservation  <=the amount  dynamically allocated  based on shares <=limits <= memory size
2) It is important to set reservation  for mission critical VMs, but limit is not very important.
3) It is important to have VM tools running inside VM. Because ballooning driver (vmmemctl) in VM tools is more efficient than host swapping under memory overcommitment.
(Under memory overcommitment, reclamation techniques techniques are transparent page sharing, ballooning, and host swapping)

http://www.vmware.com/files/pdf/perf-vsphere-memory_management.pdf
Resource pool
Cluster is a big resource pool by default
You can create sub pool under the Cluster and drag vm to the sub pool in order to fine tune VM resource.

VMware virtual machine files
location: /vmfs/volumes/$DATASTORE/$VIRTUALMACHINE
.vmx This is the primary configuration file
.nvram  This is the file that stores the state of the virtual machine's BIOS.
.vmdk   Disk DescriptorFile (ASCII text, less than 1M )
*-flat.vmdk Binary file stores the contents of the virtual machine's hard disk drive.
.vmem  The virtual machine's paging file
.vmsn VM snapshot file

Vmware configuration files in /etc/vmware/
/etc/vmware/esx.conf  is the ESX host configuration file.
Vmware runtime information in /proc/vmware/
/proc/vmware/version /proc/vmware/cpuinfo … etc.
VMware services control scripts  in /etc/init.d/
vmware : Vmware basic service supporting VMS, restarting vmware will affect running VMs
mgmt-vmware: Vmware Host Agent (/usr/lib/vmware/bin/vmware-hostd). Vmware management service, restart won't affect running vms
vmware-aam  :Vmware HA agent
vmware-vmkauthd: VMware VMkernel authorization daemon
vmware-webAccess: Vmware Web management interface 
vmware-autostart: auto start/stop VMs configured to do so
vmware-late: VMware late init tools (start kernel logger, nfs/iscsi volumes .. )
vmware-vpxa VirtualCenter agents

[3] VMware basic administrative tasks:


####Get ESX host Vmware version
$cat /proc/vmware/version
VMware ESX 4.0.0 [Releasebuild-208167], built on Nov  8 2009
$/usr/bin/vmware -v
VMware ESX 4.0.0 build-208167
####List running VMS
$/usr/bin/vmware-cmd -l
/vmfs/volumes/8292a402-3f357289/vm-01/vm-01.vmx
..
$/usr/bin/vm-support -x
..
vmid=4331       vm-01
..
$vimsh -n -e vmsvc/getallvms
Vmid         Name                                    File                                Guest OS      Version
16     vm01   [stor1] vm01/vm01.vmx   sles10_64Guest   vmx-07
####Manage VMs
/usr/bin/vmware-cmd <cfg file ( .vmx)>  command
VM command:
getstate
start [soft|hard|trysoft]
stop [soft|hard|trysoft]
reset [soft|hard|trysoft]
suspend [soft|hard|trysoft]
getconfig <variable>
setguestinfo <variable> <value>
getguestinfo <variable>
getproductinfo <product_info>
connectdevice <device_name>
disconnectdevice <device_name>
getid
getconfigfile
getheartbeat
getuptime
gettoolslastactive
hassnapshot
createsnapshot <name> <description> <quiesce> <memory>
revertsnapshot
removesnapshots
answer
####register and unregister VMs
/usr/bin/vmware-cmd -s register <config_file_path>
/usr/bin/vmware-cmd -s unregister <config_file_path>
####vmkping 
ping from vmkernel interface instead of service console interface. e.g checking connectivity to NFS server where VMS reside.
####esxcfg-advcfg   -g
-g Get/set  the value of the VMkernel advanced configuration option listed in esxcfg-info -o 
$ esxcfg-advcfg -g /Irq/RoutingPolicy
Value of RoutingPolicy is 2
####esxcfg-advcfg   -c
- c|--get-config         Get the value of a specific line in esx.conf.
esxcfg-advcfg -c /adv/Misc/HostName
####vimsh
An interactive shell on ESX host to provide almost any operation available in virtual centre
$ /usr/bin/vimsh
-n          Non-interactive mode.  Just quit after processing command line.
-e <cmd>    Run a series of commands specified by <cmd>.
$ vimsh -n -e vmsvc/getallvms
To find out the command name, press tab key to list commands in interactive shell(start vimsh without any argument)

PART #2 will be focusing on VMware command line storage management

No comments:

Post a Comment