用 Json Template 在 Azure 上創(chuàng)建 Cisco CSR 路由器

魏衡,微軟云資深架構(gòu)師,國內(nèi)Azure最早的架構(gòu)師之一

Azure的ARM(Azure資源管理器)模式可以通過Json的模板創(chuàng)建VM(虛擬機)。本文以Cisco的CSR的image為例,介紹如何用Json創(chuàng)建VM。

一、Cisco CSR的Image

首先把Cisco CSR的image復(fù)制到一個存儲賬戶中:

https://xxxx.blob.core.chinacloudapi.cn/image/CSR_3_16_4aS_CCO.vhd

創(chuàng)建VM的vhd文件也需要在這個存儲賬戶中。

二、獲得Json模板

在Github上找到From user image create VM的Json模板:

https://github.com/Azure/azure-quickstart-templates/tree/master/101-vm-from-user-image

把azuredeploy.json文件保存到本地:

https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-from-user-image/azuredeploy.json

為d:\from_image.json文件。由于Global Azure的Disk目前已經(jīng)prefer使用Management Disk了,Github上的template已經(jīng)改成MD的template。

下面是采用普通存儲賬戶的Json Template:

{

"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"customVmName": {

"type": "string",

"metadata": {

"description": "This is the name of the your VM"

}

},

"userImageStorageAccountName": {

"type": "string",

"metadata": {

"description": "This is the name of the your storage account"

}

},

"userImageStorageAccountResourceGroupName": {

"type": "string",

"metadata": {

"description": "Resource group of the existing storage account"

}

},

"osDiskVhdUri": {

"type": "string",

"metadata": {

"description": "Uri of the your user image"

}

},

"dnsLabelPrefix": {

"type": "string",

"metadata": {

"description": "DNS Label for the Public IP. Must be lowercase. It should match with the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$ or it will raise an error."

}

},

"adminUserName": {

"type": "string",

"metadata": {

"description": "User Name for the Virtual Machine"

}

},

"adminPassword": {

"type": "securestring",

"metadata": {

"description": "Password for the Virtual Machine"

}

},

"osType": {

"type": "string",

"allowedValues": [

"Windows",

"Linux"

],

"metadata": {

"description": "This is the OS that your VM will be running"

}

},

"vmSize": {

"type": "string",

"metadata": {

"description": "This is the size of your VM"

}

},

"newOrExistingVnet": {

"allowedValues": [ "new", "existing" ],

"type": "string",

"metadata": {

"description":? "Select if this template needs a new VNet or will reference an existing VNet"

}

},

"newOrExistingVnetName": {

"type": "string",

"defaultValue": "",

"metadata": {

"description": "New or Existing VNet Name"

}

},

"newOrExistingSubnetName": {

"type": "string",

"metadata": {

"description": "New or Existing subnet Name"

}

},

"existingVnetResourceGroupName": {

"type": "string",

"metadata": {

"description": "Resource group of the existing VNET"

}

}

},

"variables": {

"publicIPAddressName": "[concat(parameters('customVmName'),'IP')]",

"vmName": "[parameters('customVmName')]",

"nicName": "[concat(parameters('customVmName'),'Nic')]",

"publicIPAddressType": "Dynamic",

"apiVersion": "2015-06-15",

"templatelink": "[concat('https://raw.githubusercontent.com/singhkay/azure-quickstart-templates/master/101-vm-from-user-image/',parameters('newOrExistingVnet'),'vnet.json')]"

},

"resources": [

{

"apiVersion": "2015-01-01",

"name": "vnet-template",

"type": "Microsoft.Resources/deployments",

"properties": {

"mode": "incremental",

"templateLink": {

"uri": "[variables('templatelink')]",

"contentVersion": "1.0.0.0"

},

"parameters": {

"virtualNetworkName": {

"value": "[parameters('newOrExistingVnetName')]"

},

"subnetName": {

"value": "[parameters('newOrExistingSubnetName')]"

},

"existingVnetResourceGroupName": {

"value": "[parameters('existingVnetResourceGroupName')]"

}

}

}

},

{

"apiVersion": "[variables('apiVersion')]",

"type": "Microsoft.Network/publicIPAddresses",

"name": "[variables('publicIPAddressName')]",

"location": "[resourceGroup().location]",

"properties": {

"publicIPAllocationMethod": "[variables('publicIPAddressType')]",

"dnsSettings": {

"domainNameLabel": "[parameters('dnsLabelPrefix')]"

}

}

},

{

"apiVersion": "2016-03-30",

"type": "Microsoft.Network/networkInterfaces",

"name": "[variables('nicName')]",

"location": "[resourceGroup().location]",

"dependsOn": [

"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",

"Microsoft.Resources/deployments/vnet-template"

],

"properties": {

"ipConfigurations": [

{

"name": "ipconfig1",

"properties": {

"privateIPAllocationMethod": "Dynamic",

"publicIPAddress": {

"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"

},

"subnet": {

"id": "[reference('vnet-template').outputs.subnet1Ref.value]"

}

}

}

]

}

},

{

"apiVersion": "[variables('apiVersion')]",

"type": "Microsoft.Compute/virtualMachines",

"name": "[variables('vmName')]",

"location": "[resourceGroup().location]",

"dependsOn": [

"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]"

],

"properties": {

"hardwareProfile": {

"vmSize": "[parameters('vmSize')]"

},

"osProfile": {

"computerName": "[variables('vmName')]",

"adminUsername": "[parameters('adminUsername')]",

"adminPassword": "[parameters('adminPassword')]"

},

"storageProfile": {

"osDisk": {

"name": "[concat(variables('vmName'),'-osDisk')]",

"osType": "[parameters('osType')]",

"caching": "ReadWrite",

"createOption": "FromImage",

"image": {

"uri": "[parameters('osDiskVhdUri')]"

},

"vhd": {

"uri": "[concat(reference(resourceId(parameters('userImageStorageAccountResourceGroupName'), 'Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob, 'vhds/',variables('vmName'), uniquestring(resourceGroup().id), 'osDisk.vhd')]"

}

}

},

"networkProfile": {

"networkInterfaces": [

{

"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"

}

]

},

"diagnosticsProfile": {

"bootDiagnostics": {

"enabled": "true",

"storageUri": "[concat(reference(resourceId(parameters('userImageStorageAccountResourceGroupName'), 'Microsoft.Storage/storageAccounts/', parameters('userImageStorageAccountName')), variables('apiVersion')).primaryEndpoints.blob)]"

}

}

}

}

]

}

