差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
| tech:ubuntu_lxd [2025/11/13 18:23] – [2. 將 proxmox 的 ct 匯出] jonathan | tech:ubuntu_lxd [2025/11/14 11:56] (目前版本) – [3. 如何啟動 Web UI] jonathan | ||
|---|---|---|---|
| 行 143: | 行 143: | ||
| </ | </ | ||
| + | ===== 3. 建立 LXD image ===== | ||
| + | * 使用 root 權限執行< | ||
| + | sudo -i | ||
| + | mkdir test | ||
| + | mv / | ||
| + | cd test | ||
| + | tar -xvf vzdump-lxc-118-2025_11_13-14_03_41.tar | ||
| + | ls -la | ||
| + | # (會看到一堆檔案) | ||
| + | |||
| + | # 查看系統版本 | ||
| + | cat etc/ | ||
| + | </ | ||
| + | * 將當前目錄的所有系統檔案打包成 rootfs< | ||
| + | # 排除原始備份檔 | ||
| + | tar --numeric-owner -czf rootfs.tar.gz \ | ||
| + | --exclude=' | ||
| + | --exclude=' | ||
| + | . | ||
| + | # 檢查打包結果 | ||
| + | ls -lh rootfs.tar.gz | ||
| + | </ | ||
| + | * LXD 需要 metadata 檔案來識別映像< | ||
| + | cat > metadata.yaml << ' | ||
| + | architecture: | ||
| + | creation_date: | ||
| + | properties: | ||
| + | description: | ||
| + | os: centos | ||
| + | release: " | ||
| + | EOF | ||
| + | |||
| + | # 打包 metadata | ||
| + | tar -czf metadata.tar.gz metadata.yaml | ||
| + | |||
| + | # 確認兩個檔案都存在 | ||
| + | ls -lh metadata.tar.gz rootfs.tar.gz | ||
| + | </ | ||
| + | |||
| + | ===== 4. 建立與啟動 LXD 容器 | ||
| + | * 導入為 LXD 映像 Exp. ct-linsport <cli> | ||
| + | lxc image import metadata.tar.gz rootfs.tar.gz --alias ct-linsport | ||
| + | </ | ||
| + | * 查看導入的映像< | ||
| + | lxc image list | ||
| + | root@lin-web-210: | ||
| + | +-------------+--------------+--------+------------------------------+--------------+-----------+------------+------------------------------+ | ||
| + | | ALIAS | FINGERPRINT | ||
| + | +-------------+--------------+--------+------------------------------+--------------+-----------+------------+------------------------------+ | ||
| + | | ct-linsport | 62085b012d6b | no | CentOS 7 from Proxmox CT-118 | x86_64 | ||
| + | +-------------+--------------+--------+------------------------------+--------------+-----------+------------+------------------------------+ | ||
| + | </ | ||
| + | * 從映像創建容器 Exp. ct-118 <cli> | ||
| + | lxc init ct-linsport ct-118 | ||
| + | </ | ||
| + | * 設定權限配置參數檔 ct-118-raw.conf 與相關權限設定< | ||
| + | cat > ct-118-raw.conf << ' | ||
| + | # 放寬安全限制 | ||
| + | lxc.apparmor.profile=unconfined | ||
| + | lxc.cap.drop= | ||
| + | |||
| + | # 自動 mount:proc rw、sys mixed、cgroup mixed(關鍵:自動處理 v1) | ||
| + | lxc.mount.auto=proc: | ||
| + | |||
| + | # 手動 bind v1 控制器(僅 systemd 作為補充,optional) | ||
| + | lxc.mount.entry=/ | ||
| + | EOF | ||
| + | |||
| + | # 讀取並設定 | ||
| + | lxc config set ct-118 raw.lxc "$(cat ct-118-raw.conf)" | ||
| + | |||
| + | # 設定特權模式 | ||
| + | lxc config set ct-118 security.privileged true | ||
| + | lxc config set ct-118 security.nesting true | ||
| + | </ | ||
| + | * 設定容器可以對外連結虛擬網卡< | ||
| + | # Override eth0 為獨立 nic type(移除 profile 影響) | ||
| + | lxc config device override ct-118 eth0 type=nic | ||
| + | # 移除 eth0(現在可移除,因為已 override) | ||
| + | lxc config device remove ct-118 eth0 | ||
| + | # 新增全新 eth0 nic:macvlan 模式,綁 ens18 | ||
| + | lxc config device add ct-118 eth0 nic nictype=bridged parent=br0 name=eth0 | ||
| + | </ | ||
| + | * 啟動容器< | ||
| + | # 啟動容器 | ||
| + | lxc start ct-118 | ||
| + | |||
| + | # 查看容器狀態 | ||
| + | lxc list | ||
| + | </ | ||
| + | |||
| + | ===== 5. 進入容器測試 | ||
| + | * <cli> | ||
| + | # 進入容器 | ||
| + | lxc exec ct-118 -- bash | ||
| + | |||
| + | # 檢查系統 | ||
| + | cat / | ||
| + | hostname | ||
| + | ip addr | ||
| + | systemctl status | ||
| + | |||
| + | # 退出 | ||
| + | exit | ||
| + | </ | ||
| + | |||
| + | ===== FAQ ===== | ||
| + | ==== 1. 發現無法自動啟動服務 (systemctl 權限問題) ==== | ||
| + | * Ubuntu 24.04 host 要先設定好 mount-cgroup-v1.sh / umount-cgroup-v1.sh / cgroup-v1-legacy.service 這些環境配置 | ||
| + | * 重建容器與設定正確權限< | ||
| + | # 停止容器(如果卡住) | ||
| + | lxc stop ct-118 --force || true | ||
| + | |||
| + | # 刪除容器 (保留映像) | ||
| + | lxc delete ct-118 | ||
| + | |||
| + | # 重新創建 | ||
| + | lxc init ct-linsport ct-118 | ||
| + | |||
| + | # 創建設定檔案(完整的 systemd 支援配置) | ||
| + | cat > ct-118-raw.conf << ' | ||
| + | # 放寬安全限制 | ||
| + | lxc.apparmor.profile=unconfined | ||
| + | lxc.cap.drop= | ||
| + | |||
| + | # 自動 mount:proc rw、sys mixed、cgroup mixed(關鍵:自動處理 v1) | ||
| + | lxc.mount.auto=proc: | ||
| + | |||
| + | # 手動 bind v1 控制器(僅 systemd 作為補充,optional) | ||
| + | lxc.mount.entry=/ | ||
| + | EOF | ||
| + | |||
| + | # 讀取並設定 | ||
| + | lxc config set ct-118 raw.lxc "$(cat ct-118-raw.conf)" | ||
| + | |||
| + | # 設定特權模式 | ||
| + | lxc config set ct-118 security.privileged true | ||
| + | lxc config set ct-118 security.nesting true | ||
| + | |||
| + | # 啟動容器 | ||
| + | lxc start ct-118 | ||
| + | |||
| + | # 檢查容器狀態 | ||
| + | lxc info ct-118 | ||
| + | |||
| + | # 查看啟動日誌 | ||
| + | lxc info ct-118 --show-log | tail -50 | ||
| + | |||
| + | # 等待幾秒讓系統啟動 | ||
| + | sleep 5 | ||
| + | |||
| + | # 檢查狀態 | ||
| + | lxc info ct-118 | grep Processes | ||
| + | |||
| + | # 查看容器狀態 | ||
| + | lxc list | ||
| + | </ | ||
| + | |||
| + | ==== 2. 發現容器無法對外連結 ===== | ||
| + | * 要在 Ubuntu 24.04 Host 建立可以對外網卡的 Bridge Exp. br0 | ||
| + | * 將原本容器的網卡刪除更換成這 br0 Exp.< | ||
| + | # Override eth0 為獨立 nic type(移除 profile 影響) | ||
| + | lxc config device override ct-118 eth0 type=nic | ||
| + | # 移除 eth0(現在可移除,因為已 override) | ||
| + | lxc config device remove ct-118 eth0 | ||
| + | # 新增全新 eth0 nic:macvlan 模式,綁 ens18 | ||
| + | lxc config device add ct-118 eth0 nic nictype=bridged parent=br0 name=eth0 | ||
| + | </ | ||
| + | |||
| + | ==== 3. 如何啟動 Web UI ===== | ||
| + | * 設定 config <cli> | ||
| + | root@lin-web-210: | ||
| + | 5.21.4 LTS | ||
| + | root@lin-web-210: | ||
| + | root@lin-web-210: | ||
| + | root@lin-web-210: | ||
| + | config: | ||
| + | core.https_address: | ||
| + | root@lin-web-210: | ||
| + | +------+------+-------------+-------------+------------+-------------+ | ||
| + | | TYPE | NAME | COMMON NAME | FINGERPRINT | ISSUE DATE | EXPIRY DATE | | ||
| + | +------+------+-------------+-------------+------------+-------------+ | ||
| + | </ | ||
| + | * 因為 LXD Web UI 是採用雙向 SSL 認證方式, | ||
| + | - 瀏覽器會彈出選擇憑證, | ||
| + | - 下載憑證( Exp. lxd-ui-192.168.1.210.pfx )後匯入讓瀏覽器可以使用 | ||
| + | - 開啟瀏覽器無痕模式, | ||
| + | - 看到網頁 Step 2. 設定畫面 | ||
| + | - 回到 LXD Server 執行 < | ||
| + | root@lin-web-210: | ||
| + | TLS identity " | ||
| + | eyJjbGllbnxxxxxxxxxxxxxxxxxxxxIsImZpbmdlcnByaW5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmI2NSIsImFkZHJlc3NlcyI6WyIxOTIuMTY4LjExLxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0aWZpY2F0ZSJ9 | ||
| + | </ | ||
| + | - 將產生的 identity token 貼上 Step 2. \\ {{: | ||
| + | - 點下 Connet 後就會進入 Web UI \\ {{: | ||
| + | * 如果需要設定透過反向代理 Exp. NPM 原本雙向 SSL 認證就無法順利傳遞, | ||
| + | |||
| + | {{tag> | ||