中国区azure cli powershell azure安装登录azure常见使用命令

最新版中国区azure cli及powershell安装及使用

Powershell azure 3.6.1和azure cli 2.3.0

wps1

安装前建议先卸载azure cli(windows设置卸载程序)与powershell模块(remove-module az 再uninstall-module az),

Azure工具介绍

Azure 提供了一套丰富的体验,可让你同时以编程方式和在 Azure 门户中创建并管理你的 Azure 资源、应用程序和项目

这里编程方式指的是2种,az cli工具或者powershell azure工具,门户指的是https://portal.azure.cn

Azure PowerShell:提供了一组带 cmdlet 的模块,可让你通过使用 Windows PowerShell 来管理 Azure 资源。(azure官网的常见操作都是通过Azure PowerShell命令,命令以谓词方式开头 比如GET SET NE等 )

Azure 命令行接口 (CLI):允许你连接到 Azure 订阅,并从命令行对 Azure 资源计划各种任务。(例如以az开头的各种az命令 例如az login,但不同于powershell azure命令)

Tips:Azure 命令行接口 (CLI)命令帮助可使用az –h

Azurecli使用帮助如下所示:

<pre>

PS C:\Users\Administrator> az –h

Group

    az

Subgroups:

    account                     : Manage Azure subscription information.

    acr                         : Manage private registries with Azure Container Registries.

    ad                          : Manage Azure Active Directory Graph entities needed for Role Based

                                  Access Control.

    advisor                     : Manage Azure Advisor.

    aks                         : Manage Azure Kubernetes Services.

    ams                         : Manage Azure Media Services resources.

    apim              [Preview] : Manage Azure API Management services.

    appconfig                   : Manage App Configurations.

    appservice                  : Manage App Service plans.

    backup            [Preview] : Manage Azure Backups.

    batch                       : Manage Azure Batch.

    billing                     : Manage Azure Billing.

    bot                         : Manage Microsoft Azure Bot Service.

    cache             [Preview] : Commands to manage CLI objects cached using the

                                  `–defer` argument.

    cdn                         : Manage Azure Content Delivery Networks (CDNs).

    cloud                       : Manage registered Azure clouds.

    cognitiveservices           : Manage Azure Cognitive Services accounts.

    consumption       [Preview] : Manage consumption of Azure resources.

    container                   : Manage Azure Container Instances.

    cosmosdb                    : Manage Azure Cosmos DB database accounts.

    deployment                  : Manage Azure Resource Manager template deployment at subscription

                                  scope.

    deploymentmanager [Preview] : Create and manage rollouts for your service.

    disk                        : Manage Azure Managed Disks.

    disk-encryption-set         : Disk Encryption Set resource.

    dla               [Preview] : Manage Data Lake Analytics accounts, jobs, and catalogs.

    dls               [Preview] : Manage Data Lake Store accounts and filesystems.

    dms                         : Manage Azure Data Migration Service (DMS) instances.

    eventgrid                   : Manage Azure Event Grid topics, event subscriptions, domains and

                                  domain topics.

    eventhubs                   : Manage Azure Event Hubs namespaces, eventhubs, consumergroups and

                      &#
160;           geo recovery configurations – Alias.

    extension                   : Manage and update CLI extensions.

    feature                     : Manage resource provider features.

    functionapp                 : Manage function apps. To install the Azure Functions Core tools

                                  see https://github.com/Azure/azure-functions-core-tools.

    group                       : Manage resource groups and template deployments.

    hdinsight                   : Manage HDInsight resources.

    identity                    : Managed Service Identities.

    image                       : Manage custom virtual machine images.

    iot                         : Manage Internet of Things (IoT) assets.

    iotcentral                  : Manage IoT Central assets.

    keyvault                    : Manage KeyVault keys, secrets, and certificates.

    kusto                       : Manage Azure Kusto resources.

    lab               [Preview] : Manage Azure DevTest Labs.

    lock                        : Manage Azure locks.

    managedapp                  : Manage template solutions provided and maintained by Independent

                                  Software Vendors (ISVs).

    managedservices             : Manage the registration assignments and definitions in Azure.

    maps                        : Manage Azure Maps.

    mariadb                     : Manage Azure Database for MariaDB servers.

    monitor                     : Manage the Azure Monitor Service.

    mysql                       : Manage Azure Database for MySQL servers.

    netappfiles       [Preview] : Manage Azure NetApp Files (ANF) Resources.

    network                     : Manage Azure Network resources.

    openshift                   : Manage Azure Red Hat OpenShift Services.

    policy                      : Manage resource policies.

    postgres                    : Manage Azure Database for PostgreSQL servers.

    ppg                         : Manage Proximity Placement Groups.

    provider                    : Manage resource providers.

    redis                       : Manage dedicated Redis caches for your Azure applications.

    relay                       : Manage Azure Relay Service namespaces, WCF relays, hybrid

                                  connections, and rules.

    reservations      [Preview] : Manage Azure Reservations.

    resource                    : Manage Azure resources.

    role                        : Manage user roles for access control with Azure Active Directory

                                  and service principals.

    search            [Preview] : Manage Azure Search services, admin keys and query keys.

    security          [Preview] : Manage your security posture with Azure Security Center.

    servicebus                  : Manage Azure Service Bus namespaces, queues, topics,

                                  subscriptions, rules and geo-disaster recovery configuration

                                  alias.

    sf                [Preview] : Manage and administer Azure Service Fabric clusters.

    s
ig                         : Manage shared image gallery.

    signalr                     : Manage Azure SignalR Service.

    snapshot                    : Manage point-in-time copies of managed disks, native blobs, or

                                  other snapshots.

    sql                         : Manage Azure SQL Databases and Data Warehouses.

    storage                     : Manage Azure Cloud Storage resources.

    tag                         : Manage resource tags.

    vm                          : Manage Linux or Windows virtual machines.

    vmss                        : Manage groupings of virtual machines in an Azure Virtual Machine

                                  Scale Set (VMSS).

    webapp                      : Manage web apps.

Commands:

    configure                   : Manage Azure CLI configuration. This command is interactive.

    feedback                    : Send feedback to the Azure CLI Team!

    find                        : I’m an AI robot, my advice is based on our Azure documentation as

                                  well as the usage patterns of Azure CLI and Azure ARM users. Using

                                  me improves Azure products and documentation.

    interactive       [Preview] : Start interactive mode. Installs the Interactive

                                  extension if not installed already.

    login                       : Log in to Azure.

    logout                      : Log out to remove access to Azure subscriptions.

    rest                        : Invoke a custom request.

    version           [Preview] : Show the versions of Azure CLI modules and extensions in

                                  JSON format by default or format configured by –output.

</pre>

如何安装 Azure CLI

Azure CLI 可以安装在 Windows、macOS 和 Linux 环境中。它还可以在 Docker 容器和 Azure Cloud Shell 中运行。

文章这里只介绍Windows安装Azure CLI中国,其他Linux系统安装azure cli请参考:azure cli安装指南

在 Windows 上安装 Azure CLI

在 Windows 上,Azure CLI 是通过 MSI 安装的,因此,可以通过 Windows 命令提示符 (CMD) 或 PowerShell 访问 CLI,为适用于 Linux 的 Windows 子系统 (WSL) 安装时,可以安装适用于 Linux 分发版的包。请参阅安装主页,获取受支持包管理器的列表,或者了解如何在 WSL 下手动进行安装。

Azure CLI 的当前版本为 2.3.0。有关Azure CLI最新版本的信息,请参考发行说明。若要查看已安装的版本并查看是否需要更新,请cmd或者powershell运行

<pre>

az –version

</pre>

Azure cli安装或更新Install or update

MSI 分发版用于在 Windows 上安装或更新 Azure CLI。在使用 MSI 安装程序之前,不需要卸载任何当前版本。

下载 Azure Cli MSI 安装程序Download the MSI installer

或者使用一一网络直接下载:Azure CLI
直接下载:net4.8

当安装程序询问是否可以对计算机进行更改时,请单击“是”框。也可使用 PowerShell 安装 Azure CLI。 以管理员身份启动 PowerShell 并运行以下命令:

<pre>

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList ‘/I AzureCLI.msi /quiet’

