I'll start with a minimal install of AlmaLinux 8 with the latest updates applied.
First, install the required packages to make the host a hypervisor:
[archy@hyv01 ~]$ sudo dnf -d 2 -y --refresh module enable virt
[archy@hyv01 ~]$ sudo dnf -d 2 -y --refresh install qemu-kvm libvirt libguestfs-tools virt-install tuned swtpm cockpit cockpit-machines
[archy@hyv01 ~]$ sudo systemctl enable --now libvirtd.service tuned.service
[archy@hyv01 ~]$ sudo tuned-adm profile virtual-host
NOTE: Tuned is optional but might give you just a little bit more optimization for your workload.
Next up, network configuration. I'll create a bond with 4 NICs which can then be used for vlans and bridges.
[archy@hyv01 ~]$ sudo nmcli connection add type bond con-name bond0 ifname bond0 mode 802.3ad
[archy@hyv01 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f0 ifname ens2f0 master bond0
[archy@hyv01 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f1 ifname ens2f1 master bond0
[archy@hyv01 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f2 ifname ens2f2 master bond0
[archy@hyv01 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f3 ifname ens2f3 master bond0
[archy@hyv01 ~]$ sudo nmcli connection add type bridge con-name br0 ifname br0
[archy@hyv01 ~]$ sudo nmcli connection mod bond0 connection.master br0 connection.slave-type bridge
[archy@hyv01 ~]$ sudo nmcli connection mod br0 ipv4.address 172.31.0.250/24
[archy@hyv01 ~]$ sudo nmcli connection mod br0 ipv4.dns 9.9.9.9
[archy@hyv01 ~]$ sudo nmcli connection mod br0 +ipv4.dns 1.1.1.1
[archy@hyv01 ~]$ sudo nmcli connection mod br0 ipv4.gateway 172.31.0.254
[archy@hyv01 ~]$ sudo nmcli connection add type vlan con-name bond0.100 ifname bond0.100 dev bond0 id 100
[archy@hyv01 ~]$ sudo nmcli connection add type bridge con-name br0.100 ifname br0.100
[archy@hyv01 ~]$ sudo nmcli connection mod bond0.100 connection.master br0.100 connection.slave-type bridge
[archy@hyv01 ~]$ sudo nmcli connection mod br0.100 ipv4.method disabled
[archy@hyv01 ~]$ sudo nmcli connection mod br0.100 ipv6.method ignore
I'm not going to give the Interface an IP Address since it's not supposed to be reachable from the network.
Now, let's create storage pools. Start by creating the mountpoints and logical volumes
[archy@hyv01 ~]$ sudo mkdir -p /var/kvm/vm-images
[archy@hyv01 ~]$ sudo mkdir /var/kvm/vm-iso
[archy@hyv01 ~]$ sudo pvcreate /dev/sdb1
[archy@hyv01 ~]$ sudo vgcreate vg_data /dev/sdb1
[archy@hyv01 ~]$ sudo lvcreate -n lv_vm_images -L 2T vg_data
[archy@hyv01 ~]$ sudo lvcreate -n lv_vm_iso -L 100G vg_data
[archy@hyv01 ~]$ sudo mkfs.xfs /dev/vg_data/lv_vm_images
[archy@hyv01 ~]$ sudo mkfs.xfs /dev/vg_data/lv_vm_iso
With the volumes and mountpoints ready to go, persist them in fstab. I'll use these entries:
/dev/mapper/vg_data-lv_vm_images /var/kvm/vm-images xfs defaults 0 0
/dev/mapper/vgt_data-lv_vm_iso /var/kvm/vm-iso xfs defaults 0 0
With the fstab finished, everything should be mountable:
[archy@hyv01 ~]$ sudo mount -a
If you are using SELinux, which I highly recommend, set the appropriate context for each path:
[archy@hyv01 ~]$ sudo semanage fcontext -a -t virt_content_t '/var/kvm/vm-iso(/.*)?'
[archy@hyv01 ~]$ sudo semanage fcontext -a -t virt_image_t '/var/kvm/vm-images(/.*)?'
[archy@hyv01 ~]$ sudo restorecon -Rv /var/kvm
[archy@hyv01 ~]$ sudo chown -R qemu.qemu /var/kvm
[archy@hyv01 ~]$ sudo chmod -R 1755 /var/kvm
Now let's create the actual story pools using virsh:
[archy@hyv01 ~]$ sudo virsh pool-define-as --name 'vm-images' --type dir --target '/var/kvm/vm-images'
[archy@hyv01 ~]$ sudo virsh pool-define-as --name 'vm-iso' --type dir --target '/var/kvm/vm-iso'
[archy@hyv01 ~]$ sudo virsh pool-autostart --pool 'vm-images'
[archy@hyv01 ~]$ sudo virsh pool-autostart --pool 'vm-iso'
[archy@hyv01 ~]$ sudo virsh pool-start --pool 'vm-images'
[archy@hyv01 ~]$ sudo virsh pool-start --pool 'vm-iso'
Now for the finishing touch, copy your ssh-key to the server in order to ensure password-less authentication for ssh:
[archy@stealth-falcon ~]$ ssh-copy-id root@hyv01.archyslife.lan
You should now be able to connect using virt-manager and virsh from your local workstation to the server without being asked for a password.
As a GUI, I'd recommend either virt-manager or using cockpit which can be enabled by this command:
[archy@hyv01 ~]$ sudo systemctl enable --now cockpit.socket
This way you have a decent WebUI running on your server on port 9090 which can be used to manage VMs.
Feel free to comment and / or suggest a topic.
Comments
Post a Comment