3

使用az创建azure虚拟机

 2 years ago
source link: https://www.bboy.app/2021/08/19/%E4%BD%BF%E7%94%A8az%E5%88%9B%E5%BB%BAazure%E8%99%9A%E6%8B%9F%E6%9C%BA/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用az创建azure虚拟机

发表于

2021-08-19 分类于 azure

202108190952729.png

azure的dashboard一直很卡,有时候还会创建虚拟机失败。好在azure的cli az很给力,之后可以研究一下使用gitlab的流水线去创建主机

brew update && brew install azure-cli

az login

接着查询你的资源组

az group list -o table

查询你的订阅

az account list -o table

查询目前,或者账号的可用地区

az account list-locations -o table

创建资源组

az group create -l eastus --name 名字 --subscription 订阅id

删除资源组

az group delete --name 名字 --subscription 订阅id

查找某个区域可以使用的虚拟机配置

az vm list-sizes -l westus2 -o table

az vm create -n 虚拟机名字  \
-g 资源组名字 \
--image Centos \ # 使用的系统镜像
--admin-password '管理员密码' \
--admin-username '管理员用户名' \
--size Standard_B2s \ # 虚拟机的配置
--tags "项目"="测试项目" "用途"="测试" \ # 虚拟机标签
--storage-sku StandardSSD_LRS \ # 系统盘的sku
--public-ip-sku Basic # 公网ip的sku

给主机添加数据盘

az vm disk attach --new  \ # 表示新建磁盘
-g 资源组名字 \
--vm-name 挂载的虚拟机名字 \
--size-gb 128 \ #磁盘大小
--sku StandardSSD_LRS \ # 磁盘sku
--name 磁盘名字

卸载主机磁盘

az vm disk detach -g 资源组名字 \ 
--vm-name 虚拟机名字 \
-n 磁盘名字

删除虚拟机

az vm delete  -n 虚拟机名字 \
-g 资源组名字

创建安全组规则

az network nsg list -o table

查看安全组规则

az network nsg show --name 安全组规则名字 \
--resource-group 资源组名字

更新安全组规则

az network nsg rule update --name 规则名字 \
--resource-group 资源组名字 \
--nsg-name 安全组名字 \
--direction 入站规则还是出站规则 \
--source-address-prefixes 源ip 如果添加多个ip 1.1.1.1 2.2.2.2 当中为空格

欢迎关注我的博客www.bboy.app

Have Fun


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK