Azure VM Part 2 – Create a development network

…or create a small customer network, for that matter…

The last month is been dedicated to learning more about Windows Azure, and how to facilitate features like SQL databases, web sites, virtual network, DNS servers and virtual machines to be able to create my own optimized development environment.  I have been playing around with my work MSDN subscription and measured the cost for a small environment – with its own domain controller, web and SQL server.

Basic CPUs RAM Price/month
A0 (Extra Small) 1 768mb $15
A1 (Small) 1 1.75gb $55
A2 (Medium) 2 3.5gb $110

When creating such an environment in Windows Azure, you should do the following:

  1. Create Affinity Group
    1. Select the datacenter nearest your location. Mine is North Europe.
  2. Create Storage Account
    1. Select affinity group from (1) as Region/Affinity Group.
    2. Also choose Geo-Redundat as replication
  3. Register DNS server
    1. Set internal IP address to
  4. Define Virtual Network.
    1. Remember to select affinity group from (1) and DNS server from (3)
    2. Cost is about $50/month
  5. Create VM for AD
    1. Select “basic” tier
    2. It’s enough with a size on “A0 (shared core, 768MB memory)” for a development environment ($15/month), opposite to $55/month for A1. This can be changed in 5 minutes (including reboot).
    3. Set local administrator username and password
    4. Write the global name for the AD machine
    5. Select the virtual network defined in (4)
    6. Select the storage account defined in (2)
    7. Validate IP for AD (should be 10.0.04)
    8. install the AD domain services role and promote VM to a domain controller
    9. Create administrator and service accounts
  6. Create VM for SQL Server
    1. Create a new VM from gallery (SQL Server 2014 Web Edition)
    2. Select “Basic” tier. You don’t need load balances and auto-scaled development environment
    3. Select Basic-A1 size (easily changed to Basic-A2 og Standard-A5 for that matter)
    4. Select administrator username and password
    5. Select the virtual network defined in (4)
    6. Select the storage account defined in (2)
    7. Create a 1433 (standard MS SQL port) endpoint
    8. Join the server in created domain from (5.8)
    9. Add SQL administrator with sysadmin
    10. Create an inbound rule in the firewall for SQL Server
    11. Configure SQL Server “Max memory” (70-80% of total memory)
    12. If production server, you should add two disks for data and log formatted with 64k block size.
  7. Cerate VM for Web server
    1. Create a new VM from gallery (Windows Server 2012 R2 Datacenter)
    2. Select Basic-A0 or Basic-A1 size
    3. Same as 6 d-f
    4. Create http and https endpoints
    5. Join the server in created domain from (5.8)
    6. Install IIS web role and install software for web deploy

Powershell commands for (5.8) – install AD and promote as domain controller:

Set-DnsClient –InterfaceAlias "Ethernet*" –ConnectionSpecificSuffix 
Install-WindowsFeature AD-Domain-Services –IncludeManagementTools 
Install-ADDSForest –DomainName

Powershell command for joining a computer to domain (as in 6.8 and 7.5):

Set-DnsClient –InterfaceAlias "Ethernet*" ` –ConnectionSpecificSuffix 
Add-Computer –Domain 

The cost for this setup is about $130-$250, depending on server configuration you need:

  • Small development
    • AD + VN = Basic-A0 + $50
    • Web = Basic-A0
    • SQL = Basic-A1
    • Cost = $50 + 2*A0 + 1*A1 = $50 + $30 + $55 = $135/month
  • Small production
    • AD + VN = Basic-A0 + $50 = $65
    • Web = Basic-A1 = $55
    • SQL = Basic-A2 = $110
    • Cost = $65 +$55 + $110 =  $230/month

Now you should be ready for coding…




Azure VM Part 1 – Create SQL Server VM

When you buy a MSDN subcription with Visual Studio you receive free credits (renewed every month) to use in Windows Azure. This makes it very easy to create your own development and test environment very fast. In my case, as a developer and DBA, I want to create my own virtual machines that I have full control over.

You are able to access most of Azure through PowerShell, and I was particular excited about the possibility to create virtual machines on the fly in PowerShell, and here is the first version of my create_azure_sqlvm.ps1.

Example usage:

create_azure_sqlvm.ps1 "sql06" "sql06admin" "itsaSecret2014"

This script has 3 required parameters: vm-name, admin loginname and password. These parameters must be supplied to script as shown above. In addition, there are 2 default parameters, location and instanceSize. The first default parameters $location is which data center the new virtual machine will be stored. The default value is set to “North Europe” since this is the nearest to my home city Fredrikstad 🙂

All available locations can be retrieved by the following command:

Get-AzureLocation | Select Name

The second default parameter $instanceSize tell Azure how big the virtual machine should be when it is created. The default value for the script is set to “Small”. This value might not be ideal for a production server, but in my case for a development environment, this is okey. Se link for more information on sizes.

The script will install the latest SQL Server 2014 Web edition available. See the ImageFamily parameter to select another image for the SQL Server installation.

When you run the script in administrator mode in PowerShell, you will get some similar out as show below:


According to my calculations this virual machine will cost about $50-70 per month, depending on how much it is used.

Azure – chosing correct subscription

When working with Windows Azure it is possible to have multiple subscriptions available. You might have a private subscription, as well as one or more company subscriptions that you can use. If multiple subscriptions are available, you need to select the correct one before creating Azure infrastructure from PowerShell.

Use the following PowerShell command to make sure you are logged in Windows:


You will be presented with the opportunity to select from available Azure accounts, or supply your windows account ID. When you have successfully logged into Windows Azure, you can use the following commands to find out default subscription, list all available subscriptions and select a desired subscription where you want to create Azure infrastructure.

# Azure account details automatically set
Get-AzureSubscription -Current `
    | select SubscriptionName, ActiveDirectoryUserId

