如果你剛好用 macOS,也剛好有裝 OrbStack,
OrbStack CLI(orb 指令)的指令可以幫你輕鬆建立與管理 Linux 虛擬機。
這邊就整理一下這些細節,用 orb 指令來管理 OrbStack 內建的虛擬機。
orb 指令說明
這邊列出 orb 指令的說明,後面會跟大家說要怎麼使用
Usage:
orb create [flags] DISTRO[:VERSION] [MACHINE_NAME]
Aliases:
create, add, new
Examples:
orb create -a arm64 ubuntu:24.04
orb create --memory 4G --cpus 2 --disk 64G ubuntu dev
orb create -a amd64 fedora foo
Flags:
-a, --arch string Override the default architecture
--cpus string CPU core limit for the machine
--disk string Disk usage limit for the machine (GiB, or units like 64G)
--forward-ssh-agent Enable SSH agent forwarding for an isolated machine
-h, --help help for create
--isolate-network Block an isolated machine from other machines and host IPs
--isolated Create an isolated machine (disables file sharing and integration)
--memory string Memory limit for the machine (MiB, or units like 4G)
--mount stringArray Add a selective host mount for an isolated machine as SOURCE[:DEST] (repeatable)
-p, --set-password Set a password for the default user
-u, --user string Username for the default user
-c, --user-data string Path to Cloud-init user data file (for automatic setup)
核心指令語法
使用 orb create 即可快速建立新的 Linux 虛擬機器:
orb create [旗標] 發行版[:版本] [機器名稱]
別名(Aliases):create、add、new 皆可通用。
常用旗標(Flags)說明
旗標 / 參數
完整名稱
說明
-a
--arch
變更預設架構(例如:arm64 或 amd64)
--cpus
設定 CPU 核心數上限
--memory
設定記憶體上限(例如:4G、2048M)
--disk
設定磁碟容量上限(例如:64G)
-u
--user
指定預設使用者名稱
-p
--set-password
為預設使用者設定密碼
-c
--user-data
指定 Cloud-init 寫入檔路徑(用於自動化初始化設定)
--isolated
建立隔離機器(關閉檔案共享與系統整合)
--isolate-network
封鎖隔離機器存取其他機器與宿主機 IP
--forward-ssh-agent
為隔離機器啟用 SSH Agent 轉發
--mount
為隔離機器新增指定的宿主機掛載點(格式:來源[:目標],可重複使用)
一些快速上手的範例
1. 建立具有 Root 權限的獨立工作空間
若需要一個能隨意使用 sudo 測試安裝套件或準備素材的獨立環境,可以直接指定架構建立:
建立 x86 (amd64) 架構的 Ubuntu 虛擬機器
orb create --a amd64 ubuntu
進入該虛擬機器(以預設 ubuntu 為例)
orb -m ubuntu
進入之後你會發現提示詞有變化,會不一樣
就像你登入 SSH 一樣
然後就可以在這個環境自由的操作了
2. 其他各種常見的情境
這裏列出其他常見的指令範例,供參考
建立最新版 Ubuntu(自動命名)
orb create ubuntu
註:你可以用 tab 鍵去看有哪些發行版可以用,目前只支援 Linux 常見的發行版
官方也明確表示不支援 Windows 虛擬機
這個時候插上對應的實體埠,應該會看到你設定的對應的 IP
插上 Port 2,電腦會得到 IP: 192.168.10.254 (假設),可以正常上網
改插上 Port 3,電腦會得到 IP: 192.168.20.254 (假設),可以正常上網
Port 4, Port 5 是 Trunk Port 可以配合之前說的 OpenWRT 配置就可以上網
在 Windows 環境下運行應用程式時,將其註冊為系統服務能大幅提升管理效率。
這篇文章將介紹 NSSM(Non-Sucking Service Manager)這個強大工具,
手把手教你如何快速建立 Windows 服務。
除了介紹 NSSM 與基礎的服務建立步驟,我們還會帶你瞭解 Windows 服務背後的權限原理,
探討如何安全地授予一般權限使用者開啟或關閉指定服務的權限,讓團隊協作更靈活,DevOps 流程更順暢。無論你是初學者或經驗豐富的系統管理員,這篇文章都能幫助你提升 Windows 服務管理的效率,讓你對 Windows 服務有更近一步的瞭解。
TL;DR
使用 NSSM (Non-Sucking Service Manager) 註冊服務
nssm 為了以後設定方便,使用指令來操作
假設我有一個 Windows 服務,名叫 MyService 你可以這麼做
(執行以下指令需使用 cmd 系統管理員權限)
nssm install "MyService" "C:\Java\bin\java.exe" "-jar C:\MyService\app.jar"
nssm set MyService AppDirectory "C:\MyService\"
nssm set MyService Description "This is my service"
- name: Windows Service testing
hosts: jenkins
gather_facts: no
tasks:
- name: Stop service
ansible.windows.win_service:
name: MyService
state: stopped
- name: Start service
ansible.windows.win_service:
name: MyService
start_mode: delayed
state: started
root@OpenWrt:~# parted /dev/sda
GNU Parted 3.6
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: ATA Kston 64GB (scsi)
Disk /dev/sda: 64.0GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
128 17.4kB 262kB 245kB bios_grub
1 262kB 17.0MB 16.8MB fat16 legacy_boot
2 17.0MB 64.0GB 64.0GB ext4
# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UP qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state DOWN qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state DOWN qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state DOWN qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
6: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
你會看到類似 eth0eth1eth2eth3(或 enp* 名稱)
確認哪個 port 對應哪條實體網路線:
# 逐一測試,觀察 Link 狀態
ip link set eth0 up
cat /sys/class/net/eth0/carrier # 1 = 有連線, 0 = 無連線
OpenWRT x86 預設:
eth0 → LAN(br-lan,IP: 192.168.1.1)
eth1 → WAN(DHCP client)
預設就有設定好 NAT 連線。
以我的例子為例,
LAN1 port 是 eth0
LAN2 port 是 eth1
LAN3 port 是 eth2
WAN port 是 eth3
就依序設定好對應的 WAN 與 LAN,可能跟你的情況不同。
這邊你用 Web UI 設定也可以。
這邊還是提供指令版的修改網路設定(1 WAN + 3 LAN)
編輯 /etc/config/network:
vi /etc/config/network
內容為
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option type 'bridge'
option proto 'static'
option ipaddr '192.168.1.1'
option netmask '255.255.255.0'
option ip6assign '60'
list device 'eth0'
list device 'eth1'
list device 'eth2' # 將 eth1, eth2 也加入 LAN bridge
config interface 'wan'
option device 'eth3' # 指定第4個 port 為 WAN
option proto 'dhcp' # 或 pppoe
在 OpenWRT 中,你需要明確指定哪個實體 NIC 網卡用於 WAN 或 LAN,
x86 硬體與一般路由器不同,端口角色必須手動設定。
# apk info | grep wpad
WARNING: opening from cache https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/packages/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/base/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/kmods/6.12.67-1-aa4948ece684816486d1fa5040ce0bb3/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/luci/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/packages/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/routing/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/telephony/packages.adb: No such file or directory
WARNING: opening from cache https://downloads.openwrt.org/snapshots/packages/aarch64_cortex-a53/video/packages.adb: No such file or directory
wpad-basic-mbedtls
(這些 WARNING 可以先不用理會,關注在搜尋結果即可)
移除wpad-basic-mbedtls 套件,改安裝 wpad-wolfssl 套件
apk del wpad-basic-mbedtls && apk add wpad-wolfssl
勾選Generate PMK locally (本地生成 PMK) 。 (When using a PSK, the PMK can be automatically generated. When enabled, the R0/R1 key options below are not applied. Disable this to use the R0 and R1 key options.) 說明:勾選後路由器會自動處理金鑰,不需要手動輸入繁瑣的 R0KH/R1KH 列表。
BusyBox v1.37.0 (2026-01-02 17:07:02 UTC) built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt SNAPSHOT, r32804-ac8b5526bc
-----------------------------------------------------
OpenWrt recently switched to the "apk" package manager!
OPKG Command APK Equivalent Description
------------------------------------------------------------------
opkg install <pkg> apk add <pkg> Install a package
opkg remove <pkg> apk del <pkg> Remove a package
opkg upgrade apk upgrade Upgrade all packages
opkg files <pkg> apk info -L <pkg> List package contents
opkg list-installed apk info List installed packages
opkg update apk update Update package lists
opkg search <pkg> apk search <pkg> Search for packages
------------------------------------------------------------------
For more information visit:
https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet
Nouveau can usually be disabled by adding files to the modprobe configuration
directories and rebuilding the initramfs.
Would you like nvidia-installer to attempt to create these modprobe configuration
files for you?
One or more modprobe configuration files to disable Nouveau have been written.
You will need to reboot your system and possibly rebuild the initramfs before
these changes can take effect. Note if you later wish to reenable Nouveau, you
will need to delete these files:
/usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf,
/etc/modprobe.d/nvidia-installer-disable-nouveau.conf
WARNING: nvidia-installer was forced to guess the X library path '/usr/lib64' and X module path '/usr/lib64/xorg/modules'; these paths were not queryable from the system. If X fails to find the NVIDIA X driver module,
please install the `pkg-config` utility and the X.Org SDK/development package for your distribution and reinstall the driver.
警告: NVIDIA 安裝程式猜測 X 函式庫路徑為 /usr/lib64 且 X 模組路徑為 /usr/lib64/xorg/modules;這些路徑無法從系統中查詢到。
如果 X 無法找到 NVIDIA X 驅動程式模組,請安裝 pkg-config 工具以及適用於您發行版的 X.Org SDK/開發套件,然後重新安裝驅動程式。
這個警告可以忽略
按 OK 繼續
安裝 NVIDIA 32 位元相容性函式庫?
Install NVIDIA's 32-bit compatibility libraries?
您要安裝 NVIDIA 的 32 位元相容性函式庫嗎?
這邊選擇 NO
警告:未偵測到 Vulkan ICD 載入器
WARNING: This NVIDIA driver package includes Vulkan components, but no Vulkan ICD loader was detected on this system. The NVIDIA Vulkan ICD will not function without the loader. Most distributions package the Vulkan loader;
try installing the "vulkan-loader", "vulkan-icd-loader", or "libvulkan1" package.
Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up.
您希望執行 nvidia-xconfig 工具來自動更新您的 X 設定檔嗎?這樣,當您重新啟動 X 時,就會使用 NVIDIA X 驅動程式。任何現有的 X 設定檔都會被備份。
這邊選擇 YES
完成
Installation of the NVIDIA Accelerated Graphics Driver for Linux-x86_64 (version: 550.142) is now complete. Please update your xorg.conf file as appropriate; see the file /usr/share/doc/NVIDIA_GLX-1.0/README.txt for
details.
sudo docker run --rm --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda11.6.0-ubi8
執行紀錄
# sudo docker run --rm --runtime=nvidia --gpus all nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda11.6.0-ubi8
[Vector addition of 50000 elements]
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
Copy output data from the CUDA device to the host memory
Test PASSED
Done
# kubectl get node node
NAME STATUS ROLES AGE VERSION
ubuntu2404-k8s-ctrl1 NotReady control-plane 3m22s v1.34.2
ubuntu2404-k8s-ctrl2 NotReady control-plane 9s v1.34.2
ubuntu2404-k8s-ctrl3 NotReady control-plane 5s v1.34.2
這邊因為還沒有設定 CNI,所以 STATUS 為 NotReady 是 正常現象
(叢集才設定一半,還沒設定網路,當然顯示 K8s 叢集不可用)
# kubeadm join 192.168.1.100:6443 --token kkxxxx.xxxxxxxxxxxxxdl2 --discovery-token-ca-cert-hash sha256:bdfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx19c --control-plane --cri-socket unix:///var/run/cri-dockerd.sock
[preflight] Running pre-flight checks
[preflight] Reading configuration from the "kubeadm-config" ConfigMap in namespace "kube-system"...
[preflight] Use 'kubeadm init phase upload-config --config your-config.yaml' to re-upload it.
error execution phase preflight:
One or more conditions for hosting a new control plane instance is not satisfied.
[failure loading certificate for CA: couldn't load the certificate file /etc/kubernetes/pki/ca.crt: open /etc/kubernetes/pki/ca.crt: no such file or directory, failure loading key for service account: couldn't load the private key file /etc/kubernetes/pki/sa.key: open /etc/kubernetes/pki/sa.key: no such file or directory, failure loading certificate for front-proxy CA: couldn't load the certificate file /etc/kubernetes/pki/front-proxy-ca.crt: open /etc/kubernetes/pki/front-proxy-ca.crt: no such file or directory, failure loading certificate for etcd CA: couldn't load the certificate file /etc/kubernetes/pki/etcd/ca.crt: open /etc/kubernetes/pki/etcd/ca.crt: no such file or directory]
Please ensure that:
* The cluster has a stable controlPlaneEndpoint address.
* The certificates that must be shared among control plane instances are provided.
To see the stack trace of this error execute with --v=5 or higher
遇到這段
failure loading certificate for CA: couldn't load the certificate file