Azure的VM提供了一种管理工具叫Azure VM Extension。它实现了一些管理虚拟机所需要的重要功能,比如:重设密码、设置RDP参数、以及许多其他关键的功能,并且Azure VM一直在添加新的Extension。默认情况下,创建的Windows VM会安装以下几个基本的VM Extension,包括IaaSDiagnostics,VMAccess和BGInfo。Linux的VM,如果开启Diagnostics功能,默认会安装LinuxDiagnostic的Extension。

通过Azure CLI可以获得Azure在某个区域提供的的Extension和相关信息。可以通过如下命令:

azure vm extension-image list

本文将介绍,通过PowerShell命令,给Azure的Linux VM添加CustomerScriptForLinux的Extension。

1 准备Azure VM

Azure VM在添加Extension时,必须是运行状态,同时,其Windows Azure Agent必须已经安装。可以通过如下命令查看是否有WAagent程序在运行:

[root@hwiscsi02 waagent]# ps -ef | grep "waagent -daemon" | grep -v grep

root    : ? :: python /usr/sbin/waagent -daemon

2 准备PowerShell环境

//登陆Azure China
$mycred = Get-Credential -UserName admin@weiheng.partner.onmschina.cn -Message hello
Login-AzureRmAccount -EnvironmentName AzureChinaCloud -Credential $mycred //定义Resource Group、VM和Location变量
$RGName = 'hwiscsi'
$VmName = 'hwiscsi02'
$Location = 'China East' //定义Extension相关信息
$ExtensionName = 'CustomScriptForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$version = '1.5' $PublicConf = '{"fileUris":["https://hwarm.blob.core.chinacloudapi.cn/soft/extension.sh"], "commandToExecute": "sh extension.sh" }' 
$PrivateConf = '{
  "storageAccountName": "hwarm",
  "storageAccountKey": "xxxxxxxx=="
}' //执行Set-AzureRmVMExtension命令,安装extension:
Set-AzureRmVMExtension -ResourceGroupName $RGName -VMName $VmName -Location $Location `
  -Name $ExtensionName -Publisher $Publisher `
  -ExtensionType $ExtensionName -TypeHandlerVersion $Version `
  -Settingstring $PublicConf -ProtectedSettingString $PrivateConf

执行完后,屏幕输出如下:

执行成功。

或者采用Azure CLI命令:

azure vm extension set hwiscsi hwiscsi02 CustomScriptForLinux Microsoft.OSTCExtensions  1.5 -i '{"fileUris":["https://hwarm.blob.core.chinacloudapi.cn/soft/extension.sh"], "commandToExecute": "sh extension.sh"}'

info:    Executing command vm extension set
+ Looking up the VM "hwiscsi02
+ Installing extension "CustomScriptForLinux", VM: "hwiscsi"
info: vm extension set command OK

3 检查VM内的信息

在VM中,可以在/var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/1.5.2.0查看相关的日志。

// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]sequence number is
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]setting file path is/var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.0/config/.settings
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]JSON config: {
// :: "runtimeSettings": [
// :: {
// :: "handlerSettings": {
// :: "publicSettings": {"fileUris":["https://hwarm.blob.core.chinacloudapi.cn/soft/extension.sh"],"commandToExecute":"sh extension.sh"}
// :: }
// :: }
// :: ]
// :: }
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Install,success,,Install succeeded
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]sequence number is
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]setting file path is/var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.0/config/.settings
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]JSON config: {
// :: "runtimeSettings": [
// :: {
// :: "handlerSettings": {
// :: "publicSettings": {"fileUris":["https://hwarm.blob.core.chinacloudapi.cn/soft/extension.sh"],"commandToExecute":"sh extension.sh"}
// :: }
// :: }
// :: ]
// :: }
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]set most recent sequence number to
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Command to execute:sh extension.sh
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Enable,transitioning,,Launching the script...
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]sequence number is
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]setting file path is/var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.0/config/.settings
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]JSON config: {
// :: "runtimeSettings": [
// :: {
// :: "handlerSettings": {
// :: "publicSettings": {"fileUris":["https://hwarm.blob.core.chinacloudapi.cn/soft/extension.sh"],"commandToExecute":"sh extension.sh"}
// :: }
// :: }
// :: ]
// :: }
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Will try to download files, number of retries = , wait SECONDS between retrievals = 20s
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Command to execute:sh extension.sh
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Downloading,transitioning,,Downloading files...
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]No azure storage account and key specified in protected settings. Downloading scripts from external links...
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Converting /var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.0/download//extension.sh from DOS to Unix formats: Done
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Removing BOM of /var/lib/waagent/Microsoft.OSTCExtensions.CustomScriptForLinux-1.5.2.0/download//extension.sh: Done
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Succeeded to download files, retry count =
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Internal DNS is ready, retry count =
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Command to execute:sh extension.sh
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Command is finished.
// :: ---stdout---
// ::
// :: ---errout---
// ::
// ::
// :: [Microsoft.OSTCExtensions.CustomScriptForLinux-1.0]Daemon,success,,Command is finished.
// :: ---stdout---

脚本执行成功。

通过PowerShell命令给Azure VM添加CustomScriptExtension的更多相关文章

  1. Azure AD Domain Service(一)将 Azure VM 实例添加到域服务里

    一,引言 有网友提到实际项目中如何将 Azuer VM 实例加入到 Azure AD 域,那我们今天就带着整个问题开始今天的分析!首先我们得了解什么是 Azure AD 域服务,Azure AD 域服 ...

  2. CentOS 7.2 PowerShell下安装Azure Module

    目前Linux版本的PowerShell还是Alpha版本,所以很多功能不能使用. 比如通过Powershell命令:install-module AzureRM在线安装Azure的Module.但我 ...

  3. 用于创建和管理 Azure 虚拟机的常用 PowerShell 命令

    本文介绍一些可用于在 Azure 订阅中创建和管理虚拟机的 Azure PowerShell 命令. 若要获取特定命令行开关和选项的详细帮助,可以使用 Get-Help 命令. 有关安装最新版 Azu ...

  4. Azure PowerShell (9) 使用PowerShell导出订阅下所有的Azure VM的Public IP和Private IP

    <Windows Azure Platform 系列文章目录> 笔者在之前的工作中,有客户提出想一次性查看Azure订阅下的所有Azure VM的Public IP和Private IP. ...

  5. Azure PowerShell (12) 通过Azure PowerShell创建SSH登录的Linux VM

    <Windows Azure Platform 系列文章目录> 本章将介绍如何使用Azure PowerShell,创建SSH登录的Linux VM 前提要求: 1.安装Azure Pow ...

  6. 【Azure Developer】调用SDK的runPowerShellScript方法,在Azure VM中执行PowerShell脚本示例

    当需要通过代码的方式执行PowerShell脚本时,可以参考以下的示例. Azure SDK中提供了两个方法来执行PowerShell脚本 (SDK Source Code: https://gith ...

  7. Azure按订阅,资源组,资源类型导出所有资源powershell命令

    一般可以借助powershell命令来读取资源:例如:1, 读取某个订阅下的资源:$subscriptionID = "xxxxxxxx"Set-AzureRmContext $s ...

  8. 在 Azure VM 中使用应用商店映像创建 HPC Pack 群集的头节点

    使用 Azure 应用商店和 Azure 门户中的 Microsoft HPC Pack 2012 R2 虚拟机映像创建 HPC 群集的头节点. 此 HPC Pack VM 映像基于预安装了 HPC ...

  9. 通过Python查看Azure VM的状态

    Azure的管理平台采用Restful API的方式实现管理.比如获取VM的管理API的各种操作的文档请参考: https://docs.microsoft.com/en-us/rest/api/co ...

随机推荐

  1. spark学习4(zookeeper3.4集群搭建)

    第一步:zookeeper安装 通过WinSCP软件将zookeeper-3.4.8.tar.gz软件传送到/usr/zookeeper/目录下 [root@spark1 zookeeper]# ch ...

  2. java基础(8)-集合类

    增强for循环 /* *增强for循环 * for(元素类型 变量:数据或Collection集合){ * 使用变量即可,该变量就是元素 * } * 优点:简化了数组和集合的遍历 * 缺点:增强for ...

  3. Linux嵌入式 -- 内核 - 内核链表

    1. linux内核链表 链表数据结构的定义: struct list_head  {  struct list_head *next, *prev;  };  list_head结构包含两个指向li ...

  4. Android 6.0运行时权限第三方库的使用-----RxPermissions

    运行时权限的讲解在前一篇博客已经算是说的比较清楚了,这里就不说了,如果对6.0这个新特性不是很了解的朋友建议先看看(地址:http://blog.csdn.net/qq_33923079/articl ...

  5. tensorflow笔记:流程,概念和简单代码注释

    tensorflow是google在2015年开源的深度学习框架,可以很方便的检验算法效果.这两天看了看官方的tutorial,极客学院的文档,以及综合tensorflow的源码,把自己的心得整理了一 ...

  6. Mac下git安装(使用Xcode)

    (不使用Xcode的出门右转百度其他方法:比如直接安装git软件包.) 一.AppStore 最安全途径:搜索下载Xcode,(需要AppleID). 其他:直接百度Xcode下载. 二.Xcode ...

  7. Sharded数据分片定位数据

    [http://www.tuicool.com/articles/UNnqUnU] Jedis分片 动机 在普通的Redis主/从方式,通常有一个主服务器负责"write"请求,多 ...

  8. 2017-02-20 安装Sql Server2016+配置Java环境

    昨天在安装Sql Server 2016时,在前面的规则检查结果中,出现“Polybase要求安装Oracle JRE7更新51(64位)或更高版本”规则失败的错误,如图 解决方案为,下载安装jdk, ...

  9. MySQL 索引的知识整理

    前言:       很多面试者,在面试的时候,都会回答,”索引就相当于一本书的字典,有了他能够很快的找到数据”, 这种答案好像在读书的时候老师告诉这么说的吧.今天来全面的描述一下数据库索引的原理及优化 ...

  10. Windows 10 Certified with Oracle E-Business Suite

    Microsoft Windows 10 (32-bit and 64-bit) is certified as a desktop client operating system for end-u ...