Skip to content

Azure Cli 开机命令

224字小于1分钟

Azure

2024-09-03

# group 资源组名称
# location 开机区域
# image 镜像(Debian11: Debian:debian-11:11-gen2:latest | WindowsServer2012: MicrosoftWindowsServer:WindowsServer:2012-r2-datacenter-smalldisk-g2:latest)
# username 用户名
# password 密码
# size 机型(Standard_B1s | Standard_B2ats_v2 | Standard_B2pts_v2)
export group=default
export location=eastasia
export image=Debian:debian-11:11-gen2:latest
export username=uuser
export password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 16 | head -n 1)
export size=Standard_B2ats_v2

# 创建资源组
az group create \
    --name $group \
    --location $location

# 创建vps
az vm create \
  --resource-group $group \
  --name $location \
  --location $location \
  --public-ip-sku Basic \
  --public-ip-address-allocation dynamic \
  --image $image \
  --authentication-type password \
  --admin-username $username \
  --admin-password $password \
  --size $size \
  --os-disk-size-gb 64

# 创建入口规则
az network nsg rule create \
    --resource-group $group \
    --nsg-name "$location"NSG \
    --destination-port-ranges '*' \
    --name AllowAllInbound \
    --priority 100

# 创建出口规则
az network nsg rule create \
    --resource-group $group \
    --nsg-name "$location"NSG \
    --direction Outbound \
    --destination-port-ranges '*' \
    --name AllowAllOutbound \
    --priority 100

登录用户名: uuser

登录密码: 通过 echo $password 查看