仿照 timmy/42_38 結構建立 7 份文件,涵蓋 3 節點 PVE 8.4.16 叢集 (pve-000/.73、pve-001/.249、pve-002/.247)的架構、API、儲存、 備份與服務分類。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
177 lines
4.7 KiB
Markdown
177 lines
4.7 KiB
Markdown
# 快速上手指南
|
||
|
||
5 分鐘內開始操作 PVECluster(192.168.88.0/24)。
|
||
|
||
## 前置條件
|
||
|
||
- 可連線至 `192.168.88.0/24` 網段
|
||
- 已安裝 `curl` 和 `python3`(用於解析 JSON)
|
||
- root 密碼:`25915525`(SSH 用)
|
||
|
||
## 1. 確認連線
|
||
|
||
```bash
|
||
# SSH(三台任一皆可)
|
||
ssh root@192.168.88.247 "pveversion"
|
||
# 預期輸出:pve-manager/8.4.16/...
|
||
|
||
# API
|
||
curl -sk https://192.168.88.247:8006/api2/json/version \
|
||
-H "Authorization: PVEAPIToken=root@pam!claude=17e96169-a32f-4e2d-951e-859c77770306"
|
||
# 預期輸出:{"data":{"version":"8.4.16",...}}
|
||
```
|
||
|
||
## 2. 設定環境變數(方便後續操作)
|
||
|
||
```bash
|
||
export PVE_HOST="https://192.168.88.247:8006/api2/json"
|
||
export PVE_AUTH="Authorization: PVEAPIToken=root@pam!claude=17e96169-a32f-4e2d-951e-859c77770306"
|
||
|
||
# 定義快捷函式
|
||
pve-get() { curl -sk "$PVE_HOST$1" -H "$PVE_AUTH"; }
|
||
pve-post() { curl -sk -X POST "$PVE_HOST$1" -H "$PVE_AUTH" "${@:2}"; }
|
||
```
|
||
|
||
## 3. 查看叢集狀態
|
||
|
||
```bash
|
||
# 節點概覽
|
||
pve-get /nodes | python3 -m json.tool
|
||
|
||
# 所有 VM/容器
|
||
pve-get /cluster/resources?type=vm | python3 -c "
|
||
import sys, json
|
||
data = json.load(sys.stdin)['data']
|
||
data.sort(key=lambda x: x['vmid'])
|
||
print(f\"{'VMID':<6} {'Type':<5} {'Status':<9} {'Node':<10} {'Name':<14} {'CPU':>4} {'Mem':>8}\")
|
||
print('-' * 70)
|
||
for d in data:
|
||
mem = f\"{d['mem'] // 1048576}M\" if d['mem'] else '-'
|
||
print(f\"{d['vmid']:<6} {d['type']:<5} {d['status']:<9} {d['node']:<10} {d['name']:<14} {d.get('maxcpu','?'):>4} {mem:>8}\")
|
||
"
|
||
```
|
||
|
||
## 4. 常用操作範例
|
||
|
||
### 啟動 / 停止容器
|
||
|
||
```bash
|
||
# 啟動 CT104(NPM + Headscale)
|
||
pve-post /nodes/pve-000/lxc/104/status/start
|
||
|
||
# 優雅關閉 CT104
|
||
pve-post /nodes/pve-000/lxc/104/status/shutdown
|
||
|
||
# 強制停止
|
||
pve-post /nodes/pve-000/lxc/104/status/stop
|
||
```
|
||
|
||
### 啟動 / 停止 VM
|
||
|
||
```bash
|
||
# 啟動 VM 120(HackMD)
|
||
pve-post /nodes/pve-001/qemu/120/status/start
|
||
|
||
# 關閉 VM
|
||
pve-post /nodes/pve-001/qemu/120/status/shutdown
|
||
```
|
||
|
||
### 查看單一 VM/容器狀態
|
||
|
||
```bash
|
||
# CT 狀態
|
||
pve-get /nodes/pve-000/lxc/104/status/current | python3 -m json.tool
|
||
|
||
# VM 狀態(OpenWRT)
|
||
pve-get /nodes/pve-000/qemu/115/status/current | python3 -m json.tool
|
||
```
|
||
|
||
### 查看 / 修改設定
|
||
|
||
```bash
|
||
# 查看 CT104 設定
|
||
pve-get /nodes/pve-000/lxc/104/config | python3 -m json.tool
|
||
|
||
# 透過 SSH 修改記憶體(改為 2GB)
|
||
ssh root@192.168.88.247 "pvesh set /nodes/pve-000/lxc/104/config --memory 2048"
|
||
```
|
||
|
||
### 儲存使用狀況
|
||
|
||
```bash
|
||
pve-get /cluster/resources?type=storage | python3 -c "
|
||
import sys, json
|
||
data = json.load(sys.stdin)['data']
|
||
seen = set()
|
||
print(f\"{'Storage':<18} {'Type':<8} {'Shared':<7} {'Used':>10} {'Total':>10} {'Usage':>6}\")
|
||
print('-' * 65)
|
||
for d in sorted(data, key=lambda x: x['storage']):
|
||
key = d['storage']
|
||
if key in seen: continue
|
||
seen.add(key)
|
||
total = d.get('maxdisk', 0)
|
||
used = d.get('disk', 0)
|
||
pct = f\"{used/total*100:.0f}%\" if total else '-'
|
||
print(f\"{key:<18} {d['plugintype']:<8} {'yes' if d.get('shared') else 'no':<7} {used//1073741824:>8} GB {total//1073741824:>8} GB {pct:>6}\")
|
||
"
|
||
```
|
||
|
||
### 立即備份
|
||
|
||
```bash
|
||
# 備份 CT113(Dify/n8n/NocoDB)到 PBS
|
||
pve-post /nodes/pve-000/vzdump \
|
||
-d "vmid=113" \
|
||
-d "storage=backup1" \
|
||
-d "mode=snapshot" \
|
||
-d "notes-template={{guestname}}"
|
||
```
|
||
|
||
### 建立快照
|
||
|
||
```bash
|
||
# CT 快照
|
||
pve-post /nodes/pve-000/lxc/104/snapshot \
|
||
-d "snapname=before-upgrade" \
|
||
-d "description=升級前快照"
|
||
|
||
# 列出快照
|
||
pve-get /nodes/pve-000/lxc/104/snapshot | python3 -m json.tool
|
||
```
|
||
|
||
## 5. 節點與 VMID 對照速查
|
||
|
||
操作 API 需要知道目標在哪個節點上:
|
||
|
||
| VMID 範圍 | 節點 | 類型 | 主要用途 |
|
||
|---|---|---|---|
|
||
| 100, 101, 110, 115, 121, 124 | pve-000 | qemu | Veljko/PBS/OpenWRT/Ubuntu |
|
||
| 102, 111, 114, 116, 119, 120, 123 | pve-001 | qemu | Windows VMs / HackMD |
|
||
| 104, 106-109, 112, 113, 117, 122, 125 | pve-000 | lxc | NPM/業務應用 |
|
||
| 103, 105 | pve-001 | lxc | AMC-stage / OpenArchiver |
|
||
|
||
> 不確定在哪個節點?用 `/cluster/resources?type=vm` 查詢即可:
|
||
> ```bash
|
||
> pve-get /cluster/resources?type=vm | python3 -c "
|
||
> import sys,json
|
||
> for v in json.load(sys.stdin)['data']:
|
||
> print(f\"{v['vmid']} {v['type']} -> {v['node']}\")
|
||
> "
|
||
> ```
|
||
|
||
## 6. 重要服務速查
|
||
|
||
| 服務 | 位置 | 連線方式 |
|
||
|---|---|---|
|
||
| PVE Web UI | https://192.168.88.247:8006 | root / `25915525` |
|
||
| PBS Web UI | https://192.168.88.169:8007 | root |
|
||
| OpenWRT | http://192.168.77.1 | (需在 192.168.77.0/24 子網內) |
|
||
| Synology NAS | http://192.168.88.60 | DSM / iSCSI portal |
|
||
| HackMD | VM 120(pve-001) | 需查內部 IP |
|
||
| Nginx Proxy Manager | CT 104 (192.168.77.10) | 需經 OpenWRT |
|
||
|
||
## 7. Web UI
|
||
|
||
瀏覽器開啟 `https://192.168.88.247:8006`,使用 `root` / PAM 認證登入(密碼 `25915525`)。
|
||
三個節點任一 IP 皆可進入同一管理介面。
|