Installing and configuring kvm on RHEL 7 and OL 7

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Installing and configuring KVM on RHEL 7 and OL 7

Installing the required packages

yum -y install qemu-kvm qemu-img virt-manager libvirt libvirt-python python-virtinst libvirt-client virt-install virt-viewer
yum -y install kvm libvirt python-virtinst virt-top virt-manager virt-v2v virt-viewer vim pv

Disable firewall (to get around some issues)

systemctl stop firewalld
systemctl disable firewalld

Now, Start libvirt by using systemctl

systemctl restart libvirtd
systemctl status libvirtd

Copy any ISO / CD to /var/lib/libvirt/images (default location), so we can use that at a latter time.

One of the options I have used with a GUI, is, virt-manager, you can use that with remoteX enabled.

Once all configuration options are completed, make sure to select the option of configure after complete.
Note: To enable vnc go in to GUI and select vnc, listen to all interfaces if not, keyboard will not work.

Note: For some configurations you might need to bridge the network described latter.
FC options and howto enable multipath

cp /usr/share/doc/device-mapper-multipath-/multipath.conf /etc

To configure all the options, run

mpathconf --enable --with_multipathd y

Now, Verify if all worked

multipath -ll

To get the FC WWN, you can use the below.

cat /sys/class/scsi_host/host*/device/fc_host/host*/node_name

You can also run to below to get the WWN
Note: You might need to install systool, systool command is provided by the rpm package “sysfsutils”.

systool -c fc_host -v | grep "port_name"

Tips – Tools
You can use a verity of tools, but virt-manager and virsh are conman.
For example, to change hostname, run the below.

virsh dumpxml name_of_vm > name_of_vm.xml
virsh undefine name_of_vm
virsh define name_of_vm.xml
virsh start name_of_vm

To graceful shutdown a VM

virsh shutdown rhce1

To power off VM

virsh destroy rhce1
To start/restart VM
virsh start rhce1
virsh restart rhce1

To enable/disable autostart after server reboot.

virsh autostart rhce1
virsh autostart --disable rhce1

To list all VM's

virsh list --all
 Id Name                 State
  6 rhce1                running

In my experience I had to disable selinux for things to work properly, by doing so.

cat /etc/selinux/config

# or temporally type at commend prompt

To enable IP forwarding

net.ipv4.ip_forward = 1

To change without a reboot
sysctl -p /etc/sysctl.conf 

To create a bridge, which is needed in some cases.

brctl addbr br0
brctl addif br0 enp6s0

To use the bridge, use this in the interface file's
For example. In the physical interface ifcfg-eth0 add, remove ip and all and add to new file ifcfg-br0

# ifcfg-br0

To colne a VM

virt-clone --prompt

# For example on the command line
virt-clone --original vm1 --name vm2


Leave a Reply

Notify of