Installing KVM on Fedora/RedHat/CentOS | Complete Setup Guide
Master KVM virtualization with this comprehensive step-by-step installation and configuration guide for enterprise environments.
KVM (Kernel Virtual Machine) is a powerful virtualization technology built into the Linux kernel, based on QEMU (Quick Emulator) and designed for enterprise server virtualization. As the default hypervisor in OpenStack projects, KVM delivers exceptional performance by leveraging hardware extensions for optimal efficiency.
This comprehensive guide will walk you through setting up a production-ready two-node KVM farm using OpenFiler for storage and Fedora Core 14 as your KVM hosts. By the end of this tutorial, you’ll master KVM installation, virtual machine creation, and live migration between hosts—all using the essential KVM toolset.
Install Essential Components
Begin by installing the core virtualization components. First, identify and install the appropriate NFS client for your system architecture:
yum list | grep nfs
Install the NFS client for your architecture (example for i686):
yum install nfs-utils.i686
Next, install the essential virtualization components with a single command:
yum install virt-manager virt-viewer libvirt qemu-kvm
- virt-manager: Virtual machine management utility
- virt-viewer: Console access for virtual machines
- libvirt: Core hypervisor infrastructure
- qemu-kvm: KVM enablement package
Best Practice: Restart your system after installation to ensure all components load properly and hardware virtualization features are activated.
Configure DNS and Network Settings
Proper DNS configuration is critical for KVM cluster functionality. If you lack a dedicated DNS server, configure host file entries manually:
gedit /etc/hosts
Add entries for each KVM host using this format:
192.168.1.10 kvm-host1.local
192.168.1.11 kvm-host2.local
Setup NFS Shared Storage
Create a dedicated mount point for shared VM storage and configure the NFS share:
mkdir /var/lib/libvirt/images/kvmshared
mount -t nfs 10.0.0.28:/mnt/volgroup1/volume1/Share1/ /var/lib/libvirt/images/kvmshared
Make the mount persistent by adding it to /etc/fstab:
echo "10.0.0.28:/mnt/volgroup1/volume1/share1/ /var/lib/libvirt/images/kvmshared nfs defaults 0 0" >> /etc/fstab
Set proper permissions and configure SELinux for NFS usage:
chmod 755 -R /var/lib/libvirt/images
setsebool -P virt_use_nfs on
Configure Firewall for Live Migration
Open essential ports for remote management and live migration functionality:
- Port 22: SSH access for remote management
- Ports 49152-49261: Live migration traffic
Configure firewall rules using the system firewall utility:
/usr/bin/system-config-firewall
Add TCP port range 49152-49261 for migration traffic and apply the configuration.
Configure the Hypervisor
Start the libvirt daemon and initialize the virtual machine manager:
service libvirtd start
virt-manager
Update the default storage pool to use your NFS shared storage:
gedit /etc/libvirt/storage/default.xml
Change the path from /var/lib/libvirt/images
to /var/lib/libvirt/images/kvmshared
and restart the hypervisor:
service libvirtd restart
Creating Virtual Machines
Follow these steps to create your first virtual machine using virt-manager:
- Launch virt-manager and click the “New” button
- Enter a descriptive name for your virtual machine
- Select “Local Media (ISO Image or CDROM)” as the installation source
- Browse and select your ISO file from the shared storage location
- Allocate appropriate memory and CPU resources
- Configure virtual disk size (consider unchecking “Allocate Entire Disk Now” for space efficiency)
- Review settings and click “Finish” to create the VM
Pro Tip: To release mouse and keyboard control from a VM, press Ctrl+Alt on the left side of your keyboard.
Live Migration Setup
Enable seamless VM migration between hosts by registering remote systems in virt-manager:
Register Remote Hosts
- Open virt-manager and go to File → Add Connection
- Check “Connect to remote Host”
- Select “QEMU/KVM” from the hypervisor dropdown
- Choose “SSH” as the connection method
- Set username to “root”
- Enter the remote hostname
- Accept SSH certificates and provide credentials
Perform Migration
To migrate a running VM:
- Right-click the virtual machine
- Select “Migrate”
- Choose the destination host from the dropdown
- Click “Migrate” to begin the process
Important: After migration, delete the VM entry from the original host (but DO NOT delete storage files) to prevent conflicts with future migrations.
Troubleshooting and Useful Commands
Keep these essential commands and troubleshooting tips handy:
Fix Migration Issues
iptables -I INPUT -j ACCEPT
List Running VMs
virsh -c qemu:///system list
Direct VM Boot
qemu-kvm -m 1024 -cdrom /path/to/image.iso -boot d
Configuration files are stored in /etc/libvirt
and logs can be found in /var/log/libvirt
.
Elevate Your IT Efficiency with Expert Solutions
Transform Your Technology, Propel Your Business
Unlock advanced technology solutions tailored to your business needs. At InventiveHQ, we combine industry expertise with innovative practices to enhance your cybersecurity, streamline your IT operations, and leverage cloud technologies for optimal efficiency and growth.