1 概述
azure cli是管理azure云资源的命令行工具。
官网为:
https://learn.microsoft.com/zh-cn/cli/azure/
2 安装
2.1 容器安装
docker run -it mcr.microsoft.com/azure-cli
3 登录
9d039d31f8e5:/# az login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code NZL8HCV7U to authenticate.
Retrieving tenants and subscriptions for the selection...
[Tenant and subscription selection]
No Subscription name Subscription ID Tenant
----- ------------------- ------------------------------------ --------
[1] * Azure 订阅 2 31948b7e-32d1-420a-968f-cda1531xxxxx 默认目录
The default is marked with an *; the default tenant is '默认目录' and subscription is 'Azure 订阅 2' (31948b7e-32d1-420a-968f-cda1531xxxxx).
Select a subscription and tenant (Type a number or Enter for no changes):
Tenant: 默认目录
Subscription: Azure 订阅 2 (31948b7e-32d1-420a-968f-cda1531xxxxx)
[Announcements]
With the new Azure CLI login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink/?linkid=2271236
If you encounter any problem, please open an issue at https://aka.ms/azclibug
[Warning] The login output has been updated. Please be aware that it no longer displays the full list of available subscriptions by default.
提示用浏览器打开网址https://microsoft.com/devicelogin,并输入在命令行打印信息中显示的一个指定的码,即可登录。
4 命令
4.1 列出VPC
9d039d31f8e5:/# az network vnet list -o table
Name ResourceGroup Location NumSubnets Prefixes DnsServers DDOSProtection VMProtection
------- --------------- -------------- ------------ ----------- ------------ ---------------- --------------
ab-vnet aaa northcentralus 1 10.0.0.0/16 False
4.2 列出负载均衡器
9d039d31f8e5:/# az network lb list -o table
Location Name ProvisioningState ResourceGroup ResourceGuid
-------------- ------- ------------------- --------------- ------------------------------------
northcentralus demo-lb Succeeded aaa f3752990-b598-4aab-a04b-4979219e989c
4.3 列出虚拟机
9d039d31f8e5:/# az vm list -o table
Name ResourceGroup Location Zones
------ --------------- -------------- -------
ab AAA northcentralus
9d039d31f8e5:/# az vm list
[
{
"additionalCapabilities": {
"hibernationEnabled": false,
"ultraSsdEnabled": null
},
"applicationProfile": null,
"availabilitySet": null,
"billingProfile": null,
"capacityReservation": null,
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": null
}
},
"etag": null,
"evictionPolicy": null,
"extendedLocation": null,
"extensionsTimeBudget": null,
"hardwareProfile": {
"vmSize": "Standard_D4s_v3",
"vmSizeProperties": null
},
"host": null,
"hostGroup": null,
"id": "/subscriptions/31948b7e-32d1-420a-968f-cda1531xxxxx/resourceGroups/AAA/providers/Microsoft.Compute/virtualMachines/ab",
"identity": {
"principalId": "f3f7a5a4-20b7-48de-aee8-b8eb67c457d7",
"tenantId": "f6f134f0-dbf3-46f2-8ef8-ae6e0ad1c9eb",
"type": "SystemAssigned",
"userAssignedIdentities": null
},
"instanceView": null,
"licenseType": null,
"location": "northcentralus",
"managedBy": null,
"name": "ab",
"networkProfile": {
"networkApiVersion": null,
"networkInterfaceConfigurations": null,
"networkInterfaces": [
{
"deleteOption": "Detach",
"id": "/subscriptions/31948b7e-32d1-420a-968f-cda1531xxxxx/resourceGroups/aaa/providers/Microsoft.Network/networkInterfaces/ab724",
"primary": null,
"resourceGroup": "aaa"
}
]
},
"osProfile": {
"adminPassword": null,
"adminUsername": "lj",
"allowExtensionOperations": true,
"computerName": "ab",
"customData": null,
"linuxConfiguration": {
"disablePasswordAuthentication": false,
"enableVmAgentPlatformUpdates": null,
"patchSettings": {
"assessmentMode": "ImageDefault",
"automaticByPlatformSettings": {
"bypassPlatformSafetyChecksOnUserSchedule": false,
"rebootSetting": "IfRequired"
},
"patchMode": "AutomaticByPlatform"
},
"provisionVmAgent": true,
"ssh": null
},
"requireGuestProvisionSignal": true,
"secrets": [],
"windowsConfiguration": null
},
"plan": null,
"platformFaultDomain": null,
"priority": null,
"provisioningState": "Succeeded",
"proximityPlacementGroup": null,
"resourceGroup": "AAA",
"resources": null,
"scheduledEventsPolicy": null,
"scheduledEventsProfile": null,
"securityProfile": {
"encryptionAtHost": null,
"encryptionIdentity": null,
"proxyAgentSettings": null,
"securityType": "TrustedLaunch",
"uefiSettings": {
"secureBootEnabled": true,
"vTpmEnabled": true
}
},
"storageProfile": {
"dataDisks": [],
"diskControllerType": "SCSI",
"imageReference": {
"communityGalleryImageId": null,
"exactVersion": "20.04.202405130",
"id": null,
"offer": "0001-com-ubuntu-server-focal",
"publisher": "canonical",
"sharedGalleryImageId": null,
"sku": "20_04-lts-gen2",
"version": "latest"
},
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage",
"deleteOption": "Delete",
"diffDiskSettings": null,
"diskSizeGb": 128,
"encryptionSettings": null,
"image": null,
"managedDisk": {
"diskEncryptionSet": null,
"id": "/subscriptions/31948b7e-32d1-420a-968f-cda1531xxxxx/resourceGroups/aaa/providers/Microsoft.Compute/disks/ab_OsDisk_1_d073c751c80543e086b3de893bb1fc22",
"resourceGroup": "aaa",
"securityProfile": null,
"storageAccountType": "Standard_LRS"
},
"name": "ab_OsDisk_1_d073c751c80543e086b3de893bb1fc22",
"osType": "Linux",
"vhd": null,
"writeAcceleratorEnabled": null
}
},
"tags": null,
"timeCreated": "2024-06-04T16:51:03.359635+00:00",
"type": "Microsoft.Compute/virtualMachines",
"userData": null,
"virtualMachineScaleSet": null,
"vmId": "b4c7523a-87a9-4476-96e8-5bd8808xxxxx",
"zones": null
}
]
4.4 列出mysql
9d039d31f8e5:/# az mysql flexible-server list -o table
Name Resource Group Location Version Storage Size(GiB) Tier SKU State HA State Availability zone
------ ---------------- ---------------- --------- ------------------- --------- ------------- ------- ---------- -------------------
abc aaa North Central US 8.0.21 20 Burstable Standard_B1ms Ready NotEnabled
5 小结
本文介绍azure cli的容器情景的安装和列表型命令的使用。