Öğretici için yazılım yükleme ve kaynakları ayarlama

Önemli

Azure SQL Edge artık ARM64 platformunu desteklememektedir.

Bu üç bölümden oluşan öğreticide silika yüzdesi olarak demir ceylen safsızlıklarını tahmin etmek için bir makine öğrenmesi modeli oluşturacak ve ardından modeli Azure SQL Edge'de dağıtacaksınız. Birinci bölümde gerekli yazılımları yükleyecek ve Azure kaynaklarını dağıtacaksınız.

Ön koşullar

  1. Azure aboneliğiniz yoksa ücretsiz bir hesap oluşturun.
  2. Visual Studio 2019'u ile yükleme
    • Azure IoT Edge araçları
    • .NET Core platformlar arası geliştirme
    • Kapsayıcı geliştirme araçları
  3. Azure Data Studio'yu yükleme
  4. Azure Data Studio'yu açın ve not defterleri için Python'ı yapılandırın. Ayrıntılar için bkz . Not Defterleri için Python'ı yapılandırma. Bu adım birkaç dakika sürebilir.
  5. Azure CLI'nın en son sürümünü yükleyin. Aşağıdaki betikler, AZ PowerShell'in en son sürüm (3.5.0, Şubat 2020) olmasını gerektirir.
  6. Azure IoT EdgeHub Geliştirme Aracı'nı yükleyerek IoT Edge çözümünün hatalarını ayıklamak, çalıştırmak ve test etmek için ortamı ayarlayın.
  7. Docker'ı yükleyin.

PowerShell Betiği kullanarak Azure kaynaklarını dağıtma

Bu Azure SQL Edge öğreticisi için gereken Azure kaynaklarını dağıtın. Bu kaynaklar bir PowerShell betiği kullanılarak veya Azure portalı aracılığıyla dağıtılabilir. Bu öğreticide bir PowerShell betiği kullanılır.

Dekont

Bu makalede Azure IoT uzantısının adlı azure-ioten yeni sürümü kullanılır. Eski sürüm olarak adlandırılır azure-cli-iot-ext. Bir kerede yalnızca bir sürümünüz yüklü olmalıdır. Şu anda yüklü olan uzantıları doğrulamak için komutunu az extension list kullanabilirsiniz.

Uzantının eski sürümünü kaldırmak için kullanın az extension remove --name azure-cli-iot-ext .

Uzantının yeni sürümünü eklemek için kullanın az extension add --name azure-iot .

