Skip to content

Commit 63b2665

Browse files
SQL Edge- Added tutroial to be released for Build
1 parent 1b882c8 commit 63b2665

File tree

5 files changed

+548
-395
lines changed

5 files changed

+548
-395
lines changed
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
---
2+
title: Set up resources and software for the tutorial
3+
description: In this section, we will install pre-requisite software and set up required Azure resources for the tutorial
4+
keywords:
5+
services: sql-database-edge
6+
ms.service: sql-database-edge
7+
ms.topic: conceptual
8+
author: VasiyaKrishnan
9+
ms.author: vakrishn
10+
ms.reviewer: sstein
11+
ms.date: 05/19/2020
12+
---
13+
In this tutorial, you will be predicting iron ore impurities as a % of Silica in Azure SQL Edge. Before you proceed with the tutorial, ensure you have an active Azure subscription and you have installed the below pre-requisite software.
14+
15+
## Pre-requisite software to be installed
16+
1. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/).
17+
2. Install [Visual Studio Professions/Enterprise](https://visualstudio.microsoft.com/vs/)
18+
3. Install [PowerShell 3.6.8](https://www.python.org/downloads/release/python-368/)
19+
* Windows x86-x64 Executable Installer
20+
* Ensure to add python path to the PATH environment variables
21+
4. Install ["Microsoft Visual C++ 14.0" and build tools for Visual Studio](https://visualstudio.microsoft.com/downloads/) - Download can be located under "Tools For Visual Studio 2019"
22+
5. Install [Microsoft ODBC Driver 17 for SQL Server](https://www.microsoft.com/download/details.aspx?id=56567)
23+
6. Install [Azure Data Studio](/sql/azure-data-studio/download-azure-data-studio/)
24+
7. Open Azure Data Studio and configure Python for Notebooks. Details on how this can be accessed [here](/sql/azure-data-studio/sql-notebooks#configure-python-for-notebooks).This step can take several minutes.
25+
8. Install latest version of [Azure CLI](https://github.com/Azure/azure-powershell/releases/tag/v3.5.0-February2020)
26+
9. The below scripts require that the AZ PowerShell to be at the latest version (3.5.0, Feb 2020)
27+
28+
## Deploying Azure resources using PowerShell Script
29+
30+
Now, deploy Azure resources required for running the end to end scenario for Azure SQL Edge. These can be deployed either by using the PowerShell script below or through the Azure portal. For the purpose of this demo, we will be using the PowerShell Script.
31+
32+
1. Importing modules needed to run the below PowerShell script.
33+
```powershell
34+
Import-Module Az.Accounts -RequiredVersion 1.7.3
35+
Import-Module -Name Az -RequiredVersion 3.5.0
36+
Import-Module Az.IotHub -RequiredVersion 2.1.0
37+
Import-Module Az.Compute -RequiredVersion 3.5.0
38+
az extension add --name azure-cli-iot-ext
39+
az extension add --name azure-cli-ml
40+
```
41+
2. Now, let us declare the variables required for the script to run.
42+
```powershell
43+
$ResourceGroup = "<name_of_the_resource_group>"
44+
$IoTHubName = "<name_of_the_IoT_hub>"
45+
$location = "<location_of_your_Azure_Subscription>"
46+
$SubscriptionName = "<your_azure_subscription>"
47+
$NetworkSecGroup = "<name_of_your_network_security_group>"
48+
$StorageAccountName = "<name_of_your_storage_account>"
49+
```
50+
3. Declaring rest of the variables.
51+
```powershell
52+
$IoTHubSkuName = "S1"
53+
$IoTHubUnits = 4
54+
$EdgeDeviceId = "IronOrePredictionDevice"
55+
$publicIpName = "VMPublicIP"
56+
$imageOffer = "iot_edge_vm_ubuntu"
57+
$imagePublisher = "microsoft_iot_edge"
58+
$imageSku = "ubuntu_1604_edgeruntimeonly"
59+
$AdminAcc = "iotadmin"
60+
$AdminPassword = ConvertTo-SecureString "IoTAdmin@1234" -AsPlainText -Force
61+
$VMSize = "Standard_DS3"
62+
$NetworkName = "MyNet"
63+
$NICName = "MyNIC"
64+
$SubnetName = "MySubnet"
65+
$SubnetAddressPrefix = "10.0.0.0/24"
66+
$VnetAddressPrefix = "10.0.0.0/16"
67+
$MyWorkSpace = "SQLDatabaseEdgeDemo"
68+
$containerRegistryName = $ResourceGroup + "ContRegistry"
69+
```
70+
4. To begin creation of assets, let us log in into Azure.
71+
```powershell
72+
Login-AzAccount
73+
74+
az login
75+
```
76+
5. Next, set the Azure Subscription ID.
77+
```powershell
78+
Select-AzSubscription -Subscription $SubscriptionName
79+
az account set --subscription $SubscriptionName
80+
```
81+
6. Check and create a resource group for running the demo.
82+
```powershell
83+
$rg = Get-AzResourceGroup -Name $ResourceGroup
84+
if($rg -eq $null)
85+
{
86+
Write-Output("Resource Group $ResourceGroup does not exist, creating Resource Gorup")
87+
New-AzResourceGroup -Name $ResourceGroup -Location $location
88+
}
89+
else
90+
{
91+
Write-Output ("Resource Group $ResourceGroup exists")
92+
}
93+
```
94+
7. Check and create a Storage account and Storage account container in the Resource Group. Also create a container within the storage account and upload the zipped dacpac file. Generate a SAS URL for the file.
95+
```powershell
96+
$sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
97+
if ($sa -eq $null)
98+
{
99+
New-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName -SkuName Standard_LRS -Location $location -Kind Storage
100+
$sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
101+
$storagekey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroup -Name $StorageAccountName
102+
$storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storagekey[0].Value
103+
New-AzStorageContainer -Name "sqldatabasedacpac" -Context $storageContext
104+
}
105+
else
106+
{
107+
Write-Output ("Storage Account $StorageAccountName exists in Resource Group $ResourceGroup")
108+
}
109+
```
110+
8. Upload the Database Dacpac file to the Storage account and generate a SAS URL for the blob. **Note down the SAS URL for the database dacpac blob.**
111+
```powershell
112+
$file = Read-Host "Please Enter the location to the zipped Database DacPac file:"
113+
Set-AzStorageBlobContent -File $file -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context
114+
$DacpacFileSASURL = New-AzStorageBlobSASToken -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context -Permission r -StartTime (Get-Date).DateTime -ExpiryTime (Get-Date).AddMonths(12) -FullUri
115+
```
116+
9. Check and Create an Azure Container Registry within this Resource Group.
117+
```powershell
118+
$containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
119+
if ($containerRegistry -eq $null)
120+
{
121+
New-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName -Sku Standard -Location $location -EnableAdminUser
122+
$containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
123+
}
124+
else
125+
{
126+
Write-Output ("Container Registry $containerRegistryName exists in Resource Group $ResourceGroup")
127+
}
128+
```
129+
10. Push the ARM/AMD docker images to the Container Registry.
130+
```powershell
131+
$containerRegistryCredentials = Get-AzContainerRegistryCredential -ResourceGroupName $ResourceGroup -Name $containerRegistryName
132+
133+
$amddockerimageFile = Read-Host "Please Enter the location to the amd docker tar file:"
134+
$armdockerimageFile = Read-Host "Please Enter the location to the arm docker tar file:"
135+
$amddockertag = $containerRegistry.LoginServer + "/silicaprediction" + ":amd64"
136+
$armdockertag = $containerRegistry.LoginServer + "/silicaprediction" + ":arm64"
137+
138+
docker login $containerRegistry.LoginServer --username $containerRegistryCredentials.Username --password $containerRegistryCredentials.Password
139+
140+
docker import $amddockerimageFile $amddockertag
141+
docker push $amddockertag
142+
143+
docker import $armdockerimageFile $armdockertag
144+
docker push $armdockertag
145+
```
146+
11. Check and create the network security Group within the Resource Group.
147+
```powershell
148+
$nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
149+
if($nsg -eq $null)
150+
{
151+
Write-Output("Network Security Group $NetworkSecGroup does not exist in the resource group $ResourceGroup")
152+
153+
$rule1 = New-AzNetworkSecurityRuleConfig -Name "SSH" -Description "Allow SSH" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 22
154+
$rule2 = New-AzNetworkSecurityRuleConfig -Name "SQL" -Description "Allow SQL" -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 1600
155+
New-AzNetworkSecurityGroup -Name $NetworkSecGroup -ResourceGroupName $ResourceGroup -Location $location -SecurityRules $rule1, $rule2
156+
157+
$nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
158+
}
159+
else
160+
{
161+
Write-Output ("Network Security Group $NetworkSecGroup exists in the resource group $ResourceGroup")
162+
}
163+
```
164+
12. Create an Edge enabled VM, which will act as an Edge Device.
165+
```powershell
166+
$AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
167+
If($AzVM -eq $null)
168+
{
169+
Write-Output("The Azure VM with Name- $EdgeVMName is not present in the Resource Group- $ResourceGroup ")
170+
171+
$SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
172+
$Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroup -Location $location -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet
173+
$publicIp = New-AzPublicIpAddress -Name $publicIpName -ResourceGroupName $ResourceGroup -AllocationMethod Static -Location $location
174+
$NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup -Location $location -SubnetId $Vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -PublicIpAddressId $publicIp.Id
175+
176+
177+
##Set-AzNetworkInterfaceIpConfig -Name "ipconfig1" -NetworkInterface $NIC -PublicIpAddress $publicIp
178+
179+
$Credential = New-Object System.Management.Automation.PSCredential ($AdminAcc, $AdminPassword);
180+
181+
$VirtualMachine = New-AzVMConfig -VMName $EdgeDeviceId -VMSize $VMSize
182+
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName $EdgeDeviceId -Credential $Credential
183+
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
184+
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $imagePublisher -Offer $imageOffer -Skus $imageSku -Version latest
185+
$VirtualMachine = Set-AzVMPlan -VM $VirtualMachine -Name $imageSku -Publisher $imagePublisher -Product $imageOffer
186+
187+
$AzVM = New-AzVM -ResourceGroupName $ResourceGroup -Location $location -VM $VirtualMachine -Verbose
188+
$AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
189+
190+
}
191+
else
192+
{
193+
Write-Output ("The Azure VM with Name- $EdgeDeviceId is present in the Resource Group- $ResourceGroup ")
194+
}
195+
```
196+
13. Create an IoT Hub within the resource group.
197+
```powershell
198+
$iotHub = Get-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName
199+
If($iotHub -eq $null)
200+
{
201+
Write-Output("IoTHub $IoTHubName does not exists, creating The IoTHub in the resource group $ResourceGroup")
202+
New-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName -SkuName $IoTHubSkuName -Units $IoTHubUnits -Location $location -Verbose
203+
}
204+
else
205+
{
206+
Write-Output ("IoTHub $IoTHubName present in the resource group $ResourceGroup")
207+
}
208+
```
209+
14. Add an Edge Device to the IoT Hub. This step only creates the device digital identity
210+
```powershell
211+
$deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
212+
If($deviceIdentity -eq $null)
213+
{
214+
Write-Output("The Edge Device with DeviceId- $EdgeDeviceId is not registered to the IoTHub- $IoTHubName ")
215+
Add-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId -EdgeEnabled
216+
}
217+
else
218+
{
219+
Write-Output ("The Edge Device with DeviceId- $EdgeDeviceId is registered to the IoTHub- $IoTHubName")
220+
}
221+
$deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
222+
```
223+
15. Get the device Primary connection String. This would be needed later for the VM. The next command uses Azure CLI for deployments.
224+
```powershell
225+
$deviceConnectionString = az iot hub device-identity show-connection-string --device-id $EdgeDeviceId --hub-name $IoTHubName --resource-group $ResourceGroup --subscription $SubscriptionName
226+
$connString = $deviceConnectionString[1].Substring(23,$deviceConnectionString[1].Length-24)
227+
$connString
228+
```
229+
16. Update the connection string in the IoT Edge Config File on the Edge Device. The next commands use Azure CLI for deployments.
230+
```powershell
231+
$script = "/etc/iotedge/configedge.sh '" + $connString + "'"
232+
az vm run-command invoke -g $ResourceGroup -n $EdgeDeviceId --command-id RunShellScript --script $script
233+
```
234+
17. Create an Azure Machine learning workspace within the Resource Group
235+
```powershell
236+
az ml workspace create -w $MyWorkSpace -g $ResourceGroup
237+
```

0 commit comments

Comments
 (0)