How to clone a Azure VM

Standard

run on your sample-vm

waagent -deprovision+user

run on your azure-cli env

$rgName = "VMTestGroup"
$template = "Template-test.json"
$vmName = "VMTest"
$vhdName = "VHDTest"
 
azure vm deallocate -g $rgName -n $vmName
azure vm generalize $rgName -n $vmName
azure vm capture $rgName $vmName $vhdName -t $template
 
# the $template should looks like this. and you have to change 'newvmname' before use.
...
         "storageProfile": {
          "dataDisks": [
            {
              "caching": "ReadOnly",
              "vhd": {
                "uri": "https://yourdiskname.blob.core.windows.net/vhds/dataDisk-0.newvmname.vhd"
              },
              "image": {
                "uri": "https://yourdiskname.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/yourcapturedvmname-dataDisk-0.ff60129b-...3cf59bf9315a.vhd"
              },
              "createOption": "FromImage",
              "name": "yourcapturedvmname-dataDisk-0.ff60129b-4ec5-4dcd-ae97-3cf59bf9315a.vhd",
              "lun": 0
            }
          ],
          "osDisk": {
            "caching": "ReadWrite",
            "vhd": {
              "uri": "https://yourdiskname.blob.core.windows.net/vhds/osDisk.newvmname.vhd"
            },
            "image": {
              "uri": "https://yourdiskname.blob.core.windows.net/system/Microsoft.Compute/Images/vhds/yourcapturedvmname-osDisk.ff60129b-...3cf59bf9315a.vhd"
            },
            "createOption": "FromImage",
            "name": "yourcapturedvmname-osDisk.ff60129b-4ec5-4dcd-ae97-3cf59bf9315a.vhd",
            "osType": "Linux"
          }
        },
...
 
 
azure group deployment create $rgName MyDeployment -f Template-test-modified.json
    info:    Executing command group deployment create
    info:    Supply values for the following parameters
    vmName: NewVmName
    adminUserName: username
    adminPassword: password
    networkInterfaceId: /subscriptions/61719d1b-...ab74b6f77865/resourceGroups/VMTestGroup/providers/Microsoft.Network/networkInterfaces/YourNetworkInterfaceName
 
#If you do not have an existing NetworkInterface, you need create first. 
azure network nic create $rgName YourNetworkInterfaceName -k default -m YourSubnetVnetName  -l "westus2"

用Azure命令行配load balancer

Standard

https://azure.microsoft.com/en-us/documentation/articles/load-balancer-get-started-internet-arm-cli/
https://azure.microsoft.com/en-us/documentation/articles/load-balancer-get-started-ilb-arm-cli/
只是参照上面两篇敲一遍练练手.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
azure login
azure config mode arm
azure account set <Subscription ID>
 
azure group create ResourceGroupsName eastus2
 
azure network vnet create ResourceGroupsName ResourceGroupsName-Vnet eastus2 -a 10.0.0.0/16
azure network vnet subnet create ResourceGroupsName ResourceGroupsName-Vnet ResourceGroupsName-VnetSubnet -a 10.0.0.0/24
azure network public-ip create -g ResourceGroupsName -n ResourceGroupsName-PublicIP -l eastus2 -d rgn-esg -a static -i 4
azure network lb create ResourceGroupsName ResourceGroupsName-LB eastus2
azure network lb frontend-ip create ResourceGroupsName ResourceGroupsName-LB ResourceGroupsName-FrontendPool -i ResourceGroupsName-PublicIP
azure network lb address-pool create ResourceGroupsName ResourceGroupsName-LB ResourceGroupsName-BackendPool
 
azure network lb inbound-nat-rule create -g ResourceGroupsName -l ResourceGroupsName-LB -n ssh1 -p tcp -f 62201 -b 22
azure network lb inbound-nat-rule create -g ResourceGroupsName -l ResourceGroupsName-LB -n ssh2 -p tcp -f 62202 -b 22
 
azure network lb inbound-nat-rule create -g ResourceGroupsName -l ResourceGroupsName-LB -n ssh3 -p tcp -f 62203 -b 22
 
azure network lb rule create ResourceGroupsName ResourceGroupsName-LB lbrule -p tcp -f 9200 -b 9200 -t ResourceGroupsName-FrontendPool -o ResourceGroupsName-BackendPool
azure network lb probe create -g ResourceGroupsName -l ResourceGroupsName-LB -n healthprobe -p "http" -o 9200 -f / -i 15 -c 4
 
azure network lb show ResourceGroupsName ResourceGroupsName-LB
 
azure network nic create -g ResourceGroupsName -n lb-nic1-be --subnet-name ResourceGroupsName-VnetSubnet --subnet-vnet-name ResourceGroupsName-Vnet -d "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ResourceGroupsName/providers/Microsoft.Network/loadBalancers/ResourceGroupsName-LB/backendAddressPools/ResourceGroupsName-BackendPool" -e "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ResourceGroupsName/providers/Microsoft.Network/loadBalancers/ResourceGroupsName-LB/inboundNatRules/ssh1" eastus2
azure network nic create -g ResourceGroupsName -n lb-nic2-be --subnet-name ResourceGroupsName-VnetSubnet --subnet-vnet-name ResourceGroupsName-Vnet -d "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ResourceGroupsName/providers/Microsoft.Network/loadBalancers/ResourceGroupsName-LB/backendAddressPools/ResourceGroupsName-BackendPool" -e "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/ResourceGroupsName/providers/Microsoft.Network/loadBalancers/ResourceGroupsName-LB/inboundNatRules/ssh2" eastus2
 
azure vm create --resource-group ResourceGroupsName --name es1 --location eastus2 --vnet-name ResourceGroupsName-Vnet --vnet-subnet-name ResourceGroupsName-VnetSubnet --nic-name lb-nic1-be --availset-name ResourceGroupsName-AvSet --storage-account-name rgnesgdata -z Standard_D3_V2 --os-type Linux --image-urn Canonical:UbuntuServer:14.04.3-LTS:14.04.201512032
azure vm create --resource-group ResourceGroupsName --name es2 --location eastus2 --vnet-name ResourceGroupsName-Vnet --vnet-subnet-name ResourceGroupsName-VnetSubnet --nic-name lb-nic2-be --availset-name ResourceGroupsName-AvSet --storage-account-name rgnesgdata -z Standard_D3_V2 --os-type Linux --image-urn Canonical:UbuntuServer:14.04.3-LTS:14.04.201512032