Why?


Search This Blog

Saturday, May 23, 2015

Install KVM server on CentOS 6.6

Install KVM server on CentOS 6.6

See the meta packages contained in:

# yum grouplist | grep -i virt

Install all the packages you might need.

# yum -y groupinstall virt*

# yum -y install @virt* dejavu-lgc-* xorg-x11-xauth tigervnc \
libguestfs-tools policycoreutils-python bridge-utils kvm libvirt

# yum -y update libvirt kvm


Sanity check

# service libvirtd restart
Stopping libvirtd daemon:           [  OK  ]
Starting libvirtd daemon:           [  OK  ]
# lsmod | grep kvm
kvm_intel             144706  0
kvm                   467756  1 kvm_intel


Ensure local root connectivity

# virsh sysinfo
<sysinfo type='smbios'>
  <bios>
    <entry name='vendor'>American Megatrends Inc.</entry>
    <entry name='version'>F2</entry>
    <entry name='date'>05/09/2014</entry>
    <entry name='release'>4.6</entry>
  </bios>
  <system>

...

Verify if KVM group was created on installation

# cat /etc/group | grep kvm
kvm:x:36:qemu



**Do if you have selinux enabled

If you have use any directories other than /var/lib/libvirt for kvm files, set the selinux context. In this example I use /vm to store my disk image files.

# semanage fcontext -a -t virt_image_t "/vm(/.*)?"; restorecon -R /vm

**END Do if you have selinux enabled

!!NOTE!! Do Configure Bridged Network from server console as you may loose network connectivity !!

Configure Bridged Network


I am using network 192.168.10.0/24 with my gateway of 192.168.10.1 and DNS of 192.168.10.1
I have my Centos server with IP Addr of 192.168.10.100
I am using this bridge for my KVM quest images so they can be on the same network. They will use the br0 interface when setting them up


Turn off NetworkManager

# chkconfig NetworkManager off
# service NetworkManager stop



Verify your resolv.conf file



# vi /etc/resolv.conf
search whittenberg.domain
nameserver 192.168.10.1



Verify your networks file


# vi /etc/networks
default 0.0.0.0
loopback 127.0.0.0
link-local 169.254.0.0


Verify your network file

# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=nas
GATEWAY=192.168.10.1
NETWORKING_IPV6=no 


setup your ifcfg-eth0 file. Notice I rem out the IP numbers and add BRIDGE=br0 at the bottom .

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=74:d4:35:ea:90:1f
ONBOOT=yes
TYPE=Ethernet
UUID=a949b417-3f11-4e60-821d-20467047c8dc
BOOTPROTO=none
NETWORKING_IPV6=no
IPV6_AUTOCONF=no
#IPADDR=192.168.10.100
#NETMASK=255.255.255.0
#BROADCAST=192.168.10.255
#NETWORK=192.168.10.0
#GATEWAY=192.168.10.1
BRIDGE=br0



Build a new ifcfg-br0 file. Notice this has the IP numbers in it, DEVICE=br0, and TYPE=Bridge (Use uppercase B or will not work)
 
# vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
NETWORKING_IPV6=no
IPV6_AUTOCONF=no
STP=yes
DELAY=0
IPADDR=192.168.10.100
NETMASK=255.255.255.0
BROADCAST=192.168.10.255
NETWORK=192.168.10.0
GATEWAY=192.168.10.1


Now restart the network

 
# service network restart

Verify your setup

 
# ifconfig
br0       Link encap:Ethernet  HWaddr 74:D4:35:EA:90:1F
          inet addr:192.168.10.100  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::76d4:35ff:feea:901f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:562054 errors:0 dropped:0 overruns:0 frame:0
          TX packets:422603 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3401299937 (3.1 GiB)  TX bytes:42579134 (40.6 MiB)

eth0      Link encap:Ethernet  HWaddr 74:D4:35:EA:90:1F
          inet6 addr: fe80::76d4:35ff:feea:901f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3402344 errors:0 dropped:94 overruns:0 frame:0
          TX packets:979938 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4841659591 (4.5 GiB)  TX bytes:93819012 (89.4 MiB)
          Interrupt:18

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:460893 errors:0 dropped:0 overruns:0 frame:0
          TX packets:460893 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:6962540755 (6.4 GiB)  TX bytes:6962540755 (6.4 GiB)

vnet0     Link encap:Ethernet  HWaddr FE:54:00:96:F2:2F
          inet6 addr: fe80::fc54:ff:fe96:f22f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:205365 errors:0 dropped:0 overruns:0 frame:0
          TX packets:244950 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:15677097 (14.9 MiB)  TX bytes:324471587 (309.4 MiB)


Verify the bridge


# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.74d435ea901f       yes             eth0


Make sure you ping outside IP and FQDN (8.8.8.8 is google DNS and www.google.com is.. oh never mind. you know.


# ping 8.8.8.8
# ping www.google.com
 
**Do if you have iptables enabled

Configure iptables to allow all traffic to be forwarded across the bridge:

# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# service iptables save
# service iptables restart

Prevent bridged traffic from being processed by iptables rules, this improves the bridge’s performance. In /etc/sysctl.conf append the following lines:

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

Reload the kernel parameters configured with sysctl:

# sysctl -p /etc/sysctl.conf

Restart the libvirt daemon:

# service libvirtd reload

**END Do if you have iptables enabled


Configure libvirtd service to start automatically and reboot.

# chkconfig libvirtd on

Now reboot server and confirm operation

# reboot

The host is now ready to start creating KVM guests.

No comments:

Post a Comment