Upload
trinhdieu
View
252
Download
0
Embed Size (px)
Citation preview
Configuring a Windows Azure
SQL Sync Group
Provide Cross-Region Data Protection
Introduction Windows Azure is a truly amazing platform for consumers of IT services. It provides enterprises from
the small sole trader business through to global conglomerates the ability to quickly and effectively
consume cloud services but also allows you to so with ease.
New features and service offerings are appearing with rapid pace as Microsoft seek to make Azure
the glove that fits for everyone and the prices keep on coming down too which makes it more
affordable to consume cloud than ever before.
In this guide, I’m going to walk you through the process of setting up Windows Azure SQL Sync
between two SQL Azure databases. This technology using Windows Azure SQL allows you to
replicate databases either between other instances of Azure SQL databases or with on-premise SQL
Server databases.
This guide as are all my publications, dedicated to my wife Nicky and my three daughters; Madison,
Jessica and Layla who are subjected to living with me and technology and not always in that order.
Authors Richard J Green works as a Senior Technical Consultant for Infront Consulting, specializing in
delivering System Center solutions helping customers leverage their investment in IT with Microsoft
technologies. Richard works extensively with Windows Azure and System Center.
He has an unhealthy obsession with the colour pink hence the colour choice of this book.
You can follow Richard on Twitter @richardjgreen or read his blog focusing on Microsoft products
and technologies along with other digital ramblings at http://richardjgreen.net.
Copyright This book is copyright of Richard J Green and co-authors. No unauthorised copying of material in this
book shall be performed without the prior written consent of Richard Green or one of the co-
authors.
© 2014
Contents Introduction ...................................................................................................................................... 2
Authors ............................................................................................................................................. 2
Copyright .......................................................................................................................................... 2
Introduction to SQL Azure ................................................................................................................. 4
What is SQL Azure?........................................................................................................................ 4
How is it Different to SQL Server? .................................................................................................. 4
Why Would I Use it Verses SQL Server? ......................................................................................... 5
Introduction to SQL Azure Sync ......................................................................................................... 6
What is SQL Azure Sync ................................................................................................................. 6
SQL Server Log Shipping Features .................................................................................................. 6
SQL Azure Sync Features ................................................................................................................ 6
Prerequisites for Configuration .......................................................................................................... 8
Configuring SQL Azure Servers ........................................................................................................... 9
Configuring SQL Azure Databases .................................................................................................... 12
Creating a Sync Group ..................................................................................................................... 13
Define Sync Group Rules .............................................................................................................. 17
Configure Automatic Sync ............................................................................................................ 21
Checking the Status of the Sync Group ............................................................................................ 23
Configuring a Windows Azure SQL Sync Group
4
Introduction to SQL Azure In this first chapter, I’m going to briefly explain SQL Azure, what it has to offer and the limitations of
it over conventional SQL Server. I’m not going to get hung up on pricing here as this will vary
according to your agreements with Microsoft and what kind of commitment you make to Windows
Azure however I will touch on pricing at a high level.
What is SQL Azure? SQL Azure offers up database as a service (DBaaS). This DBaaS allows us to provide customers of our
services with a database to allow applications to store data without the concern or overhead of the
underlying database server.
SQL Azure does still rely on the concept of a database server, however this is for the most part
transparent to us. The only time we actually interact with the server is in two ways:
1. Accessing the server to manage or connect to databases using the server username and
password combination
2. Creating new databases in a specified server
SQL Azure is a regionalised service allowing us to create databases in any of the Windows Azure
regions of our choosing, allowing us to be both flexible and efficient. With this, we can home the
database in the most appropriate location with regard to our application.
How is it Different to SQL Server? The principles and concepts applied to a SQL Server and databases remain the same. A server can
host many databases. A database can have many tables, tables have many columns and rows and so
on.
The major hang-up for administrators of SQL Server platforms is centred on the sizing and
performance of those servers and this is where SQL Azure differs.
With a conventional SQL Server software, database administrators and platform engineers will
concentrate on ensuring that the server has the right amount of everything to meet the
performance expectations.
Memory to allocate to the SQL Server processes
Enough CPU sockets and cores to cope with the processing demand
Sufficient I/O per Second (IOPS) in the disk architecture and hardware
Correct RAID levels to provide appropriate protection for databases and logs
Such is this configuration complexity and challenge for SQL Server that companies such as Fusion-io
have made an entire business of developing flash based interface cards for servers to provide
massive IOPS for platforms just like SQL Server.
This is just a subset of the challenges faced by engineers designing SQL Server platforms and this is
the reason SQL Azure is a wonderful solution.
No more do we need to worry ourselves about whether a SAS 6Gbps RAID10 vs. iSCSI or Fibre
Channel storage will provide enough bandwidth for our databases or whether an Intel E5-2450 vs. an
Intel E5-2660 is the right processor.
With SQL Azure, when you decide you want a database, you pick a name for it and whether you
want to use the Web or Business scale for it and deploy. The only question that needs answering is
Introduction to SQL Azure
5
which collation you opt for and that is normally chosen for you by the application so this decision is
reduced to reading up the correct value in the software vendor’s documentation.
Why Would I Use it Verses SQL Server? Price and simplicity are the two key factors in this decision. To build and configure a SQL Server with
the appropriate hardware to meet performance expectations and requirements coupled with the
licensing requirements for SQL Server licenses, it can be costly to do.
The complexity of getting the configuration right taking into account the hardware, operating
system, SQL Server software, authentication, backup and more can be overwhelming too.
If you are working for a company which has openly adopted cloud and have extended your on-
premise datacenter to the cloud using Windows Azure Infrastructure as a Service (IaaS) with
Windows Azure VPN you may be thinking that you can avoid the configuration complexity by just
provisioning an A5, A6 or A7 virtual machine in Windows Azure which is indeed true however the
Service Provider Licensing Agreement (SPLA) for SQL Server in Windows Azure is still pretty
expensive.
SQL Azure is billed on storage consumption of the database. An example 10GB database in either the
Web or Business services will cost you just under £30 per month. A SQL Server using the A6 IaaS
Virtual Machine size could be costing you £400 a month to host the very same database.
Configuring a Windows Azure SQL Sync Group
6
Introduction to SQL Azure Sync In this section, I’ll cover what SQL Azure Sync is and how it can help you.
What is SQL Azure Sync Those of you verse in traditional SQL Server availability and data protection technologies will be
familiar with terms such as Mirroring, Log Shipping, Clustering or AlwaysOn. All of these offer a
different way to protect your data and SQL Azure Sync is a new take on this, taking some of the best
elements of each, and offering it up in a way which makes it easy to consume as you would expect
from a DBaaS cloud service.
If you were to compare SQL Azure Sync to an existing SQL Server technology, it is closest to Log
Shipping.
SQL Server Log Shipping Features With Log Shipping you are required to have multiple separate SQL Servers which transport
transaction logs from the server with the database copy designated as the Primary. These logs are
sent to one or more servers which are designated as Secondary’s of which there may be more than
one.
Log Shipping permits for a user-specified delay between the transmission of the logs allowing a
Secondary database to be kept intentionally out of sync for a configurable period of time. This can
be an ideal configuration to protect against data corruption. Having the Primary and Secondary in a
near real-time configuration provides excellent availability for the data under normal conditions
however if something corrupts data in the Primary database, you will be left running for your DPM
Central Console to recover the database from a previous backup (you are using System Center Data
Protection Manager 2012 R2 to backup your SQL Servers right).
Log Shipping when configured, allows for the use of a limited degree of read-only access from the
Secondary databases. This limited read-only access allows applications which are Log Shipping aware
to perform read operations from a Secondary database which may be closer to or better connected
to the application that the Primary although this would normally only apply in the case of a highly
distributed application as you wouldn’t typically architect an application to sit further from its
Primary than it does its Secondary.
SQL Azure Sync Features The good news firstly is that everything Log Shipping can do, SQL Azure Sync can do and some.
At a high level, here are the key features and benefits of SQL Azure.
Multi-Master Model
Conflict Detection
N-Node Architecture
User-Specified Delay Support
Granular Synchronisation
Multi-Master Model refers to a key difference between SQL Azure Sync and SQL Server Log Shipping
to the benefit of SQL Azure Sync. Whereas Log Shipping has a single Primary with multiple
Secondary’s, SQL Azure allows you to deploy bi-directional synchronisation between databases and
using Conflict Detection, SQL Azure Sync is able to determine which database update wins in the
event of a tie.
Introduction to SQL Azure Sync
7
An N-Node architecture matches the capability of Log Shipping allowing you to have a large number
of databases synchronising the same database content to make your database as distributed or
available as you require however with SQL Azure Sync, unlike SQL Server Log Shipping, these
multiple nodes are fully readable and writable in to and from any of the databases in the group.
User-Specified Delay as before, is matched by the Log Shipping feature allowing you to configure a
time delay between automatic synchronisations occurring between Sync Group members. Keep in
mind with SQL Azure Sync however that if you are planning on taking advantage of the ability to
perform read and write operations in any of your database locations that you might not want to use
a delay between the database copies as this could result in differing results for clients or applications
accessing the database due to differences between the data sources.
The advantage that SQL Azure Sync has over all other SQL Server technologies is Granular
Synchronisation. This ability means that you are fully in control of what data subsets are important
to you and warrant being kept copied in another database elsewhere in the world. If you have a
multi-gigabyte database but only a single table or even a single column in a single table are truly
important to you, then you only need to sync this subset of items. This capability means that not
only can you reduce the time it takes to converge databases between copies but also reduces your
Windows Azure storage expenditure as you will only be paying for storage for the amount that you
are consuming through sync to other database copies.
Configuring a Windows Azure SQL Sync Group
8
Prerequisites for Configuration The prerequisites for the configuration of SQL Azure Sync are actually pretty limited. In this guide, I
am solely focusing on the ability to make your Windows Azure SQL databases available across
datacenter regions, however in a future guide, I plan to unearth the ability to combine SQL Server
with SQL Azure using this technology. In that guide, we will have more to research and work on with
prerequisites, however for now, bare the following in mind.
1. Access to a Windows Azure Subscription which allows you to create new objects such as new
SQL Azure Servers and Databases
2. Sufficient spending limit entitlement remaining in the subscription to create the required
databases if your subscription is capped to a budgetary limit
For the remainder of this guide, I am assuming that you currently have no SQL Azure Servers or
Databases configured and I will walk you through the process from end-to-end.
Configuring SQL Azure Servers
9
Configuring SQL Azure Servers Before we can do anything else in this guide to work on SQL Azure Sync, we need a SQL Azure
Server, two for this example to be more specific.
As I have pointed out previously, SQL Azure Sync allows us to create an N-Node Sync Group but for
this guide I will be demonstrating the simplest possible configuration with two servers and two
databases.
Once you’ve got yourself logged into your Windows Azure Portal, select the SQL Databases node
from the navigation on the left. This will open the SQL Databases panel. From the ribbon menu at
the top, select the Servers option and then select the option at the bottom for Add.
Configuring a Windows Azure SQL Sync Group
10
First off, we want to create a SQL Server in our primary region, the region where our application that
uses the SQL database is going to be located. For me, this is North Europe so I select the North
Europe region from the bottom of the Create Server dialog. You need to specify a Login Name, Login
Password for the SQL Server and also which subscription it should be setup in if you have more than
one subscription accessible to you. The login that you create is a SQL Login for those of you familiar
with Windows Authentication vs. SQL Authentication.
With all of the fields entered, select the tick button in the bottom right of the dialog to create the
server. Servers are created in Windows Azure with a random ID name which you have no control
over if you were wondering why you weren't asked to enter a server name in the previous dialog.
With that server created, we now want to create the secondary server for our alternate datacentre
region.
Select the Add button again from the bottom of the SQL Databases Servers view.
Configuring SQL Azure Servers
11
For simplicity and to make troubleshooting easier, I like to have my username and password on my
primary and secondary servers matching but that's a choice for you to make. Enter the Login Name
and Login Password that you wish to use and select the subscription if required. Lastly, specify your
region as that which you wish to use as your secondary. I elected to use West Europe. North Europe
is in Ireland and West Europe is in Amsterdam so that's plenty of miles between the two for my data
to be safe in the event of a disaster in one location to not affect the other, unless ash clouds can
bring down datacenters as well as keep planes on the ground of course.
Configuring a Windows Azure SQL Sync Group
12
Configuring SQL Azure Databases With our SQL Servers created, we can now create databases on those servers. From the SQL
Databases view in the Windows Azure Portal, select the Databases option from the top ribbon
menu. Select the New button in the bottom left, and from the popup menu, select the Data Services
> SQL Database > Custom Create option.
From the New SQL Database Custom Create wizard, enter a name for the database. From the
Edition picker, select either Web or Business. I use Web for my database as my current database is
about 15MB so there is no way it's going to hit the ceiling of 5GB on Web edition any time
reasonably. 5GB is the limit for Web with the default size being 1GB. Business has a default size of
10GB and scales up to 150GB. You can alternate between Web and Business after the fact so I would
select Web if you are starting out with this.
The next option is Collation. Select this option wisely as you cannot change it once the database is
created. The default collation is SQL_Latin1_General_CP1_CI_AS however I am using the Windows
collations right now so I’ve selected to use Latin1_General_CI_AS. The Microsoft Support article at
http://support.microsoft.com/kb/322112 explains that SQL collations are retained for backward
compatibility and that Windows collations are preferred. There are a few small performance
differentiators between the two so please do read the article if you are unsure. Furthermore, if you
are unsure what CI_AS means or whether you need case, accent, kana or width sensitivity or
insensitivity for your database, please refer to the support documentation for your product or if no
documentation or advice on collation is provided for the product, refer to the MSDN documentation
Creating a Sync Group
13
at http://msdn.microsoft.com/en-us/library/ms143515(v=sql.105).aspx. If all the above fails, then
use the default of either SQL_Latin1_General_CP1_CI_AS or Latin1_General_CI_AS as above.
As before, select the appropriate subscription if you have multiple available to you. You will need to
select the same subscription as that which you created the SQL Server into previously. The final
option is Server. For this first database, select the Server which you created in your primary region,
North Europe for me as shown in the screenshots.
Once you have your database created, repeat all of the above steps to create the secondary
database. I like my primary and secondary databases to have the same name just for ease of
management and consistency but there is no rule which says you must do this. You could append
your names with _primary and _secondary to differentiate them if you like but this makes things
challenging if you are in a failover scenario later on where your secondary actually becomes your
primary. For the secondary database, make sure you select the server in your secondary region
which for me is West Europe.
Creating a Sync Group With our two SQL Servers and our two SQL databases now created in our two distinct regions, we
are ready to create a Sync Group between them. From the SQL Databases view of the Windows
Azure Portal, select the Add Sync option from the bottom and select the New Sync Group sub-
option.
This will launch the Create SQL Data Sync Group wizard.
Configuring a Windows Azure SQL Sync Group
14
On the opening screen, enter a Name for the Sync Group. I have named my group in accordance
with the database name but replacing the db suffix with the sync reference. For the Region option,
set this to the region of your primary database which for me is North Europe once more. As
previously, select the appropriate subscription if you have multiple available to you. This needs to be
the same subscription as the SQL Servers and databases previously created.
Creating a Sync Group
15
Next, we define the Sync Hub. The Sync Hub is the database which will be used as the dataset
source, the primary database. From the drop-down menu for the Hub Database option, you will see
your two newly created databases. Make sure you select the correct database which for me is the
database in North Europe. Once the database is selected, enter the Username and Password for the
SQL Login that you specified when you created the SQL Server. This will be validated with a green
check in the Hub Password box if correctly entered.
The final option for Conflict Resolution is probably the most important here. The two choices are
Hub Wins and Client Wins. This settings refers to what occurs in the situation where both the Hub
and Client (Reference) databases have an update to a table row and which database should win the
tie. I use Hub Wins for my situation because I am only using the Reference database as a passive
copy and I am not actively writing to it therefore any writes to the Reference for me are to be
considered fraudulent or a breach of the SQL Server security and an attempt to compromise the
database integrity.
Configuring a Windows Azure SQL Sync Group
16
The final step in the SQL Data Sync Group wizard is to define the Reference database. Not as the
name would suggest, this is the database which is used as the replica, the copy, mirror or whichever
turn of phrase you prefer to use.
Select the database from the Reference Database picker and ensure you select the database in your
secondary region, West Europe for me. Enter the Username and Password as per your SQL Server
configuration and verify that the password is validated with the green tick. The final option is to
specify the Sync Direction. The three available options are Bi-Directional, Sync to the Hub or Sync
from the Hub. This option dictates the data flow through the Sync Group. In a simple setup like my
own, I use Sync from the Hub ensuring that the Hub is the primary database and that the replica
copy in the secondary location receives updates from the Hub. If your design was utilizing the Sync
Group as a multi-read multi-write configuration then you would want to use Bi-Directional.
Select the Sync Direction option carefully to match the technical design for data flow within your
solution. Selecting the wrong option could result in your application either not being able to write to
SQL or could see inserts and updates to table rows being discarded during a sync update.
Once you have completed the wizard, you will be taken to the SQL Databases Sync view in the
Windows Azure Portal as shown below.
Creating a Sync Group
17
The Sync Group will be shown as created but the status will be Not Ready as we now need to define
the settings for the sync relationship by determining which parts of the database schema are
included or excluded.
Define Sync Group Rules To begin making the Sync Group work for you, click it from the SQL Databases Sync view and select
the Sync Rules tab from the ribbon menu.
Configuring a Windows Azure SQL Sync Group
18
Start off by clicking the Define Sync Rules option in the middle of the screen. This will open the
Define Dataset dialog.
Creating a Sync Group
19
Here we need to select the database which will be used as the initial seed database.
It's important to note that your seed database needs to have a schema consisting of tables and
columns already in place. If you make any changes to the schema in the once the Sync Group is
configured, you will need to review the configuration of the Sync rules on the database and update
the Sync Group with these changes. As this example is a WordPress database install, there is little of
that happening for me to worry about.
Select the database in your primary region, North Europe for my example then select the tick to
have Windows Azure read the schema from that database.
Configuring a Windows Azure SQL Sync Group
20
The schema for the selected database will now be shown. From now on in, we can be super granular
with how we sync the database or we can just throw everything at it. I want the whole database to
be in sync so I am going to be showing you how to sync everything but you could be a little more
picky than I am in your scenario.
Click the Select option from the bottom of the page and then select the Select all the columns in all
the tables sub-option. This will check every column in all of the tables to be included in the sync
relationship. Select the Save button at the bottom to configure this as the Sync Rule for this Sync
Group.
Clicking Save will not only save the configuration but will start the initial seed sync of the databases.
Creating a Sync Group
21
Configure Automatic Sync Once the above is complete, we want to click the Configure link in the ribbon top menu. On the
Configure tab, under the General heading, there is a setting option for Automatic Sync.
Configuring a Windows Azure SQL Sync Group
22
Select the On option for Automatic Sync and then under the Sync Frequency option set an
appropriate interval in Minutes, Hours, Days or Months. Your setting for this will vary according to
how rapidly you want the two databases to converge any changes and how quickly data in your
databases is subject to change. I have my databases set for every 12 Hours.
Synchronising the databases will incur costs as inter-region traffic within Windows Azure is a billable
item. A high frequency synchronisation setting will incur more cost than a low interval so you need to
balance your technical goals against the costs.
Select the Save button to save the changes and to enable the Automatic Sync.
Checking the Status of the Sync Group
23
Checking the Status of the Sync Group Once all of the above has been completed, the Sync Group should now be working away. An
automatic initial sync occurs once you define the Sync Rules which depending on the size of your
database will have already completed by now. Select the Properties link from the top ribbon menu
and you will see the current configuration settings for the Sync Group including the health status and
the time of the last sync.
As you can see, my Sync Group is reporting Good health status and everything looks to be working
but to be sure, we can take a look at the Logs view from the ribbon menu.
Configuring a Windows Azure SQL Sync Group
24
From the Logs view, we can see the event log for the Sync Group. My log has three events to report
that the databases were successfully provisioned and that a sync successfully completed, verifying
that my good health status is indeed good.
With all that done, you've now successfully setup a Windows Azure SQL Data Sync Group. As you can
see, it's not actually that complicated to setup but it's just a matter of getting things done in the
correct order. I hope this helps and I'll be sure to post more about this feature as I use it more for
myself.