Azure支持多种管理方法。命令行方法有:

  • PowerShell,PowerShell只能运行在Windows上
  • Azure CLI,而Azure CLI可以运行在Windows、MAC以及Linux上

如果能够熟悉Azure CLI,在各种平台的命令格式都相同。

在Windows上和MAC上安装Azure CLI只要下载安装软件包就可以了,但在Linux上安装,需要安装NodeJS和NPM,然后用npm安装Azure-cli。安装过程和方法在前面都介绍过,请参考:

http://www.cnblogs.com/hengwei/p/5183493.html

由于Azure China已经支持ARM模式,但在用Azure CLI使用ARM的时候,会遇到多种报错信息。本文将介绍目前如何使用Azure CLI管理Azure China的ARM模式。

1. NodeJS版本

在Ubuntu的Linux下,安装Azure CLI的方式是:apt-get install node; apt-get install npm; npm install -g azure-cli

其中apt-get的source list请参考:

http://wiki.ubuntu.org.cn/%E6%A8%A1%E6%9D%BF:14.04source

在CentOS的Linux下,安装Azure CLI的方式是:yum install nodejs; apt-get install npm; npm install -g azure-cli

Epel的repo请参考:

http://www.cnblogs.com/hengwei/p/5183493.html

npm的国内源请参考:

http://www.cnblogs.com/hengwei/p/5183493.html

安装完成后,就可以使用Azure的CLI了。

但在这种模式下,切换到ARM时,会有报错:

[root@hwarmvm01 ~]# azure login -e AzureChinaCloud -u admin@xxxx.partner.onmschina.cn
info: Executing command login
Password: ********
+ Authenticating...
error: CERT_UNTRUSTED
info: Error information has been recorded to /root/.azure/azure.err
error: login command failed [root@hwarmvm01 ~]# cat /root/.azure/azure.err
--27T08::.308Z:
{ [Error: CERT_UNTRUSTED]
stack: [Getter/Setter],
__frame:
{ name: '__1',
line: ,
file: '/usr/lib/node_modules/azure-cli/lib/commands/login.js',
prev: undefined,
calls: ,
active: false,
offset: ,
col: },
rawStack: [Getter] }
Error: CERT_UNTRUSTED
<<< async stack >>>
at __1 (/usr/lib/node_modules/azure-cli/lib/commands/login.js::)
<<< raw stack >>>
at SecurePair.<anonymous> (tls.js::)
at SecurePair.emit (events.js::)
at SecurePair.maybeInitFinished (tls.js::)
at CleartextStream.read [as _read] (tls.js::)
at CleartextStream.Readable.read (_stream_readable.js::)
at EncryptedStream.write [as _write] (tls.js::)
at doWrite (_stream_writable.js::)
at writeOrBuffer (_stream_writable.js::)
at EncryptedStream.Writable.write (_stream_writable.js::)
at write (_stream_readable.js::)

这个报错是由于nodejs的版本太低造成的:

root@hwubuntu02:~# node -v
v0.10.25

需要升级到4.x的版本。升级步骤如下文:

https://nodejs.org/en/download/package-manager/#installing-node-js-via-package-manager

我采用的是CentOS的机器,具体方法如下:

curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -
yum install -y nodejs

安装完成后,查看nodejs的版本:

[root@hwarmvm01 ~]# node -v
v4.4.5

再执行登陆的命令:

[root@hwarmvm01 ~]# azure login -e AzureChinaCloud -u admin@xxxx.partner.onmschina.cn
info: Executing command login
Password: ********
|info: Added subscription xxxx1
info: Added subscription xxxx2
info: Setting subscription "xxxx1" as default
+
info: login command OK
[root@hwarmvm01 ~]# azure account set xxxx1
info: Executing command account set
info: Setting subscription to "xxxx1" with id "xxxxxxxx".
info: Changes saved
info: account set command OK

2. Azure-cli的版本

登陆后,执行ARM的命令:

