How To Setup Libvirt
How to Setup Libvirt
The following guide will walk you through setting up a server to host other virtual machines utilizing The libvirt project. This guide can be used on a graphical host and virt-manager can be used to administrate the virtual machines. Alternatively this guide can be used on a headless server, and a remote connection via SSH in virt-manager can be used on a laptop or other machine to administrate this server remotely.
We will also install Cockpit and configure it to manage the virtual machines as virt-manager is deprecated and Cockpit is intended to become its replacement in a subsequent release. It is, therefore, recommended that you use the web console for managing virtualization in a GUI.
- 1. A Machine that supports Intel virtualization
- 2. Centos 7 or later
Step 1. Install the requisite software
yum install -y qemu-kvm qemu libvirt libvirt-bin libvirt-python bridge-utils virt-manager libguestfs-tools spice-vdagent virt-viewer spice-vdagent cockpit-machines cockpit virt-install
Step 2. Start the libvirt daemon and cockpit
systemctl start libvirtd
systemctl start cockpit.socket
Step 3. Enable the libvirt daemon and cockpit
systemctl enable libvirtd
systemctl enable cockpit.socket
Step 4. Create firewall rules for Cockpit
firewall-cmd --permanent --zone=public --add-service=cockpit firewall-cmd --reload
Step 5. Setup virt-manager to connect to the host
- Open virt-manager
- If virt-manager is running on the same machine, you will see "localhost"
- If virt-manager is running on a different machine - click "File" then "Add Connection"
- Check the box that says "Connect to remote host"
- Enter the IP or hostname of the libvirt server
- click "Connect"
- You will be prompted for authentication after which the "Not connected" message to the right of the connection will disappear
Step 6. Setup the network bridge so our servers will have direct access to the network
- Double click on either the localhost or remote host
- Open the "Network Interfaces" tab
- Click on the + at the bottom left to add a new network interface
- Interface type: Bridge
- Click "Forward"
- The Name of the bridge can be left at default
- Change the Start mode to "onboot"
- Check the "Activate Now" box
- Select the network interface card your server is using
- Click "Finish"