Top ESXi command line v2.0

Post on 05-Dec-2014

13.806 views 4 download

Tags:

description

 

Transcript of 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

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

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

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

The ESXi Command LineThe ESXi Command Line

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

The ESXi Command LineThe ESXi Command Line

…however, it is not enabled by default.

Part 2:Part 2:The Linux CommandsThe Linux Commands

The Linux CommandsThe Linux Commands

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

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…

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.

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

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.

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>

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.

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

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.

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!)

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.

Part 3:Part 3:The VMware CommandsThe VMware Commands

Swiss Army Knifing with vmkfstoolsSwiss Army Knifing with vmkfstools

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

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

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}

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

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).

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

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

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

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-*.

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

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}

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.

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

iSCSI Multipathing with esxcliiSCSI Multipathing with esxcli

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}

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

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.

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

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.

InstallingInstalling

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

Ensure you connectvMA to ESXi’smanagementnetwork.

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!

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

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!

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!

!!!

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