azure cli的安装和使用

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的容器情景的安装和列表型命令的使用。

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Azure CLI是一个跨平台的开源命令行工具,用于在Azure门户中创建或管理资源。通过Azure CLI,我们可以直接从Windows命令提示符发出命令并处理Azure资源。它可以在Windows、Linux或Mac OS上安装,并使用相同的命令集进行操作。要安装Azure CLI,可以从Azure官方网站下载并在本地环境中安装安装完成后,可以使用Windows PowerShell来运行Azure CLI命令。例如,要查看Azure CLI的版本号,可以在Windows PowerShell中输入"az --version"命令。此外,还可以直接从Azure门户中使用Azure CLI,但在与Azure门户通过Windows命令行进行通信时,前者更加方便。在接下来的文章中,我将详细介绍如何使用Azure CLIAzure门户中创建和管理资源。 #### 引用[.reference_title] - *1* *3* [azure3.0_Azure CLI 2.0入门](https://blog.csdn.net/culuo4781/article/details/107618308)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Azure CLI 简单入门](https://blog.csdn.net/weixin_30835649/article/details/101746962)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值