[root@hwarmvm01 ~]# azure vm list
info: Executing command vm list
+ Getting virtual machines
error: The resource type 'virtualMachines' could not be found in the namespace 'Microsoft.Compute' for api version '2016-03-30'. The supported api-versions are '2015-05-01-preview,2015-06-15'.
info: Error information has been recorded to /root/.azure/azure.err
error: vm list command failed

仍然有报错,此时的报错是说api的版本不匹配。这个原因是Azure China的ARM版本和Global的不同。用npm安装的版本是0.10.0:

[root@hwarmvm01 ~]# azure
info: _ _____ _ ___ ___
info: /_\ |_ / | | | _ \ __|
info: _ ___/ _ \__/ /| |_| | / _|___ _ _
info: (___ /_/ \_\/___|\___/|_|_\___| _____)
info: (_______ _ _) _ ______ _)_ _
info: (______________ _ ) (___ _ _)
info:
info: Microsoft Azure: Microsoft's Cloud Platform
info:
info: Tool version 0.10.

但目前Azure China要求的版本是0.9.x,比如0.9.18:

https://github.com/Azure/azure-xplat-cli/releases/tag/v0.9.18-hotfix

下载:

wget https://github.com/Azure/azure-xplat-cli/archive/v0.9.18-hotfix.tar.gz

先卸载原有Azure CLI:

cd /usr/local/lib
npm uninstall azure-cli

再安装:

npm install -g /root/v0.9.18-hotfix.tar.gz

安装完成后查看Azure CLI的版本:

[root@hwarmvm01 ~]# azure
info: _ _____ _ ___ ___
info: /_\ |_ / | | | _ \ __|
info: _ ___/ _ \__/ /| |_| | / _|___ _ _
info: (___ /_/ \_\/___|\___/|_|_\___| _____)
info: (_______ _ _) _ ______ _)_ _
info: (______________ _ ) (___ _ _)
info:
info: Microsoft Azure: Microsoft's Cloud Platform
info:
info: Tool version 0.9.

执行查询VM的命令:

[root@hwarmvm01 ~]# azure vm list
info: Executing command vm list
+ Getting virtual machines
data: ResourceGroupName Name ProvisioningState PowerState Location Size
data: ----------------- --------- ----------------- ---------- --------- -----------
data: HWARM01 hwarmvm01 Succeeded VM running chinaeast Standard_A1
data: HWERTEST hwarm01 Succeeded VM running chinaeast Standard_A1
info: vm list command OK

总结:

由于nodejs的版本和Azure-cli版本的问题,Azure China的ARM不能正常使用。正确的姿势应该是:

1. 采用4.x的nodejs

2. 采用0.9.x的Azure-cli

为不走弯路,建议开始就安装这两个版本。

