Script to configure ISCSI settings on VMWare ESX 3.5
October 1, 2008
| Overall Rating | No Ratings |
Script to configure ISCSI settings on VMWare ESX 3.5
If you have only a handful of ESX hosts it is not such a big deal to install and configure them by hand, but once your number of ESX hosts exceeds the fingers on one of your hands this becomes a major pain in the rear. Especially when you consider that sometimes rebuilding is the better option than troubleshooting an issue and waiting for VMWare’s support to eventually come back to you. Currently I have it down to rebuild and configure an ESX host in about 20 minutes (plus a few minutes maybe to disconnect the existing storage for safety reasons).
For a set of 4 new ESX hosts we moved from SAN storage to ISCSI storage and that required a different look at the scripted install. We are using the ESX Software ISCSI and are going through 4 different NICs and 4 different controllers for redundancy. This bumps the ISCSI related number of IP addresses up to 32 (4 Ips for the NICs and 4 Ips for the additional service consoles). Configuring this by hand would probably take 15-20 minutes per host. “No, Thank you!”
So, the following post installation script configures the ISCSI related pieces via shell sripting. The entire process now takes about 2.5 minutes per host + one additional reboot. So, if you want to script the ISCSI settings on your host you could use this script for VMWare ESX 3.5 U2 (probably works for any 3.5 flavor). just replace names and IP addresses to match your environment and your are. I have a total of 4 scripts now that I run as a post install script (with some other pieces included, but for here we are only looking at the ISCSI stuff).
Let’s start with creating the virtual Switches for the ISCSI connections. This section creates the switches and assigns physical NICs.
# Create vSwitch2 (ISCSI)
esxcfg-vswitch -a vSwitch2
# Add physical NICS to vSwitch2
esxcfg-vswitch -L vmnic4 vSwitch2
# Create vSwitch3 (ISCSI)
esxcfg-vswitch -a vSwitch3
# Add physical NICS to vSwitch3
esxcfg-vswitch -L vmnic5 vSwitch3
# Create vSwitch4 (ISCSI)
esxcfg-vswitch -a vSwitch4
# Add physical NICS to vSwitch4
esxcfg-vswitch -L vmnic6 vSwitch4
# Create vSwitch3 (ISCSI)
esxcfg-vswitch -a vSwitch5
# Add physical NICS to vSwitch5
esxcfg-vswitch -L vmnic7 vSwitch5
Next we want to create the Vkernel Port Groups for the ISCSI
# Create VMKernel Port Group for ISCSI
esxcfg-vswitch -A 10.10.244-A vSwitch2
esxcfg-vmknic -a -i 10.10.244.10 -n 255.255.255.128 10.10.244-A
esxcfg-vswitch -A 10.10.244-B vSwitch3
esxcfg-vmknic -a -i 10.10.244.140 -n 255.255.255.128 10.10.244-B
esxcfg-vswitch -A 10.10.245-A vSwitch4
esxcfg-vmknic -a -i 10.10.245.10 -n 255.255.255.128 10.10.245-A
esxcfg-vswitch -A 10.10.245-B vSwitch5
esxcfg-vmknic -a -i 10.10.245.140 -n 255.255.255.128 10.10.245-B
As the next step we want to add the Service Console to those virtual switches
# Add a Service Console to the vSwitches
esxcfg-vswitch –add-pg="Service Console 10.10.244-A" vSwitch2
esxcfg-vswitch –add-pg="Service Console 10.10.244-B" vSwitch3
esxcfg-vswitch –add-pg="Service Console 10.10.245-A" vSwitch4
esxcfg-vswitch –add-pg="Service Console 10.10.245-B" vSwitch5
esxcfg-vswif -a -i 10.10.244.14 -n 255.255.255.128 -p "Service Console 10.10.244-A" vswif1
esxcfg-vswif -a -i 10.10.244.144 -n 255.255.255.128 -p "Service Console 10.10.244-B" vswif2
esxcfg-vswif -a -i 10.10.245.14 -n 255.255.255.128 -p "Service Console 10.10.245-A" vswif3
esxcfg-vswif -a -i 10.10.245.144 -n 255.255.255.128 -p "Service Console 10.10.245-B" vswif4
Now let’s enable the ISCSI Initiator
# Enable iSCSI Initiator
esxcfg-swiscsi -e
If you want to use the Dynamic Discovery of the ISCSI Controller targets, you will want to add them. The "wait" is needed for each command to complete. This is where you will need 2 minutes off the 2.5 I promised earlier.
# Add ISCSI Targets
vmkiscsi-tool -D -a 10.10.244.3:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.244.4:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.244.130:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.244.131:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.245.3:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.245.4:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.245.130:3260 vmhba32
wait
vmkiscsi-tool -D -a 10.10.245.131:3260 vmhba32
wait
Good, we’re almost done now. Let’s change the cryptic ISCSI Name to something more readable
# Change ISCSI Host Name
echo "InitiatorName=iqn.1998-01.com.vmware:hostname.mydomain.com" > /etc/initiatorname.vmkiscsi
Excellent. We’re pretty much done. Let’s reboot the server automatically.
# Reboot the server.
reboot
If all went well, your ISCSI configuration is now fully scripted.
Comments
Got something to say?
You must be logged in to post a comment.

