Top ESXi command line v2.0

44
ESXi v4.1 Command Line Tricks ESXi v4.1 Command Line Tricks You Absolutely Must Know You Absolutely Must Know Greg Shields Greg Shields Partner and Principal Technologist Concentrated Technology www.ConcentratedTech.com

description

 

Transcript of Top ESXi command line v2.0

Page 1: Top ESXi command line v2.0

ESXi v4.1 Command Line Tricks You ESXi v4.1 Command Line Tricks You Absolutely Must KnowAbsolutely Must Know

Greg ShieldsGreg ShieldsPartner and Principal TechnologistConcentrated Technologywww.ConcentratedTech.com

Page 2: Top ESXi command line v2.0

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

Page 3: Top ESXi command line v2.0

Three PartsThree Parts

Part 1: Understanding the ESXi Command Line and Command-based Management

Part 2: The Linux Commands

Part 3: The VMware Commands

Part 4: vMA and Scripting

Page 4: Top ESXi command line v2.0

Part 1:Part 1:Understanding the ESXi Command Line Understanding the ESXi Command Line and Command Line Managementand Command Line Management

Page 5: Top ESXi command line v2.0

The ESXi Command LineThe ESXi Command Line

ESXi’s command line is Linux’s command line.

Page 6: Top ESXi command line v2.0

The ESXi Command LineThe ESXi Command Line

…however, it is not enabled by default.

Page 7: Top ESXi command line v2.0

Part 2:Part 2:The Linux CommandsThe Linux Commands

Page 8: Top ESXi command line v2.0

The Linux CommandsThe Linux Commands

Basic Linux Navigation– Alt-F1, Alt-F2– cd & ls– find, cat, & grep– tail– ps– kill

Page 9: Top ESXi command line v2.0

Locating Things with Find & GrepLocating Things with Find & Grep

find . –name <something> find / -name <something>

– Useful for locating files on an ESXi disk.

find / -name <something> | grep <something>– Useful for filtering located files.

Bonus points for whomever knows how “grep” got its name…

Page 10: Top ESXi command line v2.0

Locating Things with Find & GrepLocating Things with Find & Grep

find . –name <something> find / -name <something>

– Useful for locating files on an ESXi disk.

find / -name <something> | grep <something>– Useful for filtering located files.

Bonus points for whomever knows how “grep” got its name…

Originally based on the “ed” editor, grep is apseudo-acronym for g/re/p or global regular expression print.

Page 11: Top ESXi command line v2.0

Searching Files with GrepSearching Files with Grep

grep <text string> <filename>– This usage searches <filename> for a <text

string>– Useful for digging through logs– grep failure /var/log/sysboot.log– grep failure|failed|failtastic /var/log/sysboot.log

grep -r <text string> <filepath>– Recursion enables searching the contents of every

file in an entire <filepath> for a <text string>– grep -r failure /var/log

Page 12: Top ESXi command line v2.0

Reading Files with Cat and LessReading Files with Cat and Less

cat <filename>– Pipe the contents of <filename> to the screen.

less <filename>– Pipe the contents of <filename> to the screen,

but do so in a way that’s actually usable.– Return goes down one line.– “d” goes down one page.– “u” goes up one page.– “q” quits.

Page 13: Top ESXi command line v2.0

Reading Ends of Files with LessReading Ends of Files with Less

tail <filename>– Give me the last screenful of lines of <filename>

tail -10 <filename>– Give me the last ten lines from <filename>

Page 14: Top ESXi command line v2.0

Controlling Services with…Controlling Services with…

Interestingly enough, not “service”.– service is the Linux command for controlling

service state– Used in ESX

ESXi uses a slightly different syntax.– Services.sh {start|stop|restart}– This command will start|stop|restart all services.

– cat /etc/chkconfig.db to view the service database.– /etc/init.d/<servicename> restart– This command restarts a single service.

Page 15: Top ESXi command line v2.0

Manipulating text with viManipulating text with vi

