Monday, October 14, 2013

Setting Up VMWare ESXi 5.1 and Installing a VM

The main goal of this project is to have an ESXi host run several vm's using various datastores including local, nfs, and iscsi.  There should be a management network that is tagged and uses vlan 101 that the vm's will use for updates to the os and administrative intervention, and a production network that is tagged and will use the vlan id 100.  The iso's used will be FreeBSD-9.1 and CentOS 6.4.

Step 1:
Sign up for an account on vmware.com and download the VMWare ESXi iso along with the vsphere client.  VMWare ESXi 5.1 update 1 will be used.

Step 2:
Burn iso to disc or usb.  Unetbootin was used.

Step 3:
Install vmware esxi on the machine that will be used to host the vm's.  Pretty much next next finish.  The 10.0.0.x/8 network will be used for the esxi host, 172.16.0.x/16 as production, and 192.168.1.0/24 for management.  The VMWare host will get 10.0.0.1.

Step 3a (optional):
Enable ssh on the vmware esxi host.  From the console of the esxi host, log in and click on "Troubleshooting Options", then "Enable SSH".

Step 4:
Install vsphere client on a machine.  A windows xp machine in a vm using virtualbox will be used.  Pretty much next next finish.

Step 5:
Set up the local machine network.  The esxi host network will be the native vlan, the production network will be vlan 100, and the management network will be vlan 101.  A switch capable of doing vlan tagging is not available, so the local machine will be used for the trunk port, which is also running the windows vm which is running the vsphere application.  On the local machine, execute:

ip addr add 10.0.0.2/8 dev enp1s0

For vlan 100, Execute:
ip link add link enp1s0 name eth0.100 type vlan id 100
ip addr add 172.16.0.1/16 brd 172.16.0.255 dev eth0.100
ip link set dev eth0.100 up

And verify the link is up with:
ip link
...trim...
eth0.100@enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT 
...trim...
route -n
...trim...
172.16.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0.100
...trim...
ping 172.16.0.1
...trim...
64 bytes from 172.16.0.1: icmp_seq=1 ttl=64 time=0.063 ms
64 bytes from 172.16.0.1: icmp_seq=2 ttl=64 time=0.056 ms
...trim...
 
For vlan 101, Execute:
ip link add link enp1s0 name eth0.101 type vlan id 101
ip addr add 192.168.1.1/24 brd 192.168.1.255 dev eth0.101
ip link set dev eth0.101 up

And verify the link is up with:
ip link
...trim...
eth0.101@enp1s0:  mtu 1500 qdisc noqueue state UP mode DEFAULT
...trim...
route -n
...trim...
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0.101
...trim...
ping 192.168.1.1
...trim...
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.068 ms
...trim...

Log in to the esxi host from the windows xp vm:

Step 6:
Set up the esxi host network.  Once logged in to the host through vsphere, click on the "Configuration" tab, then on "Networking".  On "vSwitch0", create a "Production" port group with vlan id 100 and a "Management" port group with vlan id 101.

There is now an esxi host that connects directly to the local machine over ethernet.  The connection has a native vlan using 10.0.0.0/8, with 10.0.0.1 as the esxi host and 10.0.0.2 as the local machine that has a vm running windows xp and the vsphere client using nat, 172.16.0.0/16 as the production network on vlan 100 where 172.16.0.1 is an svi on the local machine, and 192.168.1.0/24 as the management network on vlan 101 where 192.168.1.1 is an svi on the local machine.

Step 7:
Install CentOS 6.4 on the esxi host.  Right click the esxi host in the vsphere client, and choose "New Virtual Machine".  On the first screen, choose "Custom".  Leave everything the default with the exception of the networking section where two interfaces are used: the "Managment" and "Production" port group.

Once complete, right click on the "CentOS 6.4" vm under the 10.0.0.1 esxi host, and choose "Edit Settings".  Click on the "Options" tab, and select "Boot Options".  Check the option that says "The next time the virtual machine boots, force entry into the BIOS setup screen."

Power on the vm.  The vm should stop at a bios screen.  Attach the CentOS iso from the local machine.  Towards the top of the screen, click on the icon that is a cd with a wrench, and select "Connect to ISO image on local disk...".  Select the iso image from your local machine that you want the esxi host to use for this vm, and hit ok.  Install the centos machine normally.

Step 8:
Allow access to the internet on the new vm over the management vlan, vlan 101.  On the local machine, where wlp2s0 is the external connection and eth0.101 is the vlan that needs internet access, execute:

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o wlp2s0 -j MASQUERADE
iptables -A FORWARD -i wlp2s0 -o eth0.101 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0.101 -j ACCEPT
iptables -A FORWARD -j DROP

Step 9:
Configure centos networking.  See the screenshot below, eth0 is management, eth1 is production.


Add a nameserver.
echo "nameserver 8.8.8.8 > /etc/resolve.conf"


There is now an esxi host directly attached to a local machine that carries a native vlan, a production vlan, and a management vlan.  The management vlan has internet access and the local machine can be used to set policy on the outgoing traffic coming in on the trunk uplink from the esxi host.

No comments:

Post a Comment