Thursday, July 21, 2016

Creating Azure VM's using images

This article helps you to create Azure VM's from predefined images: 

1. Introduction

Many of the times, projects require to provision dev VM's quickly.The dev VM's have various softwares installed, lot of configuration has to be done which needs to be same across other development machines. 

In such cases its best to have a VM fully configured, make an image out of it & use the image when provisioning other development VM's. This would save lot of time & effort. The below steps show how we could image.

2. Steps to Capture an Image

a. Login with your Microsoft Azure account to the Azure Portal

b. Select the VM that you want to capture the image to be created and click Connect. The RDP file will be downloaded. Connect to the VM

c. Open a command prompt within an Administrator command.

d.  Go to directory %windir%\system32\sysprep ( e.g. In my case it was c:\windows\system32\sysprep)

e. Type sysprep and start the process .In the System Preparation Tool dialog box, select the Generalize option and shutdown from the dropdown as shown below 


Once sysprep completes, the VM is shutdown

f. In the Azure classic portal, click the virtual machine & select Capture as shown below

           
                           
g. Click "I have run the sysprep" and fill in the image name

h. The new image is now available under Images


3. Create a new VM

a. To create an VM image, go to Create VM option.

b. Under Images tab, you would see the image thats create in step 2j . Select this image

c. Fill in all other details to Create the VM

d. VM would be created with the image details 

Tuesday, June 21, 2016

Implementation of Azure Traffic Manager

Azure Traffic Manager allows to control distribution of traffic to specified end points. These end points include Azure websites and cloud services.

Traffic Manager improves availability of critical applications, responsiveness of the applications, can help in maintenance of a service without downtime, and traffic distribution based on certain configuration thats set up.

Implementation of Traffic Manager

1 - Log on to Azure Portal
2 - Click Traffic Manager , and Add New as shown below

                                                                  


      

3-  In the Quick Create box, as shown below there are 3 options of Load Balancing viz. Performance (default) , Round Robin or FailOver. Select the default "Performance" option, later on we can change it as required. The performance option ensures the load is equally distributed to the Traffic Manager endpoints
                                                                 


The Round robin ensure requests are hit to the endpoints alternatively where as the failover option ensures if the first end point goes down then the second one handles all the requests.

4- Put a name for your Traffic Manager and click Create


Configuration of Traffic Manager

Once the traffic Manager is created, you need to configure it. Click the traffic manager created. Click on the "EndPoints" tab to add the endpoints
                                                                           

Select either cloud service or Azure website as end point. Here I am adding cloudservice as endpoints taking an MVC website as an example.

Once you add the EndPoints, Azure gets the status of end points.  The status of the traffic manager would be degraded one.

To get this online, you would need to do more two things. The first one being, add a simple html file (e.g. probe.html) at the root of the website. This would return status code as 200.  Ensure this file can be anonymously accessed. The second one, add a negate entry in the web.config as follows

  <conditions>
            <add input="{HTTP_HOST}" matchType="Pattern" pattern="^xxxx.cloudapp.net$" negate="true" />
          </conditions>

After doing above, you would see the status of the traffic manager as "online". The probe.html could be advanced by writing custom code e.g. to check DB connection ,etc & then return the status code.

                                                                        



Monday, May 9, 2016

Geo Replication for Azure SQL Databases

In the recent past, I wanted to have some redundancy for my databases hosted at NE (North Europe) region. 

1. Introduction

I found out Azure Geo-Replication lets you do this pretty quickly.  Active Geo-Replication lets  you configure up to 4 readable secondary databases in the same or different data center locations (regions). Secondary databases are available in the case of a data center outage or the inability to connect to the primary database.  If for any reason your primary database fails, or simply needs to be taken offline, you can failover to any of the secondary databases and the application / database would behave normal. To do the Azure Geo-Replication follow the steps:

2. Select Source Database

Select the Database as shown in the below figure. Choose the Geo-Replication option


3. Select Target Database

As seen below, the NE region is paired with WE (West Europe) region. Hence select the WE region. Enter the server name, and other details as shown below.


 

4. Geo-Replicate

The Geo-replication starts as indicated with dotted lines (in progress)


Once the Geo-Replication is complete, the secondary database is ready and available. If a failover is done, then secondary database comes in to picture and serves the need.

Note - I had to change my connection string of MVC application to the failed over database since the server name was different.  

Ref- https://azure.microsoft.com/en-in/documentation/articles/sql-database-geo-replication-overview/

Friday, May 6, 2016

Azure: Migrating VMs

This post says about how do you migrate Azure VM's from one region to other region OR move one VM from one storage account to another storage account.

Following are the steps needed: 

1. Powershell

Open an Azure Management Powershell with Admin privileges

2. Connect to tennant

2. Log on to Azure in the PowerShell window by typing the following command
  Add-AzureAccount

3. Select the subscription of the source VM

  Select-AzureSubscription -Name "BizSpark Plus"

4. Get details for source VM

$disk = Get-AzureDisk | Where-Object { $_.AttachedTo.RoleName -eq "VM_NAME" }  #VM_NAME is the source VM
$mediaLink = $disk.MediaLink
echo $mediaLink  # Get the storage name from here e.g. by copying the storage name before the first "." e.g. portalvhdsgp72f86dj50g3
The above step would give you the storage account. The log on to the portal, get the storage , key as shown below.
You would need to spend about 10 min in getting these details. 












5. Source VM commands

