Tuesday, January 30, 2018

How to install KVM on CentOS 7 / RHEL 7 Headless Server

How do I install and configure KVM
(Kernel-based Virtual Machine) on a CentOS 7 or RHEL (Red Hat Enterprise
Linux) 7 server? How can I setup KMV on a CentOS 7 and use cloud
images/cloud-init for installing guest VM?
Kernel-based Virtual Machine (KVM) is virtualization software for
CentOS or RHEL 7. KVM turn your server into a hypervisor. This page
shows how to setup and manage a virtualized environment with KVM in
CentOS 7 or RHEL 7. It also described how to install and administer
Virtual Machines (VMs) on a physical server using the CLI. Make sure
that Virtualization Technology (VT) is enabled in your server’s BIOS. You can also run the following command to test if CPU Support Intel VT and AMD-V Virtualization tech:$ lscpu | grep VirtualizationVirtualization: VT-x

Step 2: Verify kvm installation

Step 3: Configure bridged networking

By default dhcpd based network bridge configured by libvirtd. You can verify that with the following commands:# brctl show # virsh net-list
All VMs (guest machine) only have network access to other VMs on the
same server. A private network 192.168.122.0/24 created for you. Verify
it:# virsh net-dumpxml default If you want your
VMs avilable to other servers on your LAN, setup a a network bridge on
the server that connected to the your LAN. Update your nic config file
such as ifcfg-enp3s0 or em1:# vi /etc/sysconfig/network-scripts/enp3s0 Add line:

BRIDGE=br0

Save and close the file in vi. Edit /etc/sysconfig/network-scripts/ifcfg-br0 and add:# vi /etc/sysconfig/network-scripts/ifcfg-br0 Append the following:

Step 5: Using cloud images

The above
installation method is okay for learning purpose or a single VM. Do you
need to deploy lots of VMs? Try cloud images. You can modify pre built
cloud images as per your needs. For example, add users, ssh keys, setup
time zone, and more using Cloud-init
which is the defacto multi-distribution package that handles early
initialization of a cloud instance. Let us see how to create CentOS 7 vm
with 1024MB ram, 20GB disk space, and 1 vCPU.