Inhaltsverzeichnis

Proxmox Virtual Environment (VE) ist ein Typ 1 Hypervisor auf dem Debian GNU/Linux-Betriebssystem basiert. Es bietet eine umfassende Lösung für die Bereitstellung und Verwaltung von virtuellen Maschinen (VMs) und Containern. Proxmox VE integriert KVM (Kernel-based Virtual Machine) für die Virtualisierung auf der Hardwareebene und LXC (Linux Containers) für leichte, isolierte Container.

Die Installation von Proxmox VE erfolgt über ein bootfähiges Installationsmedium, das auf einem physischen Server gestartet wird. Das Webinterface ist auf Port 8006 erreichbar.

Während der Installation WIFI Adapter deaktivieren oder Ethernet Adapter als Managment wählen weil man keine Zugangsdaten eingeben kann

Proxmox VE besteht aus mehreren Hauptkomponenten:

VM Managment

Die Verwaltung von virtuellen Maschinen erfolgt über den Proxmox VE-Manager. Folgende Aufgaben können durchgeführt werden:

HA

Proxmox VE bietet Mechanismen zur Verbesserung der Hochverfügbarkeit von virtuellen Maschinen.

Live-Migration

Verschieben von laufenden virtuellen Maschinen zwischen Hosts, ohne dass es zu Unterbrechungen für Benutzer kommt.

Clustering

Proxmox VE-Cluster, um virtuelle Maschinen automatisch zwischen verfügbaren Hosts zu migrieren und Ausfallsicherheit zu gewährleisten.

TUN Adapter

In der Container Konfiguration (auf Proxmox pve) unter

/etc/pve/lxc/<container-id>.conf

diese Zeilen einfügen.

lxc.cgroup2.devices.allow = c 10:200 rwm
lxc.mount.entry = /dev/net/tun dev/net/tun none bind,create=file

APPArmor

AppArmor deaktivieren. In der Container Konfiguration (auf Proxmox pve) unter

/etc/pve/lxc/<container-id>.conf

diese Zeilen einfügen.

lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop:

CLI

# create container
# dhcp
pct create 999 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst -storage local-lvm -hostname apitest -memory 512 -net0 name=eth0,bridge=vmbr0,ip=dhcp -password s3cr3t
# static ip
pct create 999 local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst -storage local-lvm -hostname apitest -memory 512 -net0 name=eth0,bridge=vmbr0,ip=192.168.0.50/24,gw=192.168.0.1 -password s3cr3t
 
# manage container
pct start 999
pct console 999
pct exec 999 -- ip a
pct exec 999 -- ping 1.1.1.1
pct exec 999 -- ping google.de
pct exec 999 -- bash -c "echo 'root:geheim123' | chpasswd"
vzdump 999 --storage local --mode stop # sichern
pct stop 999
pct destroy 999
 
# create vm
qm create 2000 --name ubuntu-vm --memory 512 --cores 1 --net0 virtio,bridge=vmbr0 --cdrom local:iso/ubuntu-22.04.5-live-server-amd64.iso --scsihw virtio-scsi-pci --scsi0 local-lvm:32 --boot order="scsi0;ide2" --ostype l26

VM Managment

# list VMs
qm list
 
# Create or restore a virtual machine.
qm create <vmid>
 
# Create or restore a virtual machine with core, memory, disks specified.
qm create <vmid> --name <vm-name> --cores <number-of-cores> --memory <memory-size-in-bytes> --scsi0 file=<vg-name>:<size-in-gb> --cdrom local:<iso-name> --net0 virtio,bridge=<bridge-name>
 
# start a VM
qm start <vmid>
 
# Suspend virtual machine.
qm suspend <vmid>
 
# shutdown a VM
qm shutdown <vmid>
 
# reboot a VM
qm reboot <vmid>
 
# reset a VM
qm reset <vmid>
 
# stop a VM
qm stop <vmid>
 
# Destroy the VM and all used/owned volumes.
# Removes any VM specific permissions and firewall rules
qm destroy <vmid>
 
# Enter Qemu Monitor interface.
qm monitor <vmid>
 
# Get the virtual machine configuration with both current and pending values.
qm pending <vmid>
 
# Send key event to virtual machine.
qm sendkey <vmid> <key> [OPTIONS]
 
# Show command line which is used to start the VM (debug info).
qm showcmd <vmid> [OPTIONS]
 
# Unlock the VM.
qm unlock <vmid>
 
# Clone a VM
qm clone <vmid> <newid>
 
# Clone a VM in full clone mode and also set the name.
qm clone <vmid> <newid> --full --name <name>
 
# Migrate a VM
qm migrate <vmid> <target-node>
 
# Show VM status
qm status <vmid>
 
# Clean up resources for a VM
qm cleanup <vmid> <clean-shutdown> <guest-requested>
 
# Create a Template.
qm template <vmid> [OPTIONS]
 
