Script for VMware HA Feature without VirtualCenter

Thursday, October 22, 2009 by BBTUNA

So, who wants free VMware High Availability? That’s the title of a post created by Leo Raikhman on his Leo’s Ramblings blog. In this post, Leo has published the steps and scripting necessary to simulate VMware’s VI3 High Availability (HA) feature. Leo’s script works without VirtualCenter (VC), so VMware customer’s who have not implemented VC can manually create “HA -like” awareness between 2 ESX hosts. If one of the ESX servers goes offline then the virtual machines (VMs) are auto restarted on the other host. Of course, the VMs must be created on shared storage for this to work.

Before considering this script as a replacement understand the major differences between VirtualCenter HA and Leo’s HA:

  • Leo’s script only works between 2 ESX hosts while VC HA can be configured with up to 32 ESX hosts as of VI 3.5 (actually using 32 host HA clusters is another topic, but it can be done)
  • Leo’s script needs the ESX Service Console as written. It would need to be ported for the RCLI to work with ESXi. VC HA works with both ESX and ESXi
  • VC provides a visual status for the health of your HA cluster via the VI Client
  • VC HA provides HA fail over capacity for more than 1 ESX host at a time

I’ve held this post in my drafts because I wanted to try this configuration myself, but alas, I have never gotten around to it. For those that can benefit from VC -less HA and give this script a test, let me (and Leo) know your results.

Leo’s post says:


“First of all lets talk about the basics of what HA actually does: if your ESX server doesn’t respond to a heartbeat for 14 seconds, the other host registers all machines and starts them up. “

Here’s the process from Leo’s Ramblings with the scripts, commands and instructions:

Create a list of the VMs on each host and copy to the other host

But there’s a few other tricks. How do you generate that other_host file? Here’s how. On each host run the following command:

vmware-cmd -l | sed ’s/\ /\\ /g’ > /root/other_host

What you’ve done is just dumped all registered machines on each host to the /root directory.

Now, scp each /root/other_host file to the other ESX server’s /etc directory.

In each /etc/other_host file, re-organize the VM order if you want them to start up differently and delete VMs that you don’t want to start up.

Create the HA script and make it executable

#!/bin/bash
if ! ping -c 14 10.8.0.1 > /dev/null; then
for $i in `cat /etc/other_host` ; do vmware-cmd -s register $i && vmware-cmd $i start ; done
fi
sleep 16
if ! ping -c 14 10.8.0.1 > /dev/null; then
for $i in `cat /etc/other_host` ; do vmware-cmd -s register $i && vmware-cmd $i start ; done
fi

Then I made it executable:

chmod a+x /usr/bin/esx_ha.sh

Here’s what the script does:

If for 14 pings, an ESX server with Service Console IP 10.8.0.1 does not reply, then, browse the contents of the file /etc/other_host, register every listed machine there on the current host (10.8.0.2) an start them up, one by one. Then it sleeps for 16 seconds, and executes the same thing again.

Seems easy enough.

Create a cron entry to start auto HA

Now we need to create a cron entry as root by running crontab -e as the root user. The screen that opens works like vi, input the following text:

MAILTO=”youremail@yourcomapny.com
* * * * * /usr/bin/esx_ha.sh

This means, that on the minute, every minute of the day, the script (which runs twice a minute) will execute and provide HA for you.

Posted in | 0 Comments »

0 comments:

Post a Comment

About Me