Files
azuredatastudio/extensions/azurehybridtoolkit/notebooks/hybridbook/content/hadr/configure-failover.ipynb
Christopher C 0108da2a24 Cavonac/params (#14264)
* visual consistent
added variable table

* typo

* update variables and code

* variable descriptions

* typos

* typo

* added next steps

* identifying param cells

* updates to readme and removing orphaned notebooks

Co-authored-by: Alex Ma <alma1@microsoft.com>
2021-02-23 13:36:09 -08:00

392 lines
19 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"metadata": {
"kernelspec": {
"name": "powershell",
"display_name": "PowerShell",
"language": "powershell"
},
"language_info": {
"name": "powershell",
"codemirror_mode": "shell",
"mimetype": "text/x-sh",
"file_extension": ".ps1"
}
},
"nbformat_minor": 2,
"nbformat": 4,
"cells": [
{
"cell_type": "markdown",
"source": [
"# Create and configure Failover Cluster\n",
"\n",
"## Description\n",
"\n",
"Notebook to walk through creating a failover cluster on on-premises SQL Server Database."
],
"metadata": {
"azdata_cell_guid": "6af59d69-ade7-480a-b33e-52a86fe5bfd3"
}
},
{
"cell_type": "markdown",
"source": [
"Note: before running the steps below, make sure to have the following:\n",
"\n",
"- A resource group with a domain controller.\n",
"- One or more domain joined VMs in Azure running SQL Server 2016 (or later) in the _same_ availability set or _different_ availability zones that have been registered with the SQL IaaS Agent extension\n",
"- Domain joined VMs must have either a \"Enterprise\" or \"Developer\" image SKU to create a cluster in this notebook\n",
"\n",
"Refer to the Tutorial on [How to Setup a Domain with VMs in Azure](https://docs.microsoft.com/azure/azure-sql/virtual-machines/windows/availability-group-manually-configure-prerequisites-tutorial) (only follow the steps up to setting the SQL Server Service Accounts)\n",
"\n",
"Here is a listing of variables that will be used to create the failover cluster:\n",
"\n",
"| Line # | Name | Description | Example |\n",
"| --- | --- | --- | --- |\n",
"| 1 | **Subscription** | Azure Subscription ID/Name with permission to host a domain. | ToolsSubscription_1234 |\n"
"| 2 | **ResourceGroup** | Name of new or existing resource group (RG). An Azure Resource Group is a collection of Azure resources that share the same permissions, policies, etc. | \"TestRG1\" |\n",
"| 3 | **Location** | Value representing the region or location of the RG. See [Azure Geographies](https://azure.microsoft.com/global-infrastructure/geographies/) for more information. | \"East US\" |\n",
"| 4 | **Publisher** | Name of publisher that offers SQL Server configurations that can be installed on virtual machines. Default is MicrosoftSQLServer | \"MicrosoftSQLServer\" |\n",
"| 5 | **StorageAccountName** | Name of the storage account that will be used as a file share witness. See [Cloud Witness](https://docs.microsoft.com/windows-server/failover-clustering/deploy-cloud-witness) for more information. | \"TestStorageAccount\" |\n",
"| 6 | **StorageSku** | Name of SKU for a storage account. There are SKUs for different types of storage such as Standard\\_LRS for Standard Locally Redundant Storage. See [Storage Redundancy](https://docs.microsoft.com/azure/storage/common/storage-redundancy) for more information. | \"Standard\\_LRS\" |\n",
"| 7 | **ClusterName** | Name of the failover cluster that will be created. A failover cluster is a group of independent computers that work together to increase the availability and scalability of clustered roles. See [Failover Cluster](https://docs.microsoft.com/windows-server/failover-clustering/failover-clustering-overview) for more information. | \"TestCluster\" |\n",
"| 8 | **FQDN** | Fully Qualified Domain Name, this localized URL address is created as shown in the domain setup. | \"domain.testsite.com\" |\n",
"| 9 | **ServerSku** | Edition of SQL Server, each has different capabilities based on purpose, only supported versions are Enterprise or Developer. | \"Enterprise\" |\n",
"| 10 | **ServiceAccount** | Username for the SQL server service account for the domain (password is required to run commands). Any active directory account with sufficient permissions such as the installation account may be used as the service account. (will be used on all SQL VMs running in the cluster) | \"serviceaccount@domain.testsite.com\" |\n",
"| 11 | **OperatorAccount** | Username for the cluster operator account, may or may not be the same as the service account. (will be used on all SQL VMs running in the cluster) | \"operatoraccount@domain.testsite.com\" |\n",
"| 12 | **BootstrapAccount** | Username for the bootstrap account, may or may not be the same as the service account. (will be used on all SQL VMs running in the cluster) | \"bootstrapaccount@domain.testsite.com\" |"
],
"metadata": {
"azdata_cell_guid": "b911ea4f-a3d8-4ac1-bff6-6c5eb1b514f9"
}
},
{
"cell_type": "code",
"source": [
"#Set general parameters\r\n",
"$Subscription = \"\"\r\n"
"$ResourceGroup = \"\"\r\n"
"$Location = \"\"\r\n"
"$Publisher = \"\"\r\n"
"\r\n",
"#Create Storage Account\r\n",
"$StorageAccountName = \"\"\r\n",
"$StorageSku = \"\"\r\n",
"\r\n",
"#Define Cluster Media\r\n",
"$ClusterName = \"\"\r\n",
"$FQDN = \"\"\r\n",
"$ServerSku = \"\"\r\n",
"\r\n",
"#Add VMs to the cluster\r\n",
"$ServiceAccount = \"\"\r\n",
"$ServiceAccountPassword = \"\"\r\n",
"$OperatorAccount = \"\"\r\n",
"$OperatorAccountPassword = \"\"\r\n",
"$BootstrapAccount = \"\"\r\n",
"$BootstrapAccountPassword = \"\"
],
"metadata": {
"azdata_cell_guid": "7ad525ec-4993-4e14-9677-4f77433b2123",
"tags": [
"parameters"
]
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"Steps of this procedure include:\n",
"\n",
"1. Connect to Azure subscription\n",
"2. Provision resource group for SQL VM migration\n",
"3. Create a storage account\n",
"4. Define cluster metadata\n",
"5. Add VMs to the cluster\n",
"6. Validate cluster"
],
"metadata": {
"azdata_cell_guid": "34dad8cf-9457-474c-b6a3-34b003e9c71a"
}
},
{
"cell_type": "markdown",
"source": [
"### **Set Subscription**\r\n",
"Set the subscription for rest of the commands."
],
"metadata": {
"azdata_cell_guid": "cc6cb8c6-76b7-41a0-ab26-7713e72c2f7d"
}
},
{
"cell_type": "code",
"source": [
"if(!$Subscription){\r\n",
" $Subscription = Get-AzSubscription | Out-GridView -PassThru\r\n",
"}\r\n",
"\r\n",
"Set-AzContext -SubscriptionName $Subscription\r\n",
"Connect-AzAccount -Subscription $Subscription"
],
"metadata": {
"azdata_cell_guid": "741c35fa-7923-4200-8c3a-497d62b4ae66"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"\r\n",
"### **Create a resource group**\r\n",
"Create an Azure resource group with _New-AzResourceGroup_. A resource group is a logical container into which Azure resources are deployed and managed."
],
"metadata": {
"azdata_cell_guid": "455a6002-e5d5-4cb0-9146-8d417917c751"
}
},
{
"cell_type": "code",
"source": [
"# Create Azure resource group, if necessary\r\n",
"if (!(Get-AzResourceGroup -Name $ResourceGroup))\r\n",
"{\r\n",
" # Need to create a new resource group\r\n",
" Write-Output \"Resource Group $ResourceGroup does not exist. Creating...\"\r\n",
" New-AzResourceGroup -Name $ResourceGroup -Location $Location\r\n",
"}"
],
"metadata": {
"azdata_cell_guid": "d48948e1-3136-4e42-91e7-77a3301ae97d"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Create a storage account**\r\n",
"Create a standard, general-purpose storage account with LRS replication by using _New-AzStorageAccount_. Next, get the storage account context that defines the storage account you want to use. When acting on a storage account, reference the context instead of repeatedly passing in the credentials. Use the following example to create a storage account called storageaccountazure with locally redundant storage (LRS) and blob encryption (enabled by default)."
],
"metadata": {
"azdata_cell_guid": "246d062f-e7d1-4f42-ba9f-153a12a286e4"
}
},
{
"cell_type": "code",
"source": [
"$StorageAccount = New-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName `\r\n",
" -SkuName $StorageSku -Location $Location -Kind StorageV2 `\r\n",
" -AccessTier Hot -EnableHttpsTrafficOnly $true\r\n",
"\r\n",
"$Ctx = $StorageAccount.Context"
],
"metadata": {
"azdata_cell_guid": "17e3421b-a80a-455c-bd6a-25daaff46514"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Create a container**\r\n",
"Blobs are always uploaded into a container. Blobs can be organized in groups like files in folders.\r\n",
"Set the container name, then create the container by using _New-AzStorageContainer_. Set the permissions to blob to allow public access of the files. The container name in this example is quickstartblobs."
],
"metadata": {
"azdata_cell_guid": "82503754-84ea-47b7-bcaf-31e5012da008"
}
},
{
"cell_type": "code",
"source": [
"$ContainerName = \"quickstartblobs\"\r\n",
"New-AzStorageContainer -Name $ContainerName -Context $Ctx -Permission blob"
],
"metadata": {
"azdata_cell_guid": "c4557040-5ff7-4f31-9243-01b850270b90",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Get Azure Storage Acount Key**\r\n",
"This script will get the key for Storage Account which is been created."
],
"metadata": {
"azdata_cell_guid": "f48b23bf-01bc-48df-afed-ad3eea69c41d"
}
},
{
"cell_type": "code",
"source": [
"$StorageAccountKey = `\r\n",
" (Get-AzStorageAccountKey `\r\n",
" -ResourceGroupName $ResourceGroup `\r\n",
" -Name $StorageAccountName).Value[0]"
],
"metadata": {
"azdata_cell_guid": "e450bc4a-3373-4c7e-b0d0-f334712298b2",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Get Azure Storage Container Uri**\r\n",
"The following script can be used to get the Uri of Storage container."
],
"metadata": {
"azdata_cell_guid": "5f7e616b-1e9f-4640-b61f-78d4327c5562"
}
},
{
"cell_type": "code",
"source": [
" $StorageUri = (Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName | Get-AzStorageContainer | Where-Object { $_.Name -eq $AzureContainerName }).CloudBlobContainer.Uri.AbsoluteUri "
],
"metadata": {
"azdata_cell_guid": "615d8e6e-2cbf-4001-8da0-1826185a06bf"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Azure SQL VM Offers**\n",
"\n",
"Run the following command to get updated list of offers for Microsoft SQL Server in your location. Pick the offer that matches the operating system version of the VM servers.\n",
"\n",
"Note that the SQL Version is first then appended with an operating system version. E.g.: \"WS2019\" means Windows Server 2019. Along with various versions of Windows Servers, there are also enterprise Linux versions such as RedHat Enterprise, Suse Enterprise, and Ubuntu. Some versions are BYOL (Bring Your Own License) aka [Hybrid Benefit](https://azure.microsoft.com/pricing/hybrid-benefit/)."
],
"metadata": {
"azdata_cell_guid": "c17d224e-e514-4dfd-b181-06d2cde378e4"
}
},
{
"cell_type": "code",
"source": [
"$Offer = Get-AzVMImageOffer -Location $Location -Publisher $Publisher | Out-GridView -PassThru"
],
"metadata": {
"azdata_cell_guid": "6b2fa291-43cb-4619-a010-3a373dababcc"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Define cluster metadata**\n",
"\n",
"The following script is used to define the metadata for Windows Server Failover Cluster so that when the first SQL Server VM is added, the cluster is created as defined."
],
"metadata": {
"azdata_cell_guid": "000a1320-fecf-4e0b-8d1f-00ab39fc44ce"
}
},
{
"cell_type": "code",
"source": [
"$StorageAccountUrl = \"https://$StorageAccountName.blob.core.windows.net/\"\r\n",
"$SecureSAKey = ConvertTo-SecureString $StorageAccountKey -AsPlainText -Force\r\n",
"if($OperatorAccount -eq \"\"){\r\n",
" $OperatorAccount = $ServiceAccount\r\n",
" $SecureOAPassword = ConvertTo-SecureString $ServiceAccountPassword -AsPlainText -Force\r\n",
"}\r\n",
"if($BootstrapAccount -eq \"\"){\r\n",
" $BootstrapAccount = $ServiceAccount\r\n",
" $SecureBAPassword = ConvertTo-SecureString $ServiceAccountPassword -AsPlainText -Force\r\n",
"}\r\n",
"\r\n",
"$group = New-AzSqlVMGroup -Name $ClusterName -Location $Location `\r\n",
" -ResourceGroupName $ResourceGroup -Offer $Offer.Offer `\r\n",
" -Sku $ServerSku -DomainFqdn $FQDN -ClusterOperatorAccount $OperatorAccount `\r\n",
" -ClusterBootstrapAccount $BootstrapAccount -SqlServiceAccount $ServiceAccount `\r\n",
" -StorageAccountUrl $StorageAccountUrl `\r\n",
" -StorageAccountPrimaryKey $SecureSAKey"
],
"metadata": {
"azdata_cell_guid": "f59b2416-a41f-43c0-85ea-1e113e6f4221",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Select a VM to add to the cluster**\n",
"\n",
"Selecting and adding the first SQL Server VM to the cluster creates the cluster. Additional SQL Server VM nodes can be added by running this cell again. **(This will take some time, please wait for the process to finish.)**"
],
"metadata": {
"azdata_cell_guid": "cca91ca6-bf10-4e32-9b4f-80133049c1b5"
}
},
{
"cell_type": "code",
"source": [
"$sqlvm = Get-AzSqlVM -ResourceGroupName $ResourceGroup | Out-GridView -PassThru\r\n",
"$SecureSAPassword = ConvertTo-SecureString $ServiceAccountPassword -AsPlainText -Force\r\n",
"if(!$SecureOAPassword){\r\n",
" $SecureOAPassword = $SecureSAPassword\r\n",
"}\r\n",
"if(!$SecureBAPassword){\r\n",
" $SecureBAPassword = $SecureSAPassword\r\n",
"}\r\n",
"\r\n",
"$sqlvmconfig = Set-AzSqlVMConfigGroup -SqlVM $sqlvm `\r\n",
" -SqlVMGroup $group -ClusterOperatorAccountPassword $SecureOAPassword `\r\n",
" -SqlServiceAccountPassword $SecureSAPassword `\r\n",
" -ClusterBootstrapAccountPassword $SecureBAPassword\r\n",
"\r\n",
"Update-AzSqlVM -ResourceId $sqlvm.ResourceId -SqlVM $sqlvmconfig"
],
"metadata": {
"azdata_cell_guid": "9b21ab69-5be2-4d09-ac4b-3d43521a1188",
"tags": []
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### **Validate Failover Cluster**\n",
"\n",
"After adding all the nodes to the cluster, connect to the virtual machine (ex. RDP) using an administrator account to run the following command via PowerShell:\n",
"\n",
"**Test-Cluster**\n",
"\n",
"The cluster must pass validation to be supported by Microsoft. Failure to do so leaves your cluster in an unsupported state."
],
"metadata": {
"azdata_cell_guid": "3ce199e7-f88f-4592-b61c-e03ed2c7235a"
}
},
{
"cell_type": "markdown",
"source": [
"### **Post cluster creation steps**\n",
"\n",
"You can add additional nodes in the following notebook, then verify after doing so.\n",
"\n",
"Once all the desired SQL VMs in the domain have been added as nodes and the cluster verified, proceed to creating the [availability group](.\\configure-ag.ipynb)"
],
"metadata": {
"azdata_cell_guid": "0d7d63f0-ef95-4e40-9139-69957c53e85f"
}
}
]
}