三、通過模板創(chuàng)建Cisco CSR虛擬機

登錄Azure 門戶;

在New中搜索template;



如上圖所示,點擊Template Deployment。這里需要注意的是,目前必須是英文版本才可以使用這個功能。

導(dǎo)入template;



把剛剛的Json Template上傳。

填寫相應(yīng)的Parameters;



根據(jù)實際值,填寫相應(yīng)的參數(shù)。需要注意的是Resource Group和Storage Account都要和image所在的Storage Account相同。

Legal Terms;

把Legal Terms相應(yīng)的內(nèi)容填寫完整:



然后點擊create,創(chuàng)建VM。

四、登錄創(chuàng)建的Cisco CSR router;

Connecting to 42.159.203.233:22...

Connection established.

To escape to local shell, press Ctrl+Alt+].

hengweicisco#sh runn

Building configuration...

Current configuration : 1294 bytes

!

! Last configuration change at 10:21:56 UTC Mon Apr 24 2017

!

version 15.5

service timestamps debug datetime msec

service timestamps log datetime msec

no platform punt-keepalive disable-kernel-core

platform console virtual

!

hostname hengweicisco

!

boot-start-marker

boot-end-marker

!

logging persistent size 1000000 filesize 8192 immediate

!

aaa new-model

!

aaa authentication login default local

aaa authorization exec default local none

!

aaa session-id common

光看云社區(qū)未使用 Azure?

申請試用

標簽

公告 (159)

虛擬機 (70)

解決方案 (69)

云服務(wù) (62)

存儲 (57)

網(wǎng)站 (53)

常見問題 (50)

SQL 數(shù)據(jù)庫 (45)

Windows Azure 開源解決方案 (25)

服務(wù)總線 (24)

Active Directory (24)

媒體服務(wù) (18)

虛擬網(wǎng)絡(luò) (12)

移動服務(wù) (12)

HDInsight (11)

備份 (9)

Azure (7)

網(wǎng)絡(luò)服務(wù) (7)

站點恢復(fù) (7)

CDN (6)

流量管理器 (6)

MySQL Database on Azure (4)

VPN (2)

blob (2)

DocumentDB (2)

Azure VMSS (2)

Microsoft R Server (2)

SQL (2)

ARM (2)

Azure SQL (2)

數(shù)據(jù)庫 (2)

物聯(lián)網(wǎng) (2)

FreeBSD (2)

計費 (2)

Azure 分析服務(wù) (1)

Azure SQL DataBase (1)

SQL Server (1)

數(shù)據(jù)科學(xué)虛擬機鏡像 (1)

Visual Studio 2017 虛擬機鏡像 (1)

SQL 2017,Azure SQL (1)

共享目錄 (1)

SQL On Linux (1)

SQL2016,security (1)

數(shù)據(jù)庫權(quán)限,分配 (1)

NSC (1)

Ubuntu Docker,SQL Server (1)

BGP (1)

Azure Linux Disk (1)

Powershell (1)

cache (1)

Json Template (1)

Cisco CSR (1)

Azure ARM (1)

VNet (1)

Storm (1)

HBASE (1)

事件中心 (1)

流處理 (1)

Storm,HBASE,事件中心,流處理 (1)

Azure Python SDK (1)

Azure IoT 中心服務(wù),根證書 (1)

Azure Cosmos DB (1)

VMSS (1)

Microsoft R Server (1)

事件中心捕獲 (1)

performance optimization (1)

自定義鏡像 (1)

private disk (1)

Vnet (1)

OnPrem (1)

logic server (1)

Infrastructure (1)

auto deployment (1)

站點,訪問,實踐 (1)

Azure Portal (1)

Azure Resource Template (1)

private storage (1)

AAD (1)

ACS (1)

遷移 (1)

兼容性 (1)

SQL數(shù)據(jù)庫 (1)

AzureSQL (1)

初級 (1)

Visual Studio (1)

SQL Server (1)

PaaS (1)

HTTPS自有證書 (1)

域名管理 (1)

證書部署 (1)

云計算 (1)

AzureStorage (1)

azure-availability (1)

azure-networking1 (1)

IoT 中心 (1)

IoT Suite (1)

VM (1)

CDN Smart Routing (1)

BSD (1)

AppleTV (1)

Apple FairPlay (1)

Azure Stack (1)

Azure云助手 (1)

Cloud Foundry (1)

虛擬機 (1)

PowerShell (1)

移動終端 (1)

服務(wù)儀表盤 (1)

立即訪問http://market.azure.cn

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容