Ahhh, vi, the text editor everyone loves to hate.– Big, bold, complex, oddball, challenging…

Two modes: Command and Input– “i” enters input mode. (also “a” and “o”)– “ESC” enters command mode.

– Control-F and Control-B move up and down by screen.– / <pattern> searches forward for a pattern.– ? <pattern> searches backward for a pattern.– “x” to delete a char, “dd” to delete a line– :q! exits without saving, :wq! exits with saving

Page 16: Top ESXi command line v2.0

File System Info with df and vdfFile System Info with df and vdf

The Linux command df displays file system information such as partitions.– df cannot see into VMFS volumes.

The ESX command vdf digs a bit further to gather VMFS information

Both commands support the -h switch– -h turns gibberish into human-readable info.

Page 17: Top ESXi command line v2.0

Processes with ps and killProcesses with ps and kill

The Linux ps command displays running processes.– Most commonly used with the -ef switch, usually

with grep as well.– ps –ef | grep <something>

Once you have a list of processes, you can kill them by Process ID.– kill <processID>– kill -9 <processID> (kill harder!)– kill -HUP <processID> (kill and restart!)

Page 18: Top ESXi command line v2.0

Pinging with…uh…ping and vmkpingPinging with…uh…ping and vmkping

You’re already familiar with the ping command (we use it every day in Windows).

But are you familiar with the VMware vmkping command?– Uses the VMKernel’s IP stack to another ESX host’s

VMKernel port.– Useful for troubleshooting vMotion and network

storage issues.– Similar results as ping, but down a different path.

Page 19: Top ESXi command line v2.0

Part 3:Part 3:The VMware CommandsThe VMware Commands

Page 20: Top ESXi command line v2.0

Swiss Army Knifing with vmkfstoolsSwiss Army Knifing with vmkfstools

Used for manipulating virtual disk files.– Copying– Converting– Renaming– Cloning– Importing– Exporting– Resizing

Page 21: Top ESXi command line v2.0

Swiss Army Knifing with vmkfstoolsSwiss Army Knifing with vmkfstools

Creating file systems & virtual disks– vmkfstools -C vmfs3 -b 1m -S myLabel

vmhba1:3:0:1 – vmkfstools -c 2G /vmfs/volumes/…/whatever.vmdk

Cloning virtual disks– vmkfstools -i {source} {destination}

Exporting virtual disks to ext3– vmkfstools -i -d 2gbsparse {source} {destination}

Extending virtual disks– vmkfstools -X 12G /vmfs/volumes/…/whatever.vmdk

Page 22: Top ESXi command line v2.0

Swiss Army Knifing with vmkfstoolsSwiss Army Knifing with vmkfstools

New Commands in 4.1!

Checking and repairing virtual disks– vmkfstools --fix check

/vmfs/volumes/…/whatever.vmdk– vmkfstools --fix repair

/vmfs/volumes/…/whatever.vmdk

Getting and resetting disk UUIDs– vmkfstools --miscop getuuid {vmdkFile}– vmkfstools --miscop setuuid {vmdkFile}

Page 23: Top ESXi command line v2.0

Getting on top with esxtopGetting on top with esxtop

The Linux top command is excellent for figuring out which process is consuming resources.– top

The VMware esxtop command goes a step further by digging into VMware-specific resources.– esxtop

Eight displays:“c” cpu, “i” interrupt, “m ” memory, “n” network“d” disk adapter, “u” disk device, “v ” disk VM, “p” power management

Page 24: Top ESXi command line v2.0

Exporting esxtop data to PerfMonExporting esxtop data to PerfMon

Perfmon’s graphing capabilities can be used to visualize esxtop data, with a little effort…– esxtop -a -b -d {secondsBetweenCaptures} -n

{numberOfCaptures} > {filename}.csv

The -a in the command above captures all counters.– Creates a very big file…– Can impact performance…– …but does let you use PerfMon to filter counters

(easier).

Page 25: Top ESXi command line v2.0

