Aracılığıyla paylaş


Hızlı Başlangıç: ARM şablonu kullanarak Azure genel MEC'de sanal makine dağıtma

Bu hızlı başlangıçta, Azure genel çoklu erişimli uç işlem (MEC) içinde bir Ubuntu Linux sanal makinesi (VM) dağıtmak için Azure Resource Manager (ARM) şablonunu kullanmayı öğreneceksiniz.

Azure Resource Manager şablonu, projenizin altyapısını ve yapılandırmasını tanımlayan bir JavaScript Nesne Gösterimi (JSON) dosyasıdır. Bu şablonda, bildirim temelli sözdizimi kullanılır. Dağıtımı oluşturmak için programlama komutlarının sırasını yazmadan hedeflenen dağıtımınızı açıklarsınız.

Önkoşullar

  • Azure aboneliğiniz yoksa başlamadan önce ücretsiz bir hesap oluşturun.

  • Azure hesabınıza azure genel MEC'de kaynak dağıtmanıza olanak tanıyan izin verilenler listesine alınmış bir abonelik ekleyin. Etkin bir izin verilen aboneliğiniz yoksa Azure genel MEC ürün ekibine başvurun.

  • Azure Cloud Shell'de Bash ortamını kullanın. Daha fazla bilgi için bkz . Azure Cloud Shell'de Bash için hızlı başlangıç.

  • CLI başvuru komutlarını yerel olarak çalıştırmayı tercih ediyorsanız Azure CLI'yı yükleyin . Windows veya macOS üzerinde çalışıyorsanız Azure CLI’yi bir Docker kapsayıcısında çalıştırmayı değerlendirin. Daha fazla bilgi için bkz . Docker kapsayıcısında Azure CLI'yi çalıştırma.

    • Yerel yükleme kullanıyorsanız az login komutunu kullanarak Azure CLI ile oturum açın. Kimlik doğrulama işlemini tamamlamak için terminalinizde görüntülenen adımları izleyin. Diğer oturum açma seçenekleri için bkz . Azure CLI ile oturum açma.

    • İstendiğinde, ilk kullanımda Azure CLI uzantısını yükleyin. Uzantılar hakkında daha fazla bilgi için bkz. Azure CLI ile uzantıları kullanma.

    • Yüklü sürümü ve bağımlı kitaplıkları bulmak için az version komutunu çalıştırın. En son sürüme yükseltmek için az upgrade komutunu çalıştırın.

Not

Azure genel MEC dağıtımları, Azure CLI 2.26 ve sonraki sürümlerinde desteklenir.