#select all subscriptions
Get-AzureSubscription `
    | Select SubscriptionName, ActiveDirectoryUserId, IsDefault

#select desired subscription
Select-AzureSubscription "[SubscriptionName]"

These commands are important because the current subscription decides the price you have to pay for the things you are creating in Azure.

Perfmon – create collector set with powershell

I have finally found a kind of “perfect” starting point with settings for my data collector sets in “Performance Monitor”. For the last year I have set up a number of collector sets, and  found it useful to organize these into monthly folders with “YYYY-MM and set up one BLG for each day. I normally set up a schedule with 12-16 hours, starting at 06:00 and ending around 22:00. This enables me to analyse performance issues in normal work hours, plus/minus a few hours.  I only set an “All-Day” schedule if I want to monitor the server performance during backup and nightly maintenance.

The following script is used to create the data collector set and start it. Download full script here.

  [string]$name = "MyCollectorSet"

$datacollectorset = New-Object -COM Pla.DataCollectorSet
$datacollectorset.DisplayName = $name;
$datacollectorset.Duration = 50400 ;
$datacollectorset.SubdirectoryFormat = 1 ;
$datacollectorset.SubdirectoryFormatPattern = "yyyy\-MM";
$datacollectorset.RootPath = "%systemdrive%\PerfLogs\Admin\" + $name ;

$DataCollector = $datacollectorset.DataCollectors.CreateDataCollector(0) 
$DataCollector.FileName = $name + "_";
$DataCollector.FileNameFormat = 0x1 ;
$DataCollector.FileNameFormatPattern = "yyyy\-MM\-dd";
$DataCollector.SampleInterval = 15
$DataCollector.LogAppend = $true;

$counters = @(
    "\PhysicalDisk\Avg. Disk Sec/Read",
    "\PhysicalDisk\Avg. Disk Sec/Write",
    "\PhysicalDisk\Avg. Disk Queue Length",
    "\Memory\Available MBytes", 
    "\Processor(_Total)\% Processor Time", 
    "\System\Processor Queue Length"
) ;

$DataCollector.PerformanceCounters = $counters

$StartDate = [DateTime]('2013-01-01 06:00:00');

$NewSchedule = $datacollectorset.schedules.CreateSchedule()
$NewSchedule.Days = 127
$NewSchedule.StartDate = $StartDate
$NewSchedule.StartTime = $StartDate

    $datacollectorset.Commit("$name" , $null , 0x0003) | Out-Null
catch [Exception] 
    Write-Host "Exception Caught: " $_.Exception -ForegroundColor Red 

If your SYSTEM account is not member of the local groups “Performance Log Users” and “Performance Monitor Users”, the following powershell commands can be run to add these memberships:

    $group = [ADSI]"WinNT://./Performance Log Users,group"

    $group = [ADSI]"WinNT://./Performance Monitor Users,group"

When a performance monitor data collector set is screated, this can be found under Task Scheduler under “\Microsoft\Windows\PLA”. It is very useful to make some minor changes to the settings of the data collector set that is not available from Performance monitor. If you want the data collector set to automatically start after server reboot, you should add a “At startup” trigger to the scheduled task.