在 Linux 伺服器內使用 Incus(LXC/LXD 的延續版本) 建立容器來安裝 HestiaCP,是一個輕量、安全、可快速備份與遷移的方式。本篇文章將示範:
- 安裝 Incus
- 進行
incus admin init初始化(附完整「中英文對照」解釋) - 建立容器、自動與固定 IP 配置
- 進入容器後安裝 SSH 與部署 HestiaCP 需要的基本環境
以下流程完全以 Ubuntu 系統測試。
Incus 套件安裝來源庫設定
sudo mkdir -p /etc/apt/keyrings/
sudo curl -fsSL https://pkgs.zabbly.com/key.asc -o /etc/apt/keyrings/zabbly.asc
. /etc/os-release
sudo vim /etc/apt/sources.list.d/zabbly-incus-stable.sources
zabbly-incus-stable.sources 檔案內容如下:
Enabled: yes
Types: deb
URIs: https://pkgs.zabbly.com/incus/stable
Suites: noble # 填入輸出內容 cat /etc/os-release ; echo ${VERSION_CODENAME}
Components: main
Architectures: amd64 # 填入輸出內容 dpkg --print-architecture
Signed-By: /etc/apt/keyrings/zabbly.asc
sudo apt update
安裝 Incus
sudo apt install incus
sudo apt install btrfs-progs
將使用者加入 incus 群組:
sudo usermod -aG incus $USER
sudo usermod -aG incus-admin $USER
exit
重新登入會話後即可使用 incus 指令。
安裝 Incus Web UI 介面
sudo apt install incus-ui-canonical
incus config set core.https_address ":8443"
初始化 Incus(含中英文對照內容)
執行初始化:
sudo incus admin init
# 設定 incusbr0 虛擬網卡需要 root 權限,務必加 sudo
以下為完整互動流程+說明(中英文對照)。
📝 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 匯出。 |
建立 Ubuntu 24.04 容器
自動取得容器 IP:
incus launch images:ubuntu/24.04 HestiaCP
若要刪除容器:
incus stop HestiaCP
incus delete HestiaCP
指定固定 IP 建立容器
以下示範固定 IP:10.10.10.50:
incus launch images:ubuntu/24.04 HestiaCP --device eth0,ipv4.address=10.10.10.50
進入容器
incus exec HestiaCP bash
安裝 OpenSSH Server
apt install openssh-server -y
安裝完成後,啟動服務:
systemctl enable ssh
systemctl start ssh
systemctl status ssh
建立使用者並賦予 sudo 權限
adduser $USER
adduser $USER sudo
su $USER
僅允許 SSH 金鑰登入(重要安全設定)
編輯 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
容器硬體資源使用設定
CPU 限制
限制容器最多使用幾個 CPU core
incus config set <container> limits.cpu 2
指定 CPU Pin(綁定實體核心)
incus config set <container> limits.cpu "1,2"
(代表容器只能用主機的 CPU core #1 與 #2)
記憶體限制(RAM)
設定固定記憶體上限
incus config set <container> limits.memory 2GB
允許 Swap(可選)
incus config set <container> limits.memory.swap true
磁碟空間限制(rootfs)
incus config set <container> limits.disk 20GB
如果你使用的是 ZFS/btrfs,限額會更精準。
網路頻寬限制(容器網卡)
限制下載(ingress)
incus config set <container> limits.network.ingress 20Mbit
限制上傳(egress)
incus config set <container> limits.network.egress 10Mbit
檢查容器完整設定
incus config show <container>
容器快照管理教學(使用 Incus)
在管理容器時,定期建立快照可以保護資料安全,特別是在升級或修改系統前。以下示範如何使用 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)
當你需要將容器搬到另一台主機,或者建立完整備份時,可以使用 Incus 的匯出(export)與匯入(import)功能。此方法可以保留容器的檔案系統、設定與快照,方便跨主機搬移或還原。
匯出容器 export
在舊主機上,使用 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 |
+----------+---------+--------------------+------+-----------+-----------+
設定或更改固定 IP
設定 IPv4
incus config device set <container-name> eth0 ipv4.address 10.10.10.50
例如:
incus config device set mycontainer eth0 ipv4.address 10.10.10.50
重新啟動 container:
incus restart mycontainer
注意事項
- 網路 IP:搬移後若 IP 不同,需要修改 HestiaCP 的網路設定,避免服務無法訪問。
- 快照:匯出檔案會包含快照,因此還原時可以完整回到快照狀態。
- 版本一致性:建議舊主機與新主機的 Incus 版本一致,避免匯入後容器無法啟動。
- 服務檢查:匯入後請確認 Apache、Nginx、MySQL、Exim 等服務運作正常。