</pre>

这将下载并安装适用于 Windows 的 Azure CLI 最新版本。 如果已安装一个版本,这将更新现有版本。安装完成后,需要重新打开 PowerShell 以使用 Azure CLI。

现在可以通过 Windows 命令提示符或 PowerShell 使用 az 命令运行 Azure CLI 了。提供了 Windows 命令提示符所不能提供的一些 Tab 键补全功能。若要登录,请运行 az login 命令,或者参考azure命令大全

<pre>

az login

</pre>

如果 CLI 可以打开默认浏览器,它将这样做并加载 Azure 登录页。否则,请在 https://aka.ms/devicelogin 处打开浏览器页,然后输入终端中显示的授权代码。

到这里A
zure cli安装完成

如何卸载 Azure CLI

通过 Windows 中的“应用和功能”列表卸载 Azure CLI。若要卸载:

表 1

平台Platform

InstructionsInstructions

Windows 10Windows 10

“开始”>“设置”>“应用”Start > Settings > Apps

Windows 8Windows 8
Windows 7Windows 7

“开始”>“控制面板”>“程序”>“卸载程序”Start > Control Panel > Programs > Uninstall a program

请在程序搜索栏中键入 Azure CLI。要卸载的程序列为“Microsoft CLI 2.0 for Azure”。选择此应用程序,然后单击 Uninstall 按钮。

安装 Azure Powershell 模块

(Azure Powershell是一个powershell的模块与azure cli不同,azurecli是一个独立的工具,cmd与powershell是azurecli的入口,azure powershell的入口只有powershell)

PowerShellGet只是powershell安装azure模块的工具,安装过程中的确认有A输入A有Y输入Y

本文介绍如何使用Powershell的PowerShellGet 安装 Azure PowerShell 模块。这些说明适用于 Windows、macOS 和 Linux 平台。对于 Az 模块,当前不支持其他安装方法。

必要环境要求

Azure PowerShell 适用于 Windows 上的 PowerShell 5.1 或更高版本,或者所有平台上的 PowerShell Core 6.x 及更高版本。如果不确定是否有 PowerShell,或者是在 macOS 或 Linux 平台上,请安装最新版 PowerShell Core,最新Windows10默认满足 PowerShell 5.1。.

若要检查 PowerShell 版本,请在powershell运行以下命令:

<pre>

$PSVersionTable.PSVersion

</pre>

Windows Azure PowerShell安装的2个必要条件

1. Windows powershell更新到 Windows PowerShell 5.1。如果是在 Windows 10 平台上,则已安装 PowerShell 5.1。

2. 安装 .NET Framework 4.7.2 或更高版本。Windows10有可能已启用。Net4.8,应该不用安装,可以通过程序启用或关闭功能中查看是否启用

macOS 或 Linux 平台在使用 PowerShell Core 时,对于 Azure PowerShell 没有其他要求。

在系统上为所有用户进行安装,需要有管理员权限。从提升的 PowerShell 会话中,以管理员身份运行,或使用 sudo 命令在 macOS 或 Linux 上运行:

<pre>

Install-Module -Name Az -AllowClobber -Scope AllUsers

</pre>

默认情况下,PowerShell 库未配置为 PowerShellGet 的受信任存储库。首次使用 PSGallery 时会看到以下提示:输入A

<pre>

Untrusted repository

You are installing the modules from an untrusted repository. If you trust this repository, change

its InstallationPolicy value by running the Set-PSRepository cmdlet.

Are you sure you want to install the modules from ‘PSGallery’?