Azure CLI的版本问题的更多相关文章

  1. Windows系统安装Azure CLI

    本文将介绍在Windos系统下如下安装CLI 1.打开Azure官方链接:https://www.azure.cn/downloads/ 2.按照向导进行安装 3.打开Windows Powershe ...

  2. Azure CLI 简单入门

    Azure CLI 是什么 Azure 命令行接口 (CLI) 是用于管理 Azure 资源的 Microsoft 跨平台命令行体验. Azure CLI 易于学习,是构建适用于 Azure 资源的自 ...

  3. Linux上使用Azure CLI来管理Azure

    在Windows上我们有强大的Powershell提供各种命令来管理Azure的服务,在Linux上微软提供了基于Node.JS的跨平台的Azure Command Line来帮助Linux用户来管理 ...

  4. 使用 Azure CLI 创建 Windows 虚拟机

    Azure CLI 用于从命令行或脚本创建和管理 Azure 资源. 本指南详细介绍如何使用 Azure CLI 部署运行 Windows Server 2016 的虚拟机. 部署完成后,我们连接到服 ...

  5. 使用 Azure CLI 管理 Azure 虚拟网络和 Linux 虚拟机

    Azure 虚拟机使用 Azure 网络进行内部和外部网络通信. 本教程将指导读者部署两个虚拟机,并为这些 VM 配置 Azure 网络. 本教程中的示例假设 VM 将要托管包含数据库后端的 Web ...

  6. 使用 Azure CLI 管理 Azure 磁盘

    Azure 虚拟机使用磁盘来存储 VM 操作系统.应用程序和数据. 创建 VM 时,请务必选择适用于所需工作负荷的磁盘大小和配置. 本教程介绍如何部署和管理 VM 磁盘. 学习内容: OS 磁盘和临时 ...

  7. 使用 Azure CLI 创建和管理 Linux VM

    Azure 虚拟机提供完全可配置的灵活计算环境. 本教程介绍 Azure 虚拟机的基本部署项目,例如选择 VM 大小.选择 VM 映像和部署 VM. 你将学习如何执行以下操作: 创建并连接到 VM 选 ...

  8. 使用 Azure CLI 创建 Linux 虚拟机

    Azure CLI 用于从命令行或脚本创建和管理 Azure 资源. 本指南详细介绍了如何使用 Azure CLI 部署运行 Ubuntu 服务器的虚拟机. 服务器部署以后,将创建 SSH 连接,并且 ...

  9. 使用 Azure CLI 在 Azure China Cloud 云平台上手动部署一套 Cloud Foundry

    这篇文章将介绍如何使用 Azure CLI 在 Azure China Cloud 云平台上手动部署一套 Cloud Foundry.本文的目的在于: 了解作为 PaaS 的 Cloud Foundr ...

随机推荐

  1. 字符串哈希小结(BKDR,RK)

    前言 A:这么简单的东西,怎么现在才学?? B:别提了,还不是因为菜o(╥﹏╥)o A:那打算讲些什么东西 B:\(BKDRHash\).\(Rabin-karp\)以及简单应用 简洁 所谓字符串哈希 ...

  2. ACM训练小结-2018年6月23日

    今天题目情况如下:    D题:SG函数相关.    相关知识忘光...已复习.    E题:丧心病狂的模拟题目.    F题:树分块+容斥.    想到了树上莫队,但是糟糕的是不会O(1)/O(lo ...

  3. dll和lib

    lib:里面包含了很多源代码,工程会将这些源代码加入自己的项目中编译: dll:动态编译库,允许可执行文件在运行中加载里面的资源. 使用lib需注意两个文件:(1).h头文件,包含lib中说明输出的类 ...

  4. relativePath

    比如: com.tenace tenace 2.0.1 ../pom.xml //刚开始无此句 com.spider engine 2.6.0-SNAPSHOT tenace作为pom项目已经发布至r ...

  5. CCNA 课程 三

    交换机的MAC地址学习情况: 1.从一个接口收到数据帧,根据数据帧的原mac地址查找交换机的mac地址表,如果没有找到,将会添加数据帧的原mac地址和收到数据帧接口的对应条目,放进交换机的mac地址表 ...

  6. Apache Phoenix基本操作-1

    本篇我们将介绍phoenix的一些基本操作. 1. 如何使用Phoenix输出Hello World? 1.1 使用sqlline终端命令 sqlline.py SZB-L0023780:2181:/ ...

  7. nginxif多条件结合判断(实现限速)

    参考文章: https://yq.aliyun.com/articles/44957 需求: 要对某一ip下,使用android客户端的用户进行限速 原理 就是用SET变量进行. AND 就用变量叠加 ...

  8. js状态模式

    状态模式,当一个对象的内在状态改变时允许改变其行为,这个对象看起来是改变了其类. 状态模式主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况.把状态的判断逻辑转移到表示不同状态的一系列类当 ...

  9. 将Sql2008的数据库转到2005

    今天碰到一个特别伤心的事情. 事情的起因是这样的,现在我负责评教系统的维护工作.由于中途服务器转迁,迁移之前数据库版本是2005,而现在的服务器版本是2008R2的.在这个过程并没有发生什么问题. 问 ...

  10. nginx路由重定向

    location / { if ($http_host !~ "m.xxx.cn"){ rewrite ^/web/(.*)/bdu(\d?)\.htm(.*)$ /rewrite ...