Exporting esxtop data to PerfMonExporting esxtop data to PerfMon

Ship esxtop data directly to Windows using ESXi’s SMB client and a mount point…

– mkdir /mnt– mkdir /mnt/perfmon– mount -t cifs //{server}/{share} -o

username={userName} password={password} /mnt/perfmon

– esxtop -a -b -d {secondsBetweenCaptures} -n {numberOfCaptures} > /mnt/perfmon/{filename}.csv

Page 26: Top ESXi command line v2.0

The esxcfg- CommandsThe esxcfg- Commands

esxcfg-hwiscsi esxcfg-rescan esxcfg-info esxcfg-resgrp esxcfg-dumppart esxcfg-route esxcfg-advcfg esxcfg-scsidevs esxcfg-ipsec esxcfg-init esxcfg-pciid esxcfg-volume esxcfg-module esxcfg-swiscsi esxcfg-nics esxcfg-vmknic esxcfg-nas esxcfg-vswitch esxcfg-mpath esxcfg-secpolicy

Page 27: Top ESXi command line v2.0

Networking with esxcfg-Networking with esxcfg-

Verify which physical NICs are up– esxcfg-nics -l

Creating a quick network connection– esxcfg-vswitch -a vSwitch2– esxcfg-vswitch -L vmnic2 vSwitch2– esxcfg-vswitch -A PortGroup2 vSwitch2– esxcfg-vswitch -M vmnic2 -p PortGroup2 vSwitch2– esxcfg-vswitch -v 205 -p PortGroup2 vSwitch2

Enabling and verifying Jumbo Frames– esxcfg-vswitch -m 9000 vSwitch2– esxcfg-vswitch -l

Page 28: Top ESXi command line v2.0

The vim-cmd CommandsThe vim-cmd Commands

vimsh is an interactive shell buffer used for configuration and reporting.– Vim-cmd is a wrapper for the vimsh shell.– This command has different names in different

versions: vimsh, vmware-vimsh, vmware-vim-cmd– Consolidates the command syntax overlap

between vmware-cmd (not on ESXi) and esxcfg-*.

Page 29: Top ESXi command line v2.0

VM and Storage info with vim-cmdVM and Storage info with vim-cmd

List vim-cmd commands– vim-cmd

Report all registered VMs– vim-cmd vmsvc/getallvms (…use this to get vmID!)

Register a VM– Vim-cmd solo/registervm ./whatever.vmx

Gather storage information– vim-cmd hostsvc/storage/info | less– vim-cmd hostsvc/storage/hba_info | less– vim-cmd hostsvc/storage/fs_info | less

Page 30: Top ESXi command line v2.0

More fun with vim-cmdMore fun with vim-cmd

Check and toggle VM power status– vim-cmd vmsvc/power.getstat {vmID}– vim-cmd vmsvc/power.off {vmID}– vim-cmd vmsvc/power.off {vmID}

Add a physical USB device to a VM– /etc/init.d/usbarbitrator start– vim-cmd vmsvc/device.connusbdev {vmID}

“path:1/0/0 autoclean:1”

Add a license key– vim-cmd vimsvc/license --set {25CharLicenseKey}

Page 31: Top ESXi command line v2.0

The esxcli CommandsThe esxcli Commands

Another interactive shell framework for configuration and reporting.– Modular, ability to add namespaces.– Can be executed in ESX/ESXi/vCLI.– Three namespaces at present:

nmp, corestorage, swiscsi.

Page 32: Top ESXi command line v2.0

iSCSI Multipathing with esxcliiSCSI Multipathing with esxcli

Configure the LUN Create VMkernel port groups Create 1:1 vNIC->VMkernel port mappings Enable iSCSI

Connect VMkernel ports to iSCSI Initiator– esxcli swiscsi nic add -n {VMkPortGroup} -d

vmhba33

Adjust path selection to Round Robin Create datastore

Page 33: Top ESXi command line v2.0

