Vmware vMA basics

What is the vMA?

vMA stands for vSphere Management Assistant.  Is it a virtual appliance provided by vmware that is running SUSE Linux 11 and has some custom vmware commands for scripting and authentication that allows you to manage a vmware infrastructure.   You can download it from Vmware for free from this location:

http://www.vmware.com/support/developer/vima/

In order to deploy into your infrastructure you need to deploy it into your ESXi host like any other virtual appliance:

From the web client

  • vCenter -> Hosts -> select your ESXi host
  • Actions -> Deploy OVF Template
  • Go through the prompts to deploy

Once the OVF has been deployed you can power it on.  It will ask you for ip information.  Once it’s setup with ip you can manage it via the web interface https://your_ip:5480.  From here you can setup common settings and update the machine.   You just need to login as vi-admin with the default password of vmware.  Make sure to change this default password in the web interface.

Command Line

vMA’s real power is in the command line you can access it via ssh logging in as vi-admin.    Vmware has included all their common commands but one command is very powerful it’s vifp (vi fast pass) this allows you to stored login information for ESXi hosts so you don’t have to type them on every script.   You can use it like this:

To add a server (you should do this for vcenter and each ESXi host):

vifp addserver vcenter_or_esxi_host

To see what servers you have in vifp type the following:

vifp listservers

There are times where you want to manage only one host at a time you can select your target server via this command

vifptarget -s server_to_manage_name_from_listservers

Once you have selected a target you will notice it as part of your command line prompt.

Once you have added hosts and selected a target any vmware commands you run will be against the target host.

You can also add the vMA to active directory so you don’t have to store the passwords in vifp.  This is done via :

sudo domainjoin-cli join domain_name domain_admin_user

Commands:

Since the vMA is running SUSE linux a full featured linux kernel is available to us.  Which means there are a lot of things we can do to make our life easier.   You can use aliases and variables.  For example if I wanted to execute the command:

esxcli hardware cpu list

I could use variables to help:

variable_name=”data for variable”
For example:

cmd="hardware cpu list"

Then I could create an alias for the esxcli command:

alias e="esxcli"

Then I could run the following command:

e $cmd

And that would execute

esxcli hardware cpu list

If you want to keep these aliases or variables then you can add them to your environment settings via these commands:

vi ~/.profile

Add your variables and aliases and they will be available to you when you login.  There is one word of caution these variables are not available to your scripts unless you manually run them.  Any variables you need in scripts should be included in the scripts.

Some common aliases I use are the following:

alias e='esxcli'
alias v='vmware-cmd'
conn="Your connection information for older commands"

ETH0 missing after cloning a Linux virtual machine

This is a fun one.  I never used to have this problem with RHEL 5 but RHEL 6 and debian based distros have had this issue all along.   You clone from a Linux template and you get a new mac address.  But the new interface comes in as ETH1 or perhaps if you have multiple generations you might have eth6 or eth7.  How do you clear this up?  Well it’s all about the fact that the operating system keeps track of the mac address in it’s udev rules. So open up /etc/udev/rules.d/70-persistent-net.rules and delete all the mac address entries.  Once you reboot the machine you should have your interface come in as eth0 again.

In Debian it is normally named: /etc/udev/rules.d/z25_persistent-net.rules.

Enjoy!

How do I backup individual esxi hosts

Using the vMA you can backup and restore individual ESXi hosts using the vicfg-cfgbackup  command.   If you log into your vMA and type vicfg-cfg-backup –help you get some of the following information:

Synopsis: /usr/bin/vicfg-cfgbackup OPTIONS [<backupfile>]

Command-specific options:
 --force
 -f
 Force the restore of the configuration.
 --load
 -l
 Restore configuration onto the host
 --quiet
 -q
 Do not prompt for user confirmation.
 --reset
 -r
 Resets host, restore to factory settings.
 --save
 -s Backup the host configuration.

So in order to backup your ESXi host you just need to select a host and do a -s.  I like to do these sort of things automatically.   Here is my setup:

  • Create a location for backups
mkdir ~/backup
  • Create a script to do backups
#!/bin/bash
# Script created by Joseph Griffiths
# bloodygranola.com
# Date to create a unique file
date=`/bin/date '+%m-%d-%y-%H-%M'`;
# Directory to put the backup
backupdir="/home/vi-admin/backup"
# How many days we should keep backups
days="30"
# Function to do backup
function backup(){
/opt/vmware/vma/bin/vifptarget -s $1
/usr/bin/vicfg-cfgbackup -s $backupdir/$1-$date.bak
}
# Do the backup
backup "esxi01.vclass.local";
backup "esxi02.vclass.local";
# Clean up
find $backupdir -mtime +$days -exec rm -rf {} \;

Well we want to run this automatically each day correct?  We can do that with crontab lets set it for 2 am everyday

crontab -e

Enter the following:

0 2 * * * /home/vi-admin/backup.sh > /dev/null 2>&1

What about restoring?

It’s done with the same command except the -f for force and -l for load

vicfg-cfgbackup -f -l filename

