How To Install CentOS 6.3 KVM on vSphere 5.1

Step 4 – Configure Linux Networking and OVS Bridges

Finally configure your Networking and Name Servers.  For networking you will need to set up Linux Bridges for each Interface for later use by KVM, and Nicira NVP Open vSwitch.  You’re files should look similar to the examples below but first create new Bridge Interfaces:

Create new bridge interface configuration files:

# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-br0
# cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-br1
# cp /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-br2
Example Configuration for ifcfg-eth0:DEVICE=”eth0″
ONBOOT=”yes”
NAME=”System eth0″
Example Configuration for ifcfg-eth1:DEVICE=”eth1″
ONBOOT=”yes”
NAME=”System eth1″
Example Configuration for ifcfg-eth2:DEVICE=”eth2″
ONBOOT=”yes”
NAME=”System eth2″
Example Configuration for ifcfg-br0:DEVICE=”br0″
TYPE=Bridge
BOOTPROTO=”static”
ONBOOT=”yes”
IPADDR=<Management IP>
NETMASK=<netmask>
GATEWAY=<gateway>
NAME=”System breth0″
Example Configuration for ifcfg-br1:DEVICE=”br1″
TYPE=Bridge
BOOTPROTO=”static”
ONBOOT=”yes”
IPADDR=<Transport IP>
NETMASK=<netmask>
NAME=”System breth1″
Example Configuration for ifcfg-br2:DEVICE=”br2″
TYPE=Bridge
BOOTPROTO=”static”
ONBOOT=”yes”
IPADDR=<Storage IP>
NETMASK=<netmask>
NAME=”System breth2″

Create Open vSwitch Bridges for Each Interface

# ovs-vsctl add-br br0
# ovs-vsctl br-set-external-id br0 bridge-id br0
# ovs-vsctl set Bridge br0 fail-mode=standalone
# ovs-vsctl add-port br0 eth0
# ovs-vsctl add-br br1
# ovs-vsctl br-set-external-id br1 bridge-id br1
# ovs-vsctl set Bridge br1 fail-mode=standaloneo
# ovs-vsctl add-port br1 eth1
# ovs-vsctl add-br br2
# ovs-vsctl br-set-external-id br2 bridge-id br2
# ovs-vsctl set Bridge br2 fail-mode=standalone
# ovs-vsctl add-port br2 eth2

Restart The Network Services

# service network restart

Step 5 – Edit /etc/libvirt/qemu.conf

This is required for any version of libvirt that is 0.9.10 or lower and for the case of CentOS 6.3 the version of libvirt is 0.9.10

Find and Uncomment:

cgroup_controllers = [ "cpu", "devices", "memory" ]

Find and Uncomment, as well as add the reference to “/dev/net/tun”

cgroup_device_acl = [
"/dev/null", "/dev/full", "/dev/zero",
"/dev/random", "/dev/urandom",
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
"/dev/rtc", "/dev/hpet", "/dev/net/tun"
]

Find, Uncomment and set:

clear_emulator_capabilities=0

Find and uncomment:

user = "root"
group = "root"

Restart the libvirt service:

# service libvirtd restart

Step 6 – Create Generic Control Scripts for libvirt 0.9.10 and Lower

Like the above process these scripts are used ny libvirt to connect the Virtual Machines to the Open vSwitch on power up and power down.  This is only needed for libvirt 0.9.10 and lower as well and that is the case for CentOS 6.3

Create /etc/ovs-ifup-generic and make the file executable:

#!/bin/sh
if [ $# -ne 3 ]; then
echo "usage: DEVICE IFACE_ID ATTACHED_MAC"
exit 1
fi
/sbin/ifconfig $1 0.0.0.0 up
ovs-vsctl add-port br-int $1 -- \
set Interface $1 external-ids:iface-id=$2 -- \
set Interface $1 external-ids:attached-mac=$3 -- \
set Interface $1 external-ids:iface-status=active

For convienence I have also supplied a version of the file here:  [s3file s3url=”ovs-ifup-generic.txt” ]Download File[/s3file]

Simply download it and copy it to /etc/ovs-ifdown-generic and make it executable

Create /etc/ovs-ifdown-generic and make the file executable:

#!/bin/sh
/sbin/ifconfig $1 0.0.0.0 down
ovs-vsctl del-port $1

For convienence I have also supplied a version of the file here: [s3file s3url=”ovs-ifdown-generic.txt” ]Download File[/s3file]

Simply download it and copy it to /etc/ovs-ifdown-generic and make it executable

Replace script links with new links:

# rm /etc/qemu-if*
# ln -s /etc/ovs-ifup-generic /etc/qemu-ifup
# ln -s /etc/ovs-ifdown-generic /etc/qemu-ifdown

Step 7 – Create and Deploy Virtual Machines

Now you can create virtual machines with the virsh commands or using SSH with the -X switch and using virt-manager.  Either way once you create them you need to edit the XML files networking section in order to use these new scripts and connect them to the Open vSwitch.  In most cases this is where the Cloud Management System comes into play, but I will at least give the changes to the files below.

Setup Per VM Control Scrips To connect NIC’s:

The actual location and file strucure is up to you but you will need to know this to edit the Virtual Machine’s XML file

# vi /var/lib/libvirt/images/[DOMAIN]/[DOMAIN]-interfaces

Edit the File with these lines where [DOMAIN]=The Virtual Machine Name

#!/bin/sh
/etc/ovs-ifup-generic $1 [DOMAIN]-iface1

Edit the Domain (Virtual Machine’s) XML file for the BOLD sections:

# virshedit [DOMAIN]
......Snipped

/usr/libexec/qemu-kvm
<target dev='[DOMAIN]/> 
<model type='virtio'/>
</interface> 
<graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/> 
</devices>

.......Snipped

About Chris Colotti

Chris is active on the VMUG and event speaking circuit and is available for many events if you want to reach out and ask. Previously to this he spent close to a decade working for VMware as a Principal Architect. Previous to his nine plus years at VMware, Chris was a System Administrator that evolved his career into a data center architect. Chris spends a lot of time mentoring co-workers and friends on the benefits of personal growth and professional development. Chris is also amongst the first VMware Certified Design Experts (VCDX#37), and author of multiple white papers. In his spare time he helps his wife Julie run her promotional products as the accountant, book keeper, and IT Support. Chris also believes in both a healthy body and healthy mind, and has become heavily involved with fitness as a Diamond Team Beachbody Coach using P90X and other Beachbody Programs. Although Technology is his day job, Chris is passionate about fitness after losing 60 pounds himself in the last few years.

Leave a Reply

Your email address will not be published. Required fields are marked *