Proxmox Full技能使用说明
2026-03-29
新闻来源:网淘吧
围观:10
电脑广告
手机广告
Proxmox VE - 全面管理
通过 REST API 完全控制 Proxmox VE 虚拟机管理程序。
设置
export PVE_URL="https://192.168.1.10:8006"
export PVE_TOKEN="user@pam!tokenid=secret-uuid"
创建 API 令牌:数据中心 → 权限 → API 令牌 → 添加(取消勾选权限分离)

认证请求头
AUTH="Authorization: PVEAPIToken=$PVE_TOKEN"
集群与节点
# Cluster status
curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/status" | jq
# List nodes
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes" | jq '.data[] | {node, status, cpu: (.cpu*100|round), mem_pct: (.mem/.maxmem*100|round)}'
# Node details
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/status" | jq
列出虚拟机与容器
# All VMs on node
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" | jq '.data[] | {vmid, name, status}'
# All LXC on node
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc" | jq '.data[] | {vmid, name, status}'
# Cluster-wide (all VMs + LXC)
curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/resources?type=vm" | jq '.data[] | {node, type, vmid, name, status}'
虚拟机/容器控制
# Start
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/start"
# Stop (immediate)
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/stop"
# Shutdown (graceful)
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/shutdown"
# Reboot
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/status/reboot"
# For LXC: replace /qemu/ with /lxc/
创建 LXC 容器
# Get next available VMID
NEWID=$(curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/nextid" | jq -r '.data')
# Create container
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc" \
-d "vmid=$NEWID" \
-d "hostname=my-container" \
-d "ostemplate=local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst" \
-d "storage=local-lvm" \
-d "rootfs=local-lvm:8" \
-d "memory=1024" \
-d "swap=512" \
-d "cores=2" \
-d "net0=name=eth0,bridge=vmbr0,ip=dhcp" \
-d "password=changeme123" \
-d "start=1"
LXC 参数:
| 参数 | 示例 | 描述 |
|---|---|---|
| vmid | 200 | 容器 ID |
| hostname | myct | 容器主机名 |
| ostemplate | local:vztmpl/debian-12-... | 模板路径 |
| 存储 | local-lvm | rootfs 的存储 |
| rootfs | local-lvm:8 | 根磁盘 (8GB) |
| memory | 1024 | 内存 (MB) |
| swap | 512 | 交换空间 (MB) |
| cores | 2 | CPU 核心数 |
| net0 | name=eth0,bridge=vmbr0,ip=dhcp | 网络配置 |
| password | secret | 根密码 |
| ssh-public-keys | ssh-rsa ... | SSH 密钥 (URL 编码) |
| unprivileged | 1 | 非特权容器 |
| start | 1 | 创建后启动 |
创建虚拟机
# Get next VMID
NEWID=$(curl -sk -H "$AUTH" "$PVE_URL/api2/json/cluster/nextid" | jq -r '.data')
# Create VM
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" \
-d "vmid=$NEWID" \
-d "name=my-vm" \
-d "memory=2048" \
-d "cores=2" \
-d "sockets=1" \
-d "cpu=host" \
-d "net0=virtio,bridge=vmbr0" \
-d "scsi0=local-lvm:32" \
-d "scsihw=virtio-scsi-pci" \
-d "ide2=local:iso/ubuntu-22.04.iso,media=cdrom" \
-d "boot=order=scsi0;ide2;net0" \
-d "ostype=l26"
虚拟机参数:
| 参数 | 示例 | 描述 |
|---|---|---|
| 虚拟机ID | 100 | 虚拟机ID |
| 名称 | 我的虚拟机 | 虚拟机名称 |
| 内存 | 2048 | 内存大小(MB) |
| 核心数 | 2 | 每个插槽的CPU核心数 |
| 插槽数 | 1 | CPU插槽数 |
| CPU类型 | host | CPU类型 |
| 网络0 | virtio,bridge=vmbr0 | 网络 |
| scsi0 | local-lvm:32 | 磁盘 (32GB) |
| ide2 | local:iso/file.iso,media=cdrom | ISO |
| 操作系统类型 | l26 (Linux), win11 | 操作系统类型 |
| 启动 | 顺序=scsi0;ide2 | 启动顺序 |
克隆虚拟机/容器
# Clone VM
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/clone" \
-d "newid=201" \
-d "name=cloned-vm" \
-d "full=1" \
-d "storage=local-lvm"
# Clone LXC
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}/clone" \
-d "newid=202" \
-d "hostname=cloned-ct" \
-d "full=1" \
-d "storage=local-lvm"
克隆参数:
| 参数 | 描述 |
|---|---|
| 新ID | 新虚拟机ID |
| 名称/主机名 | 新名称 |
| 完整 | 1=完整克隆,0=链接克隆 |
| 存储 | 目标存储 |
| 目标 | 目标节点 (用于迁移) |
转换为模板
# Convert VM to template
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/template"
# Convert LXC to template
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}/template"
快照
# List snapshots
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot" | jq '.data[] | {name, description}'
# Create snapshot
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot" \
-d "snapname=before-update" \
-d "description=Snapshot before system update"
# Rollback
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot/{snapname}/rollback"
# Delete snapshot
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}/snapshot/{snapname}"
备份
# Start backup
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/vzdump" \
-d "vmid={vmid}" \
-d "storage=local" \
-d "mode=snapshot" \
-d "compress=zstd"
# List backups
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/{storage}/content?content=backup" | jq
# Restore backup
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu" \
-d "vmid=300" \
-d "archive=local:backup/vzdump-qemu-100-2024_01_01-12_00_00.vma.zst" \
-d "storage=local-lvm"
存储与模板
# List storage
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage" | jq '.data[] | {storage, type, avail, used}'
# List available templates
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/local/content?content=vztmpl" | jq '.data[] | .volid'
# List ISOs
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/storage/local/content?content=iso" | jq '.data[] | .volid'
# Download template
curl -sk -X POST -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/aplinfo" \
-d "storage=local" \
-d "template=debian-12-standard_12.2-1_amd64.tar.zst"
任务
# Recent tasks
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks?limit=10" | jq '.data[] | {upid, type, status}'
# Task status
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks/{upid}/status" | jq
# Task log
curl -sk -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/tasks/{upid}/log" | jq -r '.data[].t'
删除虚拟机/容器
# Delete VM (must be stopped)
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}"
# Delete LXC
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/lxc/{vmid}"
# Force delete (purge)
curl -sk -X DELETE -H "$AUTH" "$PVE_URL/api2/json/nodes/{node}/qemu/{vmid}?purge=1&destroy-unreferenced-disks=1"
快速参考
| 操作 | 端点 | 方法 |
|---|---|---|
| 列出节点 | /nodes | GET |
| 列出虚拟机 | /nodes/{node}/qemu | GET |
| 列出LXC容器 | /nodes/{node}/lxc | GET |
| 创建虚拟机 | /nodes/{node}/qemu | POST |
| 创建LXC容器 | /nodes/{node}/lxc | POST |
| 克隆 | /nodes/{node}/qemu/{vmid}/clone | POST |
| 启动 | /nodes/{node}/qemu/{vmid}/status/start | POST |
| 停止 | /nodes/{node}/qemu/{vmid}/status/stop | POST |
| 快照 | /nodes/{node}/qemu/{vmid}/snapshot | POST |
| 删除 | /nodes/{node}/qemu/{vmid} | DELETE |
| 下一个ID | /cluster/nextid | GET |
备注
- 使用
-k用于自签名证书 - API令牌不需要CSRF
- 替换
{node}为节点名称(例如,pve替换 - {vmid}
为虚拟机/容器ID使用 - qemu
代表虚拟机,lxc代表容器所有创建/克隆操作都会返回任务UPID用于跟踪 - All create/clone operations return task UPID for tracking
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~