I'll start with a minimal install of AlmaLinux 9 with the latest updates applied.
First, install the required packages to make the host a hypervisor:
[archy@hyv02 ~]$ sudo -y --refresh install qemu-kvm libvirt libguestfs-tools virt-install tuned swtpm cockpit cockpit-machines
[archy@hyv02 ~]$ sudo systemctl enable --now libvirtd.service tuned.service
[archy@hyv02 ~]$ 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 2 NICs which can then be used for vlans and bridges.
[archy@hyv02 ~]$ sudo nmcli connection add type bond con-name bond0 ifname bond0 mode 802.3ad
[archy@hyv02 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f0 ifname ens5f0 master bond0 802-3-ethernet.mtu 9000 # using 10G SFP+ here
[archy@hyv02 ~]$ sudo nmcli connection add type ethernet con-name bond0-ens2f1 ifname ens5f1 master bond0 802-3-ethernet.mtu 9000 # using 10G SFP+ here
[archy@hyv02 ~]$ sudo nmcli connection add type bridge con-name br0 ifname br0
[archy@hyv02 ~]$ sudo nmcli connection mod bond0 connection.master br0 connection.slave-type bridge
[archy@hyv02 ~]$ sudo nmcli connection mod br0 ipv4.address 172.31.10.249/24
[archy@hyv02 ~]$ sudo nmcli connection mod br0 ipv4.dns 9.9.9.9
[archy@hyv02 ~]$ sudo nmcli connection mod br0 +ipv4.dns 1.1.1.1
[archy@hyv02 ~]$ sudo nmcli connection mod br0 ipv4.gateway 172.31.10.254
[archy@hyv02 ~]$ sudo nmcli connection add type vlan con-name bond0.100 ifname bond0.100 dev bond0 id 100
[archy@hyv02 ~]$ sudo nmcli connection add type bridge con-name br0.100 ifname br0.100
[archy@hyv02 ~]$ sudo nmcli connection mod bond0.100 connection.master br0.100 connection.slave-type bridge
[archy@hyv02 ~]$ sudo nmcli connection mod br0.100 ipv4.method disabled
[archy@hyv02 ~]$ 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 the lvm backing my local storage pool. Start by creating the mountpoints and logical volumes:
[archy@hyv02 ~]$ sudo mkdir -p /var/kvm/{local-vm-data,nfs-vm-data,nfs-vm-iso}
[archy@hyv02 ~]$ sudo pvcreate /dev/sdb1
[archy@hyv02 ~]$ sudo vgcreate vg_data /dev/sdb1
[archy@hyv02 ~]$ sudo lvcreate -n lv_var_kvm_local_vm_data -L 2T vg_data
[archy@hyv02 ~]$ sudo mkfs.xfs /dev/vg_data/lv_var_kvm_local_vm_data
With the volume and mountpoints ready to go, persist them in fstab. I'll use this entry:
/dev/mapper/vg_data-lv_var_kvm_local_vm_data /var/kvm/local-vm-data xfs defaults 0 0
With the fstab finished, everything should be mountable:
[archy@hyv02 ~]$ sudo mount -a
If you are using SELinux, which I highly recommend, set the appropriate context for each path:
[archy@hyv02 ~]$ sudo semanage fcontext -a -t virt_image_t '/var/kvm/local-vm-data(/.*)?'
[archy@hyv02 ~]$ sudo restorecon -Rv /var/kvm
[archy@hyv02 ~]$ sudo chown -R qemu.qemu /var/kvm
[archy@hyv02 ~]$ sudo chmod -R 1755 /var/kvm
Now let's create the actual story pools using virsh:
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-define-as --name 'local-vm-data' --type 'dir' --target '/var/kvm/local-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-define-as --name 'nfs-vm-data' --type 'netfs' --source-host '172.31.10.248' --source-path '/volume1/nfs-vm-data' --target '/var/kvm/nfs-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-define-as --name 'nfs-vm-data' --type 'netfs' --source-host '172.31.10.248' --source-path '/volume1/nfs-vm-iso' --target '/var/kvm/nfs-vm-iso'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-autostart --pool 'local-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-autostart --pool 'nfs-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-autostart --pool 'nfs-vm-iso'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-start --pool 'local-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-start --pool 'nfs-vm-data'
[archy@hyv02 ~]$ sudo virsh -c 'qemu:///system' pool-start --pool 'nfs-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 -i ~/.ssh/home-archy-ed25519 root@hyv02.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@hyv02 ~]$ 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