From the above screenshots, we can get the values of Storage Account Name, Source Key (master key), Container and Virtual Hard Disk(vhd).
$sourceStorageAccountName = "portalvhdsgp72f86dj50g5"
$sourceKey = "d/MxXjv3SMw4TP+zSSYMJsSUHOtgBKLmFmouJgNFRYkhGVf742vdPzmYAXQW4cBJwWlccgkOtV3PCiGZEU3nAw=="
$sourceContainer ="vhds"
$sourceContext = New-AzureStorageContext –StorageAccountName $sourceStorageAccountName -StorageAccountKey $sourceKey
$blobName = "VM_Name.vhd" 

 If you want to put your destination VM or disk under a particular storage account follow step 4 to get the details of the storage account, container, and key.
If you need to create a new storage, container then create it and note down its values.

6. Destination VM commands

If the subscription to the destination VM is same, then dont select the subscription else you would need to select azure subscription
$destinationStorageAccountName = "portalvhds56k8sxsm0mns9"
$destinationKey = "uKFhc8ebZ6kA2Z4FxWNXQsWfa7k8GVKnVHs+B/FzbGM4/Jbo9NJVyz+V0+5/YaUUkQ9O0Fdb/oxpV+3KknhIVg=="
$destinationContext = New-AzureStorageContext –StorageAccountName $destinationStorageAccountName -StorageAccountKey $destinationKey   
$destinationContainerName = "migratedvhds"

6. Copy the blob now from source to target

$blobCopy = Start-AzureStorageBlobCopy -DestContainer $destinationContainerName -DestContext $destinationContext   -SrcBlob $blobName  -Context $sourceContext  -
SrcContainer $sourceContainer

7. Check the status of blog copy.

The blob copy may take up to few hours depending on the size of the blog e.g. I have seen 1 TB of data disk to be moved takes 
~4 hours
$blobCopy | Get-AzureStorageBlobCopyState   #to check the status
Once the blog gets completely copied, the next step is to create an Azure disk as shown below. If you need to use new Azure Portal, search "OS Disks" and create one.
   
Use the VHD URL explorer to select the blob from the destination container that was copied earlier. If you migrating the VM please select “The VHD contains an 
operating system.” If you are migrating data disk uncheck the previous check box. 
After the disk is created, if the disk created is of type "operating system" then create a new VM.
  
When creating the VM select the disk which just was created. This would ensure you have the same copy of the virtual machine as of the source. 

If the disk created above is a data disk, then add this disk to an existing VM using "Add Disks" option.

8. Clean up

Last and final step is clean up the source VM's, disks and blobs. 
Detach the disks you attached.
Delete the VMs.

Tuesday, April 12, 2016

Migrating data from SQL sever (On Prem) to Azure

I was trying to migrate the data from SQL Server 2012 to Azure DB. There are different ways to this , one of being exporting the data tier and importing back to Azure.

However, during exporting data tier some times you land up with bunch of exceptions as seen below. Its time consuming to get rid of these and sometimes you don't know what to do other than by searching or any trial and error.

I found a very cool tool that does this for you. Please download sqlazuremw for the SQL version you have from codeplex available at https://sqlazuremw.codeplex.com/



I downloaded it for SQL Server 2012 and works like a gem ! 
                                            
Steps:

1. Select the Analyze/Migrate option and connect to source
2. Do the analysis of the source database
3. Connect to target server
4. Start the migration

Haven't seen any issues so far. You could visit http://sqlazuremw.codeplex.com/workitem/list/basic for any known issues.

Monday, April 11, 2016

Azure - Getting Started


Getting Started for Azure

I have come across many of the people asking where do we start with Azure Portal. What is in there , what would be the price if I need to host a simple website along with SQL as a backend.

Let's start with Azure basics.  The Azure™ Services Platform (Azure) is an internet-scale cloud services platform hosted in Microsoft data centers, which provides an operating system and a set of developer services that can be used individually or together. Azure’s flexible and interoperable platform can be used to build new applications to run from the cloud or enhance existing applications with cloud-based capabilities. Its open architecture gives developers the choice to build web applications, applications running on connected devices, PCs, servers, or hybrid solutions offering the best of online and on-premises.


I would suggest to go for an Azure trial account for a month before you opt for any subscription.

To sign up Azure , click  https://account.windowsazure.com/signup 



At the bottom click "Sign Up" to fill in all the required details to get started. You would also need to fill in card details , don't worry its safe & charges won't  be deducted till you are under free month subscription. 


You receive $200 of Windows Azure credits with the Free Trial.  The choice is yours on how you use your Windows Azure credits. You could use it on Virtual Machines, Web Sites, Cloud Services, Mobile Services, Storage, SQL Database, on whatever you need. To protect you from accidentally incurring charges for usage beyond the included offer amount please set the Spending Limit feature by default to a limit of $0.


Once you are done with initial sign up process, please click the URL  https://portal.azure.com/.

 


After logging on to the Azure Portal, click the "New" button & provision whatever you like. e.g. You would need to publish an MVC website along with a SQL database.

Click the "New" link , then "MarketPlace" -> "Everything". You would see "WebApp + SQL" as shown below. Click the same to create an app along with SQL database. 


        



Please follow the link https://azure.microsoft.com/en-us/marketplace/partners/microsoft/websitesqldatabase/
 to get more details on publishing your first app.

Enjoy Azure!

Cheers,
Kailas