How do vmware tools communicate with the host?

Great question.  Well with ESXi 5.1 they communicate with the host via a virtual chip that is part of the virtual hardware.  Vmware tools access this chip and the host accesses the chip allowing for communication without networking.   Vmware even provides a API to program against this chip to create socket communication.

vCop’s appliance unable to connect to vCloud director

I ran into this one last week.  I was trying to tie my vCop’s instance into vCloud director with the vCloud adapter.   I tried using the hostname / ip without any success.  Some review of the logs for the adapter showed:

2013-08-08 14:57:50,272 ERROR [Collector worker thread 21] (171) com.integrien.adapter3.vcloud.VCloudAdapter.login - Exception occurred in login:
com.vmware.vcloud.sdk.VCloudRuntimeException: org.apache.http.NoHttpResponseException: The target server failed to respond

I just love java errors… I will spare you all the crap that came after.  The problem was simple but I had not expected it… DNS resolution was not working.  I did not believe it… why would I need DNS when I was using the ip address of my systems.   Well it’s a little complex by vcloud is three cells frontended by a F5 load balancer.   I was using the ip address of the load balancer but the public URL in VCD was set to a DNS name.  When you visit the ip address it redirects you and vcop’s to https://fqdn/vcloud  this redirection using DNS was causing the failure.   So we just have to get the linux appliances to see DNS.

  1. Login as root on both the UI and analytics machine
  2. Change the file /etc/sys/esxiconfig/network/configs
  3. Add the following line
  4. NETCONFIG_DNS_STATIC_SERVERS=”IP_ADDRESS_FOR_DNS_WITH_SPACES_FOR_MULTIPLES”
  5. Run the following command to sync to /etc/resolv.conf
  6. netconfig update -f

Then it should work.  Enjoy.

How do I improve network performance between VM’s

Let’s create an example situation.  You have two machines a application server and a database.  These machines do a lot of network traffic to each other.  You want to ensure they have the best possible performance.  In vmware worlds there are a few tricks to help you out.  First make sure your using the latest vmknic available.  After you have upgraded the nic’s the only thing left is to take advantage of the vmware ring buffer.

What is the vmware ring buffer?

Since virtual switches are defined as software dumb switches they operate in ram.  Ram is really fast.  So if you can send a message without leaving your virtual switch it can be really fast.   The ring buffer exists on each esxi host and where possible allows guests to communicate with each other (layer 2 so they have to be in the same subnet)  without involving anything but RAM.  You can see a 2X performance gain by just using the ring buffer.

How do I use it?

Keep your talking vm’s on the same host using affinity rules and your all set.

What is .dvsData

So you have noticed this folder on your datastore called .dvsData what is it?

This is a folder that stores information on a virtual machines connected port when connected to a virtual distributed switch.   Inside this folder is a subdirectory with the UUID of the distrubuted switch. Inside that folder are files that represent a port binding on the vDS switch (which is a specially configured hidden vSwitch).

You can find the vDS’s UUID via the following command:

esxcli network vswitch dvs vmware list

This will also give you a port ID which ties to the file name:

Name: vDS-01
 VDS ID: 14 5e 0d 50 af f5 6d 3a-30 ad 00 b0 f5 d7 cc ce
 Class: etherswitch
 Num Ports: 512
 Used Ports: 4
 Configured Ports: 512
 MTU: 1500
 CDP Status: listen
 Beacon Timeout: -1
 Uplinks: vmnic1
 VMware Branded: true
 DVPort:
 Client: vmnic1
 DVPortgroup ID: dvportgroup-53
 In Use: true
 Port ID: 2
Client:
 DVPortgroup ID: dvportgroup-53
 In Use: false
 Port ID: 3
Client:
 DVPortgroup ID: dvportgroup-55
 In Use: false
 Port ID: 132
Client: Win01-A.eth0
 DVPortgroup ID: dvportgroup-55
 In Use: true
 Port ID: 133
Client:
 DVPortgroup ID: dvportgroup-55
 In Use: false
 Port ID: 135
Client:
 DVPortgroup ID: dvportgroup-55
 In Use: false
 Port ID: 134

Vmware command line start / stop hosts or maintenance mode

Ok it’s rare that I need to do this from the command line but it’s possible from the vMA:

Shutdown host:

vicfg-hostops --server server_name --username user_name --password pass_word --operation shutdown

Reboot host:

vicfg-hostops --server server_name --username user_name --password pass_word --operation reboot

Enter Maintenance mode:

vicfg-hostops --server server_name --username user_name --password pass_word --operation enter

Exit Maintenance mode:

vicfg-hostops --server server_name --username user_name --password pass_word --operation exit

Info on Maintenance mode:

vicfg-hostops --server server_name --username user_name --password pass_word --operation info

Vcenter Install failed port 80 in use

I normally use a Oracle backend for my database to vcenter but the other day I setup a single box with SQL server for the database.  I ran into issues with port 80 already being in use.  After a few netstats I found it was the SQL Server Reporting Services.  Which unless you plan on doing reporting can be safely turned off and shutdown.