# Set virtual machine options (synchrounous API)
qm set <vmid> [OPTIONS]

Container Managment

# List containers
pct list
 
# Create or restore a container.
pct create <vmid> <ostemplate> [OPTIONS]
 
# Start the container.
pct start <vmid> [OPTIONS]
 
# Create a container clone/copy
pct clone <vmid> <newid> [OPTIONS]
 
# Suspend the container. This is experimental.
pct suspend <vmid>
 
# Resume the container.
pct resume <vmid>
 
# Stop the container.
# This will abruptly stop all processes running in the container.
pct stop <vmid> [OPTIONS]
 
# Shutdown the container.
# This will trigger a clean shutdown of the container, see lxc-stop(1) for details.
pct shutdown <vmid> [OPTIONS]
 
# Destroy the container (also delete all uses files).
pct destroy <vmid> [OPTIONS]
 
# Show CT status.
pct status <vmid> [OPTIONS]
 
# Migrate the container to another node. Creates a new migration task.
pct migrate <vmid> <target> [OPTIONS]
 
# Get container configuration.
pct config <vmid> [OPTIONS]
 
# Print the list of assigned CPU sets.
pct cpusets
 
# Get container configuration, including pending changes.
pct pending <vmid>
 
# Reboot the container by shutting it down, and starting it again. Applies pending changes.
pct reboot <vmid> [OPTIONS]
 
# Create or restore a container.
pct restore <vmid> <ostemplate> [OPTIONS]
 
# Set container options.
pct set <vmid> [OPTIONS]
 
# Create a Template.
pct template <vmid>
 
# Unlock the VM.
pct unlock <vmid>

CheatSheet

API

#!/bin/bash
 
# ===== KONFIGURATION =====
PVE_HOST="192.168.0.100"         # IP oder Hostname deines Proxmox-Servers
PVE_USER="root@pam"             # API-Benutzer (z. B. root@pam oder apiuser@pve)
PVE_PASS="Lunikoff0310#"        # Passwort oder API-Token
PVE_NODE="pve"                  # Name des Proxmox-Nodes (z. B. pve)
 
VMID=120
HOSTNAME="myct"
TEMPLATE="local:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst"
MEMORY=512                     # MB
CORES=1
DISK_SIZE=1                    # GB
BRIDGE="vmbr0"
IP_CONFIG="ip=dhcp"
ROOT_PASS="lunikoff"
 
# ===== LOGIN (Ticket holen) =====
echo "[*] Authentifiziere bei Proxmox API..."
AUTH_RESPONSE=$(curl -sk -d "username=$PVE_USER&password=$PVE_PASS" https://$PVE_HOST:8006/api2/json/access/ticket)
 
TICKET=$(echo "$AUTH_RESPONSE" | jq -r '.data.ticket')
CSRF=$(echo "$AUTH_RESPONSE" | jq -r '.data.CSRFPreventionToken')
 
if [[ -z "$TICKET" || -z "$CSRF" ]]; then
  echo "[!] Fehler: Authentifizierung fehlgeschlagen."
  exit 1
fi
 
# ===== LXC erstellen =====
echo "[*] Erstelle LXC-Container $VMID auf Node $PVE_NODE..."
 
CREATE_RESPONSE=$(curl -sk -X POST https://$PVE_HOST:8006/api2/json/nodes/$PVE_NODE/lxc \
  -H "CSRFPreventionToken: $CSRF" \
  -b "PVEAuthCookie=$TICKET" \
  -d vmid=$VMID \
  -d hostname=$HOSTNAME \
  -d ostemplate=$TEMPLATE \
  -d memory=$MEMORY \
  -d cores=$CORES \
  -d rootfs="local-lvm:${DISK_SIZE}" \
  -d unprivileged=1)
 
echo "$CREATE_RESPONSE" | jq
 
# ===== Container starten =====
echo "[*] Starte Container $VMID..."
answer=$(curl -sk -X POST https://$PVE_HOST:8006/api2/json/nodes/$PVE_NODE/lxc/$VMID/status/start \
  -H "CSRFPreventionToken: $CSRF" \
  -b "PVEAuthCookie=$TICKET" | jq)
 
sleep 15
 
ssh root@192.168.0.100 "pct exec $VMID -- bash -c 'useradd -m user -G sudo -s /bin/bash'"
ssh root@192.168.0.100 "pct exec $VMID -- bash -c 'echo user:$ROOT_PASS | chpasswd'"
ssh root@192.168.0.100 "pct set $VMID -net0 name=eth0,bridge=vmbr0,ip=192.168.0.120/24,gw=192.168.0.1"
 
echo "[✓] Container $VMID wurde erstellt und gestartet."

Traffic Monitoring

Um den Traffic einzelner VMs/Container verlässlich zu monitoren braucht man zusätzliche Tools wie z.B vnstat.