Benutzer-Werkzeuge

Webseiten-Werkzeuge


proxmox

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
proxmox [2025/06/14 12:20]
jango [CLI]
proxmox [2025/07/04 11:26] (aktuell)
jango [Links]
Zeile 55: Zeile 55:
  
 <code bash> <code bash>
 +# 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 start 999
 +pct console 999
 pct exec 999 -- ip a pct exec 999 -- ip a
 pct exec 999 -- ping 1.1.1.1 pct exec 999 -- ping 1.1.1.1
 pct exec 999 -- ping google.de 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
 +</code>
  
-# create container +====VM Managment==== 
-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 +<code bash> 
-# static ip +list VMs 
-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+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]
 </code> </code>
 +
 +====Container Managment====
 +
 +<code bash>
 +# 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>
 +</code>
 +
 +{{https://sweworld.net/cheatsheets/proxmox/|CheatSheet}}
 +=====API=====
 +
 +<code bash>
 +#!/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."
 +</code>
 +
 +=====Traffic Monitoring=====
 +
 +Um den Traffic einzelner VMs/Container verlässlich zu monitoren braucht man zusätzliche Tools wie z.B [[vnstat]].
  
 =====Links===== =====Links=====
Zeile 73: Zeile 284:
   * [[https://www.youtube.com/watch?v=ITYMeRE455g|How to create and settings a NAT network on a single IP address]]   * [[https://www.youtube.com/watch?v=ITYMeRE455g|How to create and settings a NAT network on a single IP address]]
   * [[https://homelabtopia.com/roxmox-fail2ban/|Proxmox Fail2Ban]]   * [[https://homelabtopia.com/roxmox-fail2ban/|Proxmox Fail2Ban]]
 +  * [[https://www.youtube.com/watch?v=VcTGKBHcqmk|OPNSense Router]]
proxmox.1749896436.txt.gz · Zuletzt geändert: 2025/06/14 12:20 von jango