[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"):

</pre>

Az 模块是 Azure PowerShell cmdlet 的汇总模块。安装它时,系统会下载所有可用的 Azure 资源管理器模块并使其 cmdlet 可供使用,下载交慢,建议联通网络下载,移动限速。

更新 Azure PowerShell 模块Update the Azure PowerShell module

<pre>

Install-Module -Name Az -AllowClobber -Force

</pre>

使用多个版本的 Azure PowerShell

检查az模块版本信息|管道符后筛选

<pre>

Get-InstalledModule -Name Az -AllVersions | select Name,Version

</pre>

如果模块自动加载,模块自动加载和 Import-Module 默认情况下会加载最新版本。如果模块没加载可以通过powershell命令加载Azure powershell模块

<pre>Import-Module </pre>

中国区通过powershell azure模块登录Azure

Get-AzEnvironment 命令可以获取所在区域的环境名称。

<pre>

Get-AzEnvironment

</pre>

登录中国区Azure

<pre>

Connect-AzAccount -Environment AzureChinaCloud

</pre>

在 PowerShell 5.1 环境中,将显示一个登录对话框,用于为 Azure 帐户提供用户名和密码。在 PowerShell 的每个其他版本上,你将获得可在 [https://microsoft.com/devicelogin ] 上使用的令牌。在浏览器中打开此页面,输入令牌,使用 Azure 帐户凭据登录,然后对 Azure PowerShell 进行授权。

查找命令Find commands

Azure PowerShell cmdlet 遵循 PowerShell 的标准命名约定 谓词描述操作(例如 New、Get、Set 和 Remove),名词描述资源类型(例如 AzVM、AzKeyVaultCertificate、AzFirewall 和 AzVirtualNetworkGateway)

Azure PowerShell 中的名词始终以 Az 前缀开头。有关标准谓词的完整列表,请参阅 PowerShell 命令的已批准谓词

了解名词、谓词和 Azure PowerShell 模块有助于使用 Get-Command cmdlet 查找命令。例如,若要查找使用 Get 谓词的所有 VM 相关命令:

<pre>

Get-Command -Verb Get -Noun AzVM* -Module Az.Compute

</pre>

为帮助你查找常用命令,下表列出了资源类型、相应的 Azure PowerShell 模块,以及要在 Get-Command 中使用的名词前缀:

表 1

资源类型Resource type

Azure PowerShell 模块Azure PowerShell module

名词前缀Noun prefix

资源组Resource group

Az.ResourcesAz.Resources

AzResourceGroup

虚拟机Virtual machines

Az.ComputeAz.Compute

AzVM

存储帐户Storage accounts

Az.StorageAz.Storage

AzStorageAccount

Key VaultKey Vault

Az.KeyVaultAz.KeyVault

AzKeyVault

Web 应用程序Web applications

Az.WebsitesAz.Websites

AzWebApp

SQL 数据库SQL databases

Az.SqlAz.Sql

AzSqlDatabase

有关 Azure PowerShell 中的模块的完整列表,请参阅 GitHub 上的 Azure PowerShell 模块列表

更多请参考VPN网关指南

https://docs.azure.cn/zh-cn/vpn-gateway/

Powershell azureopenvpn P2S VPN 客户端播发自定义路由

你可能想要向所有点到站点 VPN 客户端播发自定义路由。 例如,当你在 VNet 中启用了存储终结点并希望远程用户能够通过 VPN 连接访问这些存储帐户时。可以向所有远程用户播发存储终结点的 IP 地址,以使到存储帐户的流量通过 VPN 隧道,而不是公共 Internet。wps2

Azure openvpn播发自定义路由To advertise custom routes

若要播发自定义路由,请使用 Set-AzVirtualNetworkGateway cmdlet。 以下示例演示如何播发 Contoso 存储帐户表的 IP。

1、Ping contoso.table.core.chinacloudapi.cn 并记录 IP 地址。

<pre>

C:\>ping contoso.table.core.chinacloudapi.cnPinging table.by4prdstr05a.store.core.chinacloudapi.cn [13.88.144.250] with 32 bytes of data:

</pre>

2、运行以下 PowerShell 命令:

<pre>

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute 13.88.144.250/32

</pre>

请使用逗号和空格分隔地址。例如:

<pre>

Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute x.x.x.x/xx , y.y.y.y/yy

</pre>

查看自定义路由To view custom routes

使用以下示例查看自定义路由:

<pre>

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>$gw.CustomRoutes | Format-List

</pre>

删除自定义路由To delete custom routes

使用以下示例删除自定义路由:Use the following example to delete custom routes:

<pre>

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute @0

</pre>

后续步骤Next steps

有关其他 P2S 路由信息,请参阅关于点到站点路由

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享