免费VMware高可用性的方法

首先介绍一下HA的简单原理:如果你的ESX服务器在14秒内没有响应,那么将所有的虚拟机注册并运行到另外一个ESX服务器。下面的脚本可以帮你实现这个功能(把它取名为/usr/bin/esx_ha.sh):

#!/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

然后使它变为可执行: chmod a+x /usr/bin/esx_ha.sh

该脚本实现了:如果ESX服务器服务控制台10.8.0.1在14次ping内都没有反应的话,把在/etc/other_host文件中的所有虚拟机注册并运行到当前的ESX服务器上(如10.8.0.2)。接着延时16秒,重复相同的脚本。

other_host文件可以通过以下的命令生成: vmware-cmd -l | sed ’s/ / /g’ > /root/other_host

接着只要scp这个/root/other_host文件到其他的ESX服务器的/etc目录下。然后以root身份运行crontab -e,并输入下列文本:

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

那么该脚本就会在每分钟运行2次来实现HA功能。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注