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

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

最新文章

  1. D3中动画(transition函数)的使用
  2. thinkphp 3.2加载类
  3. tomcat war部署根目录下
  4. centos6.6编译安装lnmp系列之PHP
  5. 解Tom大叔出的Javascript题目
  6. Bash Shell read file line by line and substring
  7. cometd的js端代码
  8. 自己实现的一款在线Javascript正则表达式测试器——JRE-Parser
  9. 可灵活扩展的自定义Session状态存储驱动
  10. Remote Direct Memory Access (RDMA)
  11. 设置ORACLE环境变量
  12. RMAN数据库恢复 之归档模式有(无)备份-丢失数据文件的恢复
  13. 抽象类(abstract class)和 接口(interface)
  14. log4net和一般的记录日志方法
  15. 10个实用的PHP正则表达式汇总
  16. SOA面向服务架构
  17. 如何使用LightningChart拖放功能进行数据转移 ?
  18. IntelliJ IDEA 环境常用设置整理
  19. Pycharm配置(三)
  20. 简单的ajax遮罩层(加载进度圈)cvi_busy_lib.js

热门文章

  1. vue引入bootstrap.min.css报错:Cannot find module &quot;./assets/css/bootstrap.min.css&quot;
  2. Python多线程循环
  3. 20165101刘天野 2017-2018-2 《Java程序设计》第5周学习总结
  4. .NET自带泛型委托方法Func、Action和Predicate
  5. 通过公钥解密密文思路(256bits RSA)
  6. Java 访问修饰符总结
  7. Luogu-3346 [ZJOI2015]诸神眷顾的幻想乡
  8. jqgrid的scroll参数的使用
  9. HDU 3473 Minimum Sum (划分树求区间第k大带求和)(转)
  10. JAVA题库01