Şablonu gözden geçirme

  1. Aşağıdaki örnek ARM şablonunu gözden geçirin.

    Azure genel MEC'de dağıttığınız her kaynağın, Azure'ın kaynak sağlayıcısına eklediği adlı extendedLocationek bir özniteliği vardır. Örnek ARM şablonu şu kaynakları dağıtır:

    • Sanal ağ
    • Genel IP adresi
    • Ağ arabirimi
    • Ağ güvenlik grubu
    • Sanal makine

    Bu örnekte ARM şablonu:

    • Azure Edge Bölge Kimliği, Azure genel MEC'nin görünen adından farklıdır.
    • Azure ağ güvenlik grubunun her yerden SSH ve HTTPS erişimine izin veren bir gelen kuralı vardır.
    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "adminUsername": {
                "type": "String",
                "metadata": {
                    "description": "Username for the Virtual Machine."
                }
            },
            "adminPassword": {
                "type": "SecureString",
                "metadata": {
                    "description": "Password for the Virtual Machine."
                }
            },
            "dnsLabelPrefix": {
                "type": "String",
                "metadata": {
                    "description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
                }
            },
            "vmSize": {
                "defaultValue": "Standard_D2s_v3",
                "type": "String",
                "metadata": {
                    "description": "Size of the virtual machine."
                }
            },
            "location": {
                "defaultValue": "[resourceGroup().location]",
                "type": "String",
                "metadata": {
                    "description": "Location for all resources."
                }
            },
            "EdgeZone": {
                "type": "String"
            },
            "publisher": { 
                "type": "string", 
                "defaultValue": "Canonical",
                "metadata" : {
                    "description": "Publisher for the VM Image"
                }
            }, 
            "offer": { 
                "type": "string",
                "defaultValue": "UbuntuServer",
                "metadata" : {
                    "description": "Offer for the VM Image"
                }
            }, 
            "sku": { 
                "type": "string",
                "defaultValue": "18.04-LTS",
                "metadata" : {
                    "description": "SKU for the VM Image"
                }
            }, 
            "osVersion": { 
                "type": "string",
                "defaultValue": "latest",
                "metadata" : {
                    "description": "version for the VM Image"
                }
            },
            "vmName": {
                "defaultValue": "myEdgeVM",
                "type": "String",
                "metadata": {
                    "description": "VM Name."
                }
            }
        },
        "variables": {
            "nicName": "myEdgeVMNic",
            "addressPrefix": "10.0.0.0/16",
            "subnetName": "Subnet",
            "subnetPrefix": "10.0.0.0/24",
            "publicIPAddressName": "myEdgePublicIP",
            "virtualNetworkName": "MyEdgeVNET",
            "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]",
            "networkSecurityGroupName": "default-NSG"
        },
        "resources": [
            {
                "type": "Microsoft.Network/publicIPAddresses",
                "apiVersion": "2018-11-01",
                "name": "[variables('publicIPAddressName')]",
                "location": "[parameters('location')]",
                "extendedLocation": {
                    "type": "EdgeZone",
                    "name": "[parameters('EdgeZone')]"
                },
                "sku": {
                    "name": "Standard"
                },
                "properties": {
                    "publicIPAllocationMethod": "Static",
                    "dnsSettings": {
                        "domainNameLabel": "[parameters('dnsLabelPrefix')]"
                    }
                }
            },
            {
                "type": "Microsoft.Network/networkSecurityGroups",
                "apiVersion": "2019-08-01",
                "name": "[variables('networkSecurityGroupName')]",
                "location": "[parameters('location')]",
                "properties": {
                    "securityRules": [
                       {
                            "name": "AllowHttps",
                            "properties": {
                                "description": "HTTPS is allowed",
                                "protocol": "*",
                                "sourcePortRange": "*",
                                "destinationPortRange": "443",
                                "sourceAddressPrefix": "*",
                                "destinationAddressPrefix": "*",
                                "access": "Allow",
                                "priority": 130,
                                "direction": "Inbound",
                                "sourcePortRanges": [],
                                "destinationPortRanges": [],
                                "sourceAddressPrefixes": [],
                                "destinationAddressPrefixes": []
                             }
                        },
                        { 
                            "name": "AllowSSH",
                            "properties": {
                                "description": "HTTPS is allowed",
                                "protocol": "*",
                                "sourcePortRange": "*",
                                "destinationPortRange": "22",
                                "sourceAddressPrefix": "*",
                                "destinationAddressPrefix": "*",
                                "access": "Allow",
                                "priority": 140,
                                "direction": "Inbound",
                                "sourcePortRanges": [],
                                "destinationPortRanges": [],
                                "sourceAddressPrefixes": [],
                                "destinationAddressPrefixes": []
                             }
                        }
                    ]
                }
            },
            {
                "type": "Microsoft.Network/virtualNetworks",
                "apiVersion": "2018-11-01",
                "name": "[variables('virtualNetworkName')]",
                "location": "[parameters('location')]",
                "extendedLocation": {
                    "type": "EdgeZone",
                    "name": "[parameters('EdgeZone')]"
                },
                "dependsOn": [
                    "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                ],
                "properties": {
                    "addressSpace": {
                        "addressPrefixes": [
                            "[variables('addressPrefix')]"
                        ]
                    },
                    "subnets": [
                        {
                            "name": "[variables('subnetName')]",
                            "properties": {
                                "addressPrefix": "[variables('subnetPrefix')]",
                                "networkSecurityGroup": {
                                    "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                                 }
                            }
                        }
                    ]
                }
            },
            {
                "type": "Microsoft.Network/networkInterfaces",
                "apiVersion": "2018-11-01",
                "name": "[variables('nicName')]",
                "location": "[parameters('location')]",
                "extendedLocation": {
                    "type": "EdgeZone",
                    "name": "[parameters('EdgeZone')]"
                },
                "dependsOn": [
                    "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
                    "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
                ],
                "properties": {
                    "ipConfigurations": [
                        {
                            "name": "ipconfig1",
                            "properties": {
                                "privateIPAllocationMethod": "Dynamic",
                                "publicIPAddress": {
                                    "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
                                },
                                "subnet": {
                                    "id": "[variables('subnetRef')]"
                                }
                            }
                        }
                    ]
                }
            },
            {
                "type": "Microsoft.Compute/virtualMachines",
                "apiVersion": "2020-06-01",
                "name": "[parameters('vmName')]",
                "location": "[parameters('location')]",
                "extendedLocation": {
                    "type": "EdgeZone",
                    "name": "[parameters('EdgeZone')]"
                },
                "dependsOn": [
                    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
                ],
                "properties": {
                    "hardwareProfile": {
                        "vmSize": "[parameters('vmSize')]"
                    },
                    "osProfile": {
                        "computerName": "[parameters('vmName')]",
                        "adminUsername": "[parameters('adminUsername')]",
                        "adminPassword": "[parameters('adminPassword')]"
                    },
                    "storageProfile": {
                        "imageReference": {
                            "publisher": "[parameters('publisher')]",
                            "offer": "[parameters('offer')]",
                            "sku": "[parameters('sku')]",
                            "version": "[parameters('osVersion')]"
                        },
                        "osDisk": {
                            "createOption": "FromImage",
                            "managedDisk": {
                                "storageAccountType": "StandardSSD_LRS"
                            }
                        }
                    },
                    "networkProfile": {
                        "networkInterfaces": [
                            {
                                "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]"
                            }
                        ]
                    }
                }
            }
        ],
        "outputs": {
            "hostname": {
                "type": "String",
                "value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"
            },
            "sshCommand": {
                "type": "string",
                "value": "[format('ssh {0}@{1}', parameters('adminUsername'), reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))).dnsSettings.fqdn)]"
            }
        }
    }
    

Azure CLI kullanarak ARM şablonunu dağıtma

  1. Önceki bölümde yer alan örnek ARM şablonunun içeriğini azurepublicmecDeploy.json adlı bir dosyaya kaydedin.

  2. az login ile Azure'da oturum açın ve az account set komutuyla Azure aboneliğini ayarlayın .

    az login                                
    az account set --subscription <subscription name>
    
  3. az group create komutuyla bir Azure kaynak grubu oluşturun. Kaynak grubu, Azure kaynaklarının dağıtıldığı ve yönetildiği bir mantıksal kapsayıcıdır. Aşağıdaki örnek myResourceGroup adlı bir kaynak grubu oluşturur:

    az group create --name myResourceGroup --location <location>
    

    Not

    Her Azure genel MEC sitesi bir Azure bölgesiyle ilişkilendirilir. Kaynağın dağıtılması gereken Azure genel MEC konumuna bağlı olarak, parametresi için --location uygun bölge değerini seçin. Daha fazla bilgi için bkz . Azure genel MEC için temel kavramlar.

  4. ARM şablonunu az deployment group create komutuyla kaynak grubuna dağıtın.

    az deployment group create --resource-group myResourceGroup --template-file azurepublicmecDeploy.json
    
    Please provide string value for 'adminUsername' (? for help): <username>
    Please provide securestring value for 'adminPassword' (? for help): <password>
    Please provide string value for 'dnsLabelPrefix' (? for help): <uniqueDnsLabel>
    Please provide string value for 'EdgeZone' (? for help): <edge zone ID>
    
  5. Dağıtımın çalışması için birkaç dakika bekleyin.

    Komut yürütme tamamlandıktan sonra myResourceGroup kaynak grubunda yeni kaynakları görebilirsiniz. Aşağıda örnek bir çıkış verilmişti:

    { 
    "id": "/subscriptions/xxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Resources/deployments/edgeZonesDeploy",
      "location": null,
      "name": "edgeZonesDeploy",
      "properties": {
        "correlationId": "<xxxxxxxx>",
        "debugSetting": null,
        "dependencies": [
          {
            "dependsOn": [
              {
                "id": "/subscriptions/xxxxx/resourceGroups/myResourceGroup /providers/Microsoft.Network/networkSecurityGroups/default-NSG",
                "resourceGroup": " myResourceGroup ",
                "resourceName": "default-NSG",
                "resourceType": "Microsoft.Network/networkSecurityGroups"
              }
            ],
            "id": "/subscriptions/xxxxxx/resourceGroups/ myResourceGroup /providers/Microsoft.Network/virtualNetworks/MyEdgeTestVnet",
            "resourceGroup": " myResourceGroup ",
            "resourceName": " MyEdgeTestVnet ",
            "resourceType": "Microsoft.Network/virtualNetworks"
          },
     "outputs": {
          "hostname": {
            "type": "String",
            "value": "xxxxx.cloudapp.azure.com"
          },
          "sshCommand": {
            "type": "String",
            "value": "ssh <adminUsername>@<publicIPFQDN>"
          }
        },
    ...
    }
    

Sanal makineye erişme

Azure genel MEC'deki sanal makineye bağlanmak için SSH kullanmak için en iyi yöntem, Azure üst bölgesinde bir atlama kutusu dağıtmaktır.

  1. Bölgede sanal makine oluşturma başlığındaki yönergeleri izleyin.

  2. Bölgede dağıtılan atlama kutusu sanal makinesine bağlanmak için SSH kullanın.

    ssh <username>@<regionVM_publicIP>
    
  3. Atlama kutusundan SSH kullanarak Azure genel MEC'de oluşturulan sanal makineye bağlanın.

    ssh <username>@<edgezoneVM_publicIP>
    

Kaynakları temizleme

Bu hızlı başlangıçta, Azure CLI kullanarak Azure genel MEC'de bir ARM şablonu dağıttınız. Gelecekte bu kaynaklara ihtiyaç duymayı beklemiyorsanız az group delete komutunu kullanarak kaynak grubunu, ölçek kümesini ve tüm ilgili kaynakları kaldırın. parametresi kullanıldığında --yes , onay istemi olmadan kaynaklar silinir.

az group delete \--name myResourceGroup \--yes

Sonraki adımlar

Azure CLI kullanarak Azure genel MEC'de bir sanal makine dağıtmak için aşağıdaki makaleye ilerleyin: