Breaking News
Popular News


Enter your email address below and subscribe to our newsletter

網路補給站

在 Linux 伺服器內使用 Incus(LXC/LXD 的延續版本) 建立容器來安裝 HestiaCP,是一個輕量、安全、可快速備份與遷移的方式。本篇文章將示範:
incus admin init 初始化(附完整「中英文對照」解釋)以下流程完全以 Ubuntu 系統測試。
sudo apt install incus
將使用者加入 incus 群組:
sudo usermod -aG incus $USER
sudo usermod -aG incus-admin $USER
exit
重新登入會話後即可使用 incus 指令。
執行初始化:
incus admin init
以下為完整互動流程+說明(中英文對照)。
| 問題(英文) | 問題(中文) | 建議 | 說明 |
|---|---|---|---|
| Would you like to use clustering? | 是否啟用叢集模式? | no | 單主機環境選否即可。 |
| Do you want to configure a new storage pool? | 是否建立新的儲存池? | yes | 建議建立新的存放容器的 storage pool。 |
| Name of the new storage pool | 新儲存池名稱 | incus-storage | 自訂名稱。 |
| Name of the storage backend | 儲存後端類型 | btrfs | btrfs 適合大量容器用途。可建立 snapshot |
| Create a new BTRFS pool? | 建立新的 BTRFS pool? | yes | 使用 loop device 建立。 |
| Use an existing empty block device? | 使用既有硬碟或分割區? | no | 無專用硬碟就選否。 |
| Size in GiB of the new loop device | loop device 大小 | 60GiB | 自行決定容量。90% host 機的容量 |
| Create a new local network bridge? | 建立網路橋接? | yes | 建議建立。 |
| Name of the bridge | 橋接名稱 | incusbr0 | 默認即可。 |
| IPv4 address (CIDR) | IPv4 子網設定 | 10.10.10.1/24 | 自訂網段十分常見。 |
| NAT IPv4? | 啟用 NAT? | yes | 讓容器可對外連網。 |
| IPv6 address | IPv6 設定 | none | 本例不使用 IPv6。 |
| Server available over network? | 啟用遠端 API? | no | 單機使用不需要。 |
| Auto-update cached images? | 自動更新映像檔? | yes | 建議啟動。 |
| Print YAML “init” preseed? | 顯示 YAML 初始化腳本? | no | 不需要 YAML 匯出。 |
incus launch images:ubuntu/24.04 HestiaCP
incus stop HestiaCP
incus delete HestiaCP
以下示範固定 IP:10.10.10.50:
incus launch images:ubuntu/24.04 HestiaCP --device eth0,ipv4.address=10.10.10.50
incus exec HestiaCP bash
apt install openssh-server -y
adduser $USER
adduser $USER sudo
su $USER
編輯 sshd_config:
sudo vim /etc/ssh/sshd_config
至少確認以下項目:
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
PermitRootLogin no
重新啟動 SSH:
sudo systemctl restart ssh
incus config set <container> limits.cpu 2
incus config set <container> limits.cpu "1,2"
(代表容器只能用主機的 CPU core #1 與 #2)
incus config set <container> limits.memory 2GB
incus config set <container> limits.memory.swap true
incus config set <container> limits.disk 20GB
如果你使用的是 ZFS/btrfs,限額會更精準。
incus config set <container> limits.network.ingress 20Mbit
incus config set <container> limits.network.egress 10Mbit
incus config show <container>
在管理容器時,定期建立快照可以保護資料安全,特別是在升級或修改系統前。以下示範如何使用 Incus 指令對容器建立、查詢、還原與刪除快照。
在對容器操作前,可以先使用 incus list 查詢所有容器與其狀態、IP 等資訊:
# 查看所有容器列表
incus list
範例輸出:
+----------+---------+--------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------+---------+--------------------+------+-----------+-----------+
| HestiaCP | RUNNING | 10.10.10.50 (eth0) | | CONTAINER | 1 |
+----------+---------+--------------------+------+-----------+-----------+
STATE表示容器是否運行,SNAPSHOTS則顯示已建立的快照數量。
使用 incus snapshot create 指令建立快照。建議在重要操作前先建立。
# 建立名稱為 before-update 的快照
incus snapshot create HestiaCP before-update
建立完成後,快照會保存在容器中,便於後續還原使用。
使用 incus snapshot list 查看 HestiaCP 容器的所有快照。
# 查詢 HestiaCP 容器快照列表
incus snapshot list HestiaCP
範例輸出:
+---------------+----------------------+------------+----------+
| NAME | TAKEN AT | EXPIRES AT | STATEFUL |
+---------------+----------------------+------------+----------+
| before-update | 2025/12/01 19:24 CST | | NO |
+---------------+----------------------+------------+----------+
若操作失敗或需要回到先前狀態,可使用 incus snapshot restore 還原快照。
# 將 HestiaCP 容器還原至 before-update 快照
incus snapshot restore HestiaCP before-update
還原快照時,容器將回到建立快照時的狀態。請確保重要資料已備份。
不再需要的快照可用 incus snapshot delete 刪除,釋放磁碟空間。
# 刪除名稱為 before-update 的快照
incus snapshot delete HestiaCP before-update
當你需要將容器搬到另一台主機,或者建立完整備份時,可以使用 Incus 的匯出(export)與匯入(import)功能。此方法可以保留容器的檔案系統、設定與快照,方便跨主機搬移或還原。
在舊主機上,使用 incus export 將容器打包成檔案:
# 將 HestiaCP 容器匯出成 tar.gz 檔案
incus export HestiaCP ~/HestiaCP-backup.tar.gz
HestiaCP:容器名稱。~/HestiaCP-backup.tar.gz:匯出後的檔案路徑。匯出完成後,你將得到一個包含容器完整狀態的壓縮檔,可作為備份或搬移檔。
使用 scp 或 rsync 將備份檔傳到新主機:
# 使用 scp 傳輸到新主機
scp ~/HestiaCP-backup.tar.gz user@newhost:~
請將
user@newhost替換成新主機的 SSH 帳號與 IP。
在新主機上使用 incus import 匯入容器:
# 匯入 HestiaCP 容器
incus import ~/HestiaCP-backup.tar.gz <new_container_name>
注意:舊版本的 Incus 不支援在 import 時直接改名稱,匯入後容器名稱將沿用原本匯出時的名稱。
如果你想改名稱,可使用:
# 將匯入的容器改名
incus rename HestiaCP HestiaCP1
匯入完成後,啟動容器:
incus start HestiaCP1
啟動後可使用
incus list查看容器狀態與 IP:
incus list
範例輸出:
+----------+---------+--------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------+---------+--------------------+------+-----------+-----------+
| HestiaCP1 | RUNNING | 10.10.10.50 (eth0) | | CONTAINER | 1 |
+----------+---------+--------------------+------+-----------+-----------+