iSCSI Multipathing with esxcliiSCSI Multipathing with esxcli

Page 34: Top ESXi command line v2.0

More fun with esxcliMore fun with esxcli

List active TCP/IP connections and ARP entries– esxcli network connection list– esxcli network neighbor list

List running VMs & kill those non-responding– esxcli vms vm list– esxcli vms vm kill --world-id {worldID} --type

{soft|hard|force}

Page 35: Top ESXi command line v2.0

Host Updates with esxupdateHost Updates with esxupdate

Installing updates from the command line is a secondary tactic when automation fails.– esxupdate update –bundle=<bundlename.zip>

Can even assist with (major) 4.0 to 4.1 upgrades– Run the pre-upgrade, then the upgrade bundle while

in maintenance mode.

– esxupdate update --bundle=pre-upgrade-from-ESX4.0-to-4.1.0-0.0.260247-release.zip

– esxupdate update --bundle=upgrade-from-ESX4.0-to-4.1.0-0.0.260247-release.zip

– reboot

Page 36: Top ESXi command line v2.0

Troubleshoot with vm-supportTroubleshoot with vm-support

Calls with VMware often require sending them a support bundle.– Inside that bundle are logs, output from

commands, and configuration info.– vm-support will create a .tgz archive to send.

Can also be used to stop stalled VMs.– These VMs show resources are assigned, but don’t

appear to be running.– vm-support -x then vm-support –X <worldID>.

– First command gets the world ID– Second command kills processes of that world ID.

Page 37: Top ESXi command line v2.0

Part 4:Part 4:The vMA and ScriptingThe vMA and Scripting

Page 38: Top ESXi command line v2.0

VMware Management AssistantVMware Management Assistant

All of these commands are handy, but the shell is quite limiting.

Needed is a command and scripting environment for managing ESX and ESXi hosts.– One such environment is the vMA.– Installed as a Virtual Appliance.– Client/Server architecture connects to multiple

machines, can work with multiple machines at once.

– Enables use of Perl for scripting.

Page 39: Top ESXi command line v2.0

InstallingInstalling

Because of itsVirtual Applianceroots, installing thevMA requires usingthe vSphere Client.

Ensure you connectvMA to ESXi’smanagementnetwork.

Page 40: Top ESXi command line v2.0

Installing and ConfiguringInstalling and Configuring

Install vMA Virtual Appliance from OVF Update VMX file to correct error

– scsi0.virtualDev = “lsilogic”– guestOS = “rhel5-64″

Configure vMA at first boot Add target servers to vMA

– vifp addserver {serverName}

Target a server to run a command against– vifptarget -s {serverName}

Use! Command! Script!

Page 41: Top ESXi command line v2.0

The vicfg- CommandsThe vicfg- Commands

vicfg-advcfg vicfg-ntp vicfg-authconfig vicfg-rescae vicfg-cfgbackup vicfg-route vicfg-dns vicfg-scsidevs vicfg-dumppart vicfg-snmp vicfg-hostops vicfg-syslog vicfg-ipsec vicfg-user vicfg-iscsi vicfg-vmknic vicfg-module vicfg-volume vicfg-mpath vicfg-vswitch vicfg-nas

Page 42: Top ESXi command line v2.0

Final ThoughtsFinal Thoughts

Linux isn’t hard.– It was just developed by some very weird people

over a very long period of time.– That group of people didn’t always agree on which

commands to use. That’s why different distros use different command structures.

– Silly UNIX admins.

Always remember two discovery commands…– find / -name <something>– <command> --help

Those two commands will always help!

Page 43: Top ESXi command line v2.0

ESXi v4.1 Command Line Tricks You ESXi v4.1 Command Line Tricks You Absolutely Must KnowAbsolutely Must Know

Greg ShieldsGreg ShieldsPartner and Principal TechnologistConcentrated Technologywww.ConcentratedTech.com

Please fill out evaluations,Do it for the children!

!!!

Page 44: Top ESXi command line v2.0

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC