在 Azure Linux VM 上运行 OpenClaw Gateway,通过 Azure Bastion 安全访问,NSG 加固网络。
架构要点
- VM 无公网 IP,仅通过 Azure Bastion SSH 访问
- NSG 规则:仅允许 Bastion 子网 SSH,拒绝公网 SSH
- Bastion Standard SKU 支持 CLI 隧道(
az network bastion ssh)
前置条件
- Azure 订阅(有创建计算和网络资源的权限)
- Azure CLI 已安装
- SSH 密钥对
- 约 20-30 分钟
部署步骤
1. 登录并注册资源提供商
az login
az extension add -n ssh
az provider register --namespace Microsoft.Compute
az provider register --namespace Microsoft.Network2. 设置变量
RG="rg-openclaw"
LOCATION="westus2"
VM_NAME="vm-openclaw"
ADMIN_USERNAME="openclaw"
VM_SIZE="Standard_B2as_v2"
OS_DISK_SIZE_GB=643. 创建网络资源
# 创建资源组
az group create -n "${RG}" -l "${LOCATION}"
# 创建 NSG(仅允许 Bastion 子网 SSH)
az network nsg create -g "${RG}" -n "nsg-openclaw-vm" -l "${LOCATION}"
az network nsg rule create -g "${RG}" --nsg-name "nsg-openclaw-vm" \
-n AllowSshFromBastionSubnet --priority 100 \
--access Allow --direction Inbound --protocol Tcp \
--source-address-prefixes "10.40.1.0/26" --destination-port-ranges 224. 创建 VM(无公网 IP)
az vm create -g "${RG}" -n "${VM_NAME}" -l "${LOCATION}" \
--image "Canonical:ubuntu-24_04-lts:server:latest" \
--size "${VM_SIZE}" --os-disk-size-gb "${OS_DISK_SIZE_GB}" \
--admin-username "${ADMIN_USERNAME}" \
--ssh-key-values "$(cat ~/.ssh/id_ed25519.pub)" \
--public-ip-address "" --nsg ""5. 创建 Azure Bastion
az network bastion create -g "${RG}" -n "bas-openclaw" -l "${LOCATION}" \
--vnet-name "vnet-openclaw" \
--public-ip-address "pip-openclaw-bastion" \
--sku Standard --enable-tunneling trueBastion 创建通常需要 5-30 分钟。
6. 通过 Bastion SSH 安装 OpenClaw
VM_ID="$(az vm show -g "${RG}" -n "${VM_NAME}" --query id -o tsv)"
az network bastion ssh \
--name "bas-openclaw" --resource-group "${RG}" \
--target-resource-id "${VM_ID}" \
--auth-type ssh-key --username "${ADMIN_USERNAME}" \
--ssh-key ~/.ssh/id_ed25519
# 在 VM 内执行
curl -fsSL https://openclaw.ai/install.sh -o /tmp/install.sh
bash /tmp/install.sh && rm -f /tmp/install.sh
openclaw gateway status费用参考
- Azure Bastion Standard SKU:约 $140/月
- VM(Standard_B2as_v2):约 $55/月
降低费用:
- 不用时 deallocate VM(停止计费)
- 不需要 SSH 时删除 Bastion(几分钟可重建)
- 使用 Basic Bastion SKU(约 $38/月,仅支持 Portal SSH)
清理
az group delete -n "${RG}" --yes --no-wait相关链接
- install-gcp — GCP 部署
- install-digitalocean — DigitalOcean 部署