差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:ubuntu_lxd [2025/11/13 18:34] – 3. 建立 LXD image 與 4. 建立與啟動 LXD 容器 jonathantech:ubuntu_lxd [2025/11/14 11:56] (目前版本) – [3. 如何啟動 Web UI] jonathan
行 234: 行 234:
 </cli> </cli>
  
 +===== 5. 進入容器測試  =====
 +  * <cli>
 +# 進入容器
 +lxc exec ct-118 -- bash
  
 +# 檢查系統
 +cat /etc/redhat-release
 +hostname
 +ip addr
 +systemctl status
 +
 +# 退出
 +exit
 +</cli>
 +
 +===== FAQ =====
 +==== 1. 發現無法自動啟動服務 (systemctl 權限問題) ====
 +  * Ubuntu 24.04 host 要先設定好 mount-cgroup-v1.sh / umount-cgroup-v1.sh / cgroup-v1-legacy.service 這些環境配置
 +  * 重建容器與設定正確權限<cli>
 +# 停止容器(如果卡住)
 +lxc stop ct-118 --force || true
 +
 +# 刪除容器 (保留映像)
 +lxc delete ct-118
 +
 +# 重新創建
 +lxc init ct-linsport ct-118
 +
 +# 創建設定檔案(完整的 systemd 支援配置)
 +cat > ct-118-raw.conf << 'EOF'
 +# 放寬安全限制
 +lxc.apparmor.profile=unconfined
 +lxc.cap.drop=
 +
 +# 自動 mount:proc rw、sys mixed、cgroup mixed(關鍵:自動處理 v1)
 +lxc.mount.auto=proc:rw sys:mixed cgroup:mixed
 +
 +# 手動 bind v1 控制器(僅 systemd 作為補充,optional)
 +lxc.mount.entry=/sys/fs/cgroup/systemd /sys/fs/cgroup/systemd none bind,create=dir,optional 0 0
 +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
 +</cli>
 +
 +==== 2. 發現容器無法對外連結 =====
 +  * 要在 Ubuntu 24.04 Host 建立可以對外網卡的 Bridge Exp. br0
 +  * 將原本容器的網卡刪除更換成這 br0 Exp.<cli>
 +# 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
 +</cli>
 +
 +==== 3. 如何啟動 Web UI =====
 +  * 設定 config <cli>
 +root@lin-web-210:~# lxd --version
 +5.21.4 LTS
 +root@lin-web-210:~# lxc config set core.https_address [::]
 +root@lin-web-210:~# lxc config set core.https_address 0.0.0.0:8443
 +root@lin-web-210:~# lxc config show
 +config:
 +  core.https_address: 0.0.0.0:8443
 +root@lin-web-210:~# lxc config trust list
 ++------+------+-------------+-------------+------------+-------------+
 +| TYPE | NAME | COMMON NAME | FINGERPRINT | ISSUE DATE | EXPIRY DATE |
 ++------+------+-------------+-------------+------------+-------------+
 +</cli>
 +  * 因為 LXD Web UI 是採用雙向 SSL 認證方式, 所以第一次進入網址要產生與下載憑證 Exp. https://192.168.1.210:8443
 +    - 瀏覽器會彈出選擇憑證, 如果沒有憑證或取消就會進入 Step 1. TLS login 設定畫面 \\ {{:tech:螢幕擷取畫面_2025-11-14_103428.png?1000|}}
 +    - 下載憑證( Exp. lxd-ui-192.168.1.210.pfx )後匯入讓瀏覽器可以使用
 +    - 開啟瀏覽器無痕模式, 彈出選擇憑證時, 選擇剛剛匯入的憑證 Exp. \\ {{:tech:螢幕擷取畫面_2025-11-14_104711.png|}}
 +    - 看到網頁 Step 2. 設定畫面
 +    - 回到 LXD Server 執行 <cli>lxc auth identity create tls/lxd-ui --group admins</cli>產生 identity token Exp. <cli>
 +root@lin-web-210:~# lxc auth identity create tls/lxd-ui --group admins
 +TLS identity "tls/lxd-ui" (4fd2xxxx-xxxx-xxxx-xxxx-xxxxxxxx88bc) pending identity token:
 +eyJjbGllbnxxxxxxxxxxxxxxxxxxxxIsImZpbmdlcnByaW5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxmI2NSIsImFkZHJlc3NlcyI6WyIxOTIuMTY4LjExLxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0aWZpY2F0ZSJ9
 +</cli>
 +    - 將產生的 identity token 貼上 Step 2. \\ {{:tech:螢幕擷取畫面_2025-11-14_104936.png?1000|}}
 +    - 點下 Connet 後就會進入 Web UI \\ {{:tech:螢幕擷取畫面_2025-11-14_105240.png?1000|}} \\ {{:tech:螢幕擷取畫面_2025-11-14_105422.png?1000|}}
 +    * 如果需要設定透過反向代理 Exp. NPM 原本雙向 SSL 認證就無法順利傳遞, 必須要增加設定 OIDC (Exp. Google oAuth 認證) 方式來達成, 可參考 - [[tech/ubuntu_lxd/oidc]]
 +
 +{{tag>pve ct lxd}}
  • tech/ubuntu_lxd.1763030059.txt.gz
  • 上一次變更: 2025/11/13 18:34
  • jonathan