Thursday, 14 July 2016

Install KVM in CentOS-7 Minimal


Installing KVM in CentOS-7 Minimal.


1. Verify that Virtualization Technology (VT) is enabled in your server’s BIOS. Else enable the same in BIOS.

# grep -E 'svm|vmx' /proc/cpuinfo -> you can see some vmx flags

2. Install Required packages for KVM.

# yum install kvm virt-manager libvirt virt-install qemu-kvm xauth dejavu-lgc-sans-fonts libvirt-python libguestfs-tools

3. Enable and start the libvirtd service.

# systemctl enable libvirtd && systemctl start libvirtd

4. Verify the following kernel modules are loaded, and if not load manually.

# cat /proc/modules | grep kvm                -> you will get two lines stating kvm and kvm_Intel  

5. Configure a bridge port for VMs.

5.1 Add following entry in network controller configuration file. (/etc/sysconfig/network-scripts/ifcfg-eno1)

BRIDGE=br0

5.2 Here I am using static IP address for server, and I am going to use the same for bridge interface too.

For this purpose I disabled following lines in network controller configuration file. (/etc/sysconfig/network-scripts/ifcfg-eno1)

#IPADDR="192.168.0.46"
#PREFIX="16"
#GATEWAY="192.168.0.1"
#DNS1="192.168.0.31"
#DNS2="8.8.8.8"

5.3 Create /etc/sysconfig/network-scripts/ifcfg-br0 and add following lines.

DEVICE="br0"
TYPE="Bridge"
ONBOOT="yes"
BOOTPROTO="static"
DELAY="0"
IPADDR="192.168.0.46"
PREFIX="16"
GATEWAY="192.168.0.1"
DNS1="192.168.0.31"
DNS2="8.8.8.8"

5.4 Add following entry in /etc/sysctl.conf to enable network forwarding.

net.ipv4.ip_forward = 1

5.5 Read the file.

# sysctl -p /etc/sysctl.conf

5.6 Restart the ‘NetworkManager’ service.

# systemctl restart NetworkManager

6. Finally connect to KVM and issue list command, it will return an empty table.

# virsh -c qemu:///system list

7. Enable following line in  /etc/libvirt/qemu.conf  to change the default listen address of vnc connection for VM.

vnc_listen = "0.0.0.0"

8. Restart libvirtd service, in order to apply the above change.

9. Now you can connect to Virtual machine manager and start creating VM change storage location and copy iso images of Operating system. else use virt-install.

10. Inorder to connect VM through VNC check the port in console.

#  virsh vncdisplay <domain name>   if the line returns 0 vnc port number will be 5900.

11. Check the same through netstat (if netstat not installed you can install it with net-tools package).

#  netstat -tln|grep :59

12. In tight vnc put 192.168.0.46:5900 as remote host name.




https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-remote-access-for-the-gnome-desktop-on-centos-7