How to Deploy KVM Virtualization on CentOS 7 with a Web Management Interface
This guide explains virtualization concepts, introduces KVM, and provides step‑by‑step instructions for installing KVM on CentOS 7, configuring networking, setting up libvirt, deploying the webvirtmgr web UI, creating virtual machines, and troubleshooting common issues.
Virtualization Overview
Virtualization creates multiple logical computers on a single physical machine, allowing each logical computer to run a different operating system. It expands hardware capacity, enables multiple OSes to share resources, and isolates applications so they do not interfere with each other.
Why Enterprises Use Virtualization
Enterprises adopt virtualization to save costs and improve efficiency. The physical host provides hardware resources to guest virtual machines through a hypervisor, a software layer between hardware and the OS. Hypervisors come in two types: full virtualization (no kernel modification required) and para‑virtualization (requires kernel changes).
KVM Introduction
KVM (Kernel‑Based Virtual Machine) is implemented as a Linux kernel module kvm.ko that manages virtual CPU and memory. I/O virtualization (storage, network) is handled by QEMU, a pure‑software emulator that translates virtual device operations to real hardware. Together, KVM provides hardware‑assisted CPU/memory virtualization while QEMU handles device emulation.
KVM Deployment (CentOS 7)
Environment: CentOS 7, IP 192.168.222.140.
Enable CPU virtualization in the BIOS (or shut down the VM to enable it).
Configure a new VM with 8 GB RAM, 80 GB disk, and enable virtualization.
# lsblk // view partitions # parted /dev/sdb # mkfs.xfs /dev/sdb1 # mkdir /kvmdata # vim /etc/fstab UUID="09888ad8-a1ef-42fb-9c36-937e071bf897" /kvmdata xfs defaults 0 0 # mount -aDisable firewall and SELinux, then reboot:
# systemctl stop firewalld # setenforce 0 # systemctl disable --now firewalld # rebootConfigure YUM repository (Aliyun mirror) and install required packages:
# rm -rf /etc/yum.repos.d/* # curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo # yum -y install epel-release wget net-tools unzip zip gcc gcc-c++Verify CPU supports KVM: # egrep -o 'vmx|svm' /proc/cpuinfo Install KVM and related packages:
# yum -y install qemu-kvm qemu-kvm-tools qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils libguestfs-toolsConfigure network bridge (br0) to place VMs on the same LAN as the host:
# cp ifcfg-ens33 ifcfg-br0 # vim ifcfg-br0 TYPE=bridge
BOOTPROTO=none
NAME=br0
DEVICE=br0
ONBOOT=yes
IPADDR=192.168.222.140
PREFIX=24
GATEWAY=192.168.222.2
DNS1=192.168.222.2 # vim ifcfg-ens33 TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
BRIDGE=br0 # systemctl restart NetworkManagerEnable and start libvirtd: # systemctl enable --now libvirtd Verify KVM modules are loaded: # lsmod | grep kvm Create a symlink for the qemu-kvm command:
# ln -s /usr/libexec/qemu-kvm /usr/bin/qemu-kvmKVM Web Management Interface Installation
Install dependencies for webvirtmgr:
# yum -y install git python-pip libvirt-python libxml2-python python-websockify supervisor nginx python-develMap GitHub domain if needed:
# vim /etc/hosts 20.205.243.166 github.comClone the webvirtmgr source code and install Python requirements:
# cd /usr/local/src/ # git clone http://github.com/retspen/webvirtmgr.git # cd webvirtmgr # pip install -r requirements.txtInitialize the Django database and create a superuser: # python manage.py syncdb Copy web files to /var/www and set ownership:
# mkdir /var/www # cp -r /usr/local/src/webvirtmgr/ /var/www/ # chown -R nginx.nginx /var/www/webvirtmgr/Configure Gunicorn to bind to localhost:8000:
# vim /var/www/webvirtmgr/conf/gunicorn.conf.py bind = '127.0.0.1:8000'
backlog = 2048Configure Nginx as a reverse proxy:
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak # vim /etc/nginx/nginx.conf user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
worker_rlimit_nofile 655350; # vim /etc/nginx/conf.d/webvirtmgr.conf server {
listen 80 default_server;
server_name localhost;
location /static/ {
root /var/www/webvirtmgr/webvirtmgr;
expires max;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $remote_addr;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
client_max_body_size 1024M;
}
}Configure Supervisor to manage Gunicorn and the console service:
# vim /etc/supervisord.conf [program:webvirtmgr]
command=/usr/bin/python2 /var/www/webvirtmgr/manage.py run_gunicorn -c /var/www/webvirtmgr/conf/gunicorn.conf.py
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
logfile=/var/log/supervisor/webvirtmgr.log
log_stderr=true
user=nginx
[program:webvirtmgr-console]
command=/usr/bin/python2 /var/www/webvirtmgr/console/webvirtmgr-console
directory=/var/www/webvirtmgr
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/webvirtmgr-console.log
redirect_stderr=true
user=nginxEnable and start services:
# systemctl enable --now nginx # systemctl enable --now libvirtd # systemctl enable --now supervisord.serviceKVM Web Interface Management
Access the web UI via a browser (e.g., http://<host_ip>/), log in with the superuser created earlier, add a connection to the local KVM host, create storage pools, upload ISO images, define networks, and launch new virtual machines using the graphical wizard.
Typical steps in the UI include:
Creating a storage pool pointing to /kvmdata.
Uploading an OS ISO (e.g., CentOS‑7‑x86_64‑DVD‑1708.iso).
Defining a virtual network (bridge mode).
Launching a new VM with desired CPU, memory, and disk settings.
Troubleshooting
If cloning the repository fails due to network restrictions, configure proxy settings or update the /etc/hosts entry for GitHub. Verify that the Git configuration does not contain invalid proxy entries.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