Hangi uzantıları yüklediğinizi görmek için kullanın az extension list.

  1. Bu öğreticide PowerShell betiğini çalıştırmak için gereken modülleri içeri aktarın.

    Import-Module Az.Accounts -RequiredVersion 1.7.3
    Import-Module -Name Az -RequiredVersion 3.5.0
    Import-Module Az.IotHub -RequiredVersion 2.1.0
    Import-Module Az.Compute -RequiredVersion 3.5.0
    az extension add --name azure-iot
    az extension add --name azure-cli-ml
    
  2. PowerShell betiğinin gerektirdiği değişkenleri bildirin.

    $ResourceGroup = "<name_of_the_resource_group>"
    $IoTHubName = "<name_of_the_IoT_hub>"
    $location = "<location_of_your_Azure_Subscription>"
    $SubscriptionName = "<your_azure_subscription>"
    $NetworkSecGroup = "<name_of_your_network_security_group>"
    $StorageAccountName = "<name_of_your_storage_account>"
    
  3. Değişkenlerin geri kalanını bildirin.

    $IoTHubSkuName = "S1"
    $IoTHubUnits = 4
    $EdgeDeviceId = "IronOrePredictionDevice"
    $publicIpName = "VMPublicIP"
    $imageOffer = "iot_edge_vm_ubuntu"
    $imagePublisher = "microsoft_iot_edge"
    $imageSku = "ubuntu_1604_edgeruntimeonly"
    $AdminAcc = "iotadmin"
    $AdminPassword = ConvertTo-SecureString "IoTAdmin@1234" -AsPlainText -Force
    $VMSize = "Standard_DS3"
    $NetworkName = "MyNet"
    $NICName = "MyNIC"
    $SubnetName = "MySubnet"
    $SubnetAddressPrefix = "10.0.0.0/24"
    $VnetAddressPrefix = "10.0.0.0/16"
    $MyWorkSpace = "SQLDatabaseEdgeDemo"
    $containerRegistryName = $ResourceGroup + "ContRegistry"
    
  4. Varlık oluşturmaya başlamak için Azure'da oturum açın.

    Login-AzAccount
    
    az login
    
  5. Azure abonelik kimliğini ayarlayın.

    Select-AzSubscription -Subscription $SubscriptionName
    az account set --subscription $SubscriptionName
    
  6. Henüz yoksa kaynak grubunu oluşturun.

    $rg = Get-AzResourceGroup -Name $ResourceGroup
    if($rg -eq $null)
    {
        Write-Output("Resource Group $ResourceGroup does not exist, creating Resource Gorup")
        New-AzResourceGroup -Name $ResourceGroup -Location $location
    }
    else
    {
        Write-Output ("Resource Group $ResourceGroup exists")
    }
    
  7. Kaynak grubunda depolama hesabı ve depolama hesabı kapsayıcısı oluşturun.

    $sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
    if ($sa -eq $null)
    {
        New-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName -SkuName Standard_LRS -Location $location -Kind Storage
        $sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
        $storageKey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroup -Name $StorageAccountName
        $storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey[0].Value
        New-AzStorageContainer -Name "sqldatabasedacpac" -Context $storageContext
    }
    else
    {
       Write-Output ("Storage Account $StorageAccountName exists in Resource Group $ResourceGroup")
    }
    
  8. Veritabanı dacpac dosyasını depolama hesabına yükleyin ve blob için bir SAS URL'si oluşturun. Veritabanı dacpac blobu için SAS URL'sini not edin.

    $file = Read-Host "Please Enter the location to the zipped Database DacPac file:"
    Set-AzStorageBlobContent -File $file -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context
    $DacpacFileSASURL = New-AzStorageBlobSASToken -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context -Permission r -StartTime (Get-Date).DateTime -ExpiryTime (Get-Date).AddMonths(12) -FullUri
    
  9. Bu kaynak grubu içinde bir Azure kapsayıcı kayıt defteri oluşturun.

    $containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
    if ($containerRegistry -eq $null)
    {
        New-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName -Sku Standard -Location $location -EnableAdminUser
        $containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
    }
    else
    {
        Write-Output ("Container Registry $containerRegistryName exists in Resource Group $ResourceGroup")
    }
    
  10. Kaynak grubu içinde ağ güvenlik grubunu oluşturun.

    $nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
    if($nsg -eq $null)
    {
        Write-Output("Network Security Group $NetworkSecGroup does not exist in the resource group $ResourceGroup")
    
        $rule1 = New-AzNetworkSecurityRuleConfig -Name "SSH" -Description "Allow SSH" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 22
        $rule2 = New-AzNetworkSecurityRuleConfig -Name "SQL" -Description "Allow SQL" -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 1600
        New-AzNetworkSecurityGroup -Name $NetworkSecGroup -ResourceGroupName $ResourceGroup -Location $location -SecurityRules $rule1, $rule2
    
        $nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
    }
    else
    {
        Write-Output ("Network Security Group $NetworkSecGroup exists in the resource group $ResourceGroup")
    }
    
  11. SQL Edge ile etkinleştirilmiş bir Azure sanal makinesi oluşturun. Bu VM bir Edge cihazı işlevi görür.

    $AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
    If($AzVM -eq $null)
    {
        Write-Output("The Azure VM with Name- $EdgeVMName is not present in the Resource Group- $ResourceGroup ")
    
        $SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
        $Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroup -Location $location -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet
        $publicIp = New-AzPublicIpAddress -Name $publicIpName -ResourceGroupName $ResourceGroup -AllocationMethod Static -Location $location
        $NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup -Location $location -SubnetId $Vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -PublicIpAddressId $publicIp.Id
    
        ##Set-AzNetworkInterfaceIpConfig -Name "ipconfig1"  -NetworkInterface $NIC -PublicIpAddress $publicIp
    
        $Credential = New-Object System.Management.Automation.PSCredential ($AdminAcc, $AdminPassword);
    
        $VirtualMachine = New-AzVMConfig -VMName $EdgeDeviceId -VMSize $VMSize
        $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName $EdgeDeviceId -Credential $Credential
        $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
        $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $imagePublisher -Offer $imageOffer -Skus $imageSku -Version latest
        $VirtualMachine = Set-AzVMPlan -VM $VirtualMachine -Name $imageSku -Publisher $imagePublisher -Product $imageOffer
    
        $AzVM = New-AzVM -ResourceGroupName $ResourceGroup -Location $location -VM $VirtualMachine -Verbose
        $AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
    
    }
    else
    {
        Write-Output ("The Azure VM with Name- $EdgeDeviceId is present in the Resource Group- $ResourceGroup ")
    }
    
  12. Kaynak grubu içinde bir IoT hub'ı oluşturun.

    $iotHub = Get-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName
    If($iotHub -eq $null)
    {
        Write-Output("IoTHub $IoTHubName does not exists, creating The IoTHub in the resource group $ResourceGroup")
        New-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName -SkuName $IoTHubSkuName -Units $IoTHubUnits -Location $location -Verbose
    }
    else
    {
        Write-Output ("IoTHub $IoTHubName present in the resource group $ResourceGroup")
    }
    
  13. IoT hub'ına bir Edge cihazı ekleyin. Bu adım yalnızca cihaz dijital kimliğini oluşturur.

    $deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
    If($deviceIdentity -eq $null)
    {
        Write-Output("The Edge Device with DeviceId- $EdgeDeviceId is not registered to the IoTHub- $IoTHubName ")
        Add-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId -EdgeEnabled
    }
    else
    {
        Write-Output ("The Edge Device with DeviceId- $EdgeDeviceId is registered to the IoTHub- $IoTHubName")
    }
    $deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
    
  14. Daha sonra VM için gerekli olan cihaz birincil bağlantı dizesi alın. Aşağıdaki komut dağıtımlar için Azure CLI'yi kullanır.

    $deviceConnectionString = az iot hub device-identity connection-string show --device-id $EdgeDeviceId --hub-name $IoTHubName --resource-group $ResourceGroup --subscription $SubscriptionName
    $connString = $deviceConnectionString[1].Substring(23,$deviceConnectionString[1].Length-24)
    $connString
    
  15. Edge cihazındaki IoT Edge yapılandırma dosyasındaki bağlantı dizesi güncelleştirin. Aşağıdaki komutlar dağıtımlar için Azure CLI'yi kullanır.

    $script = "/etc/iotedge/configedge.sh '" + $connString + "'"
    az vm run-command invoke -g $ResourceGroup -n $EdgeDeviceId  --command-id RunShellScript --script $script
    
  16. Kaynak grubu içinde bir Azure Machine Learning çalışma alanı oluşturun.

    az ml workspace create -w $MyWorkSpace -g $ResourceGroup
    

Sonraki adımlar