Advertisement
Guest User

Running a MySQL Galera cluster on Microsoft Azure

a guest
Dec 5th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. #
  2. # Set up three VMs for a Galera Cluster
  3. #
  4.  
  5.  
  6. # Azure Cmdlet Reference
  7. # http://msdn.microsoft.com/library/azure/jj554330.aspx
  8.  
  9. $subscriptionId = "<your subscription ID here>"
  10. $imageLabel = "Ubuntu Server 14.04 LTS" # One from Get-AzureVMImage | select Label
  11. $datacenter = "West Europe" # change this to your preferred data center, your VNET and storage account have to be set up there as well
  12. $adminuser = "<your linux user name here>"
  13. $adminpass = "<a linux password>"
  14. $instanceSize = "ExtraSmall" # ExtraSmall,Small,Medium,Large,ExtraLarge,A5,A6,A7,A8,A9,Basic_A0,Basic_A1,Basic_A2,Basic_A3,Basic_A4
  15. $storageAccountName = "<the storage account name for the vm harddisk files>"
  16. $vnetname = "<the name of your vnet>"
  17. $subnetname = "<the name of the subnet for the database servers>"
  18.  
  19. $loadBalancerName = "galera-ilb" # should be changed if there are multiple galera clusters
  20. $loadBalancerIP = "10.11.0.10"
  21.  
  22. $servicename = "<your service name>" # all machines will be created in this service
  23. $availabilityset = "galera-as" # should be changed if there are multiple galera clusters
  24.  
  25. #
  26. # Calculate a bunch of properties
  27. #
  28. $subscriptionName = (Get-AzureSubscription | `
  29. select SubscriptionName, SubscriptionId | `
  30. Where-Object SubscriptionId -eq $subscriptionId | `
  31. Select-Object SubscriptionName)[0].SubscriptionName
  32.  
  33. Select-AzureSubscription -SubscriptionName $subscriptionName -Current
  34.  
  35. $imageName = (Get-AzureVMImage | Where Label -eq $imageLabel | Sort-Object -Descending PublishedDate)[0].ImageName
  36.  
  37. $storageAccountKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary
  38.  
  39. $storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
  40.  
  41. #
  42. # Fix the local subscription object
  43. #
  44. Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $storageAccountName
  45.  
  46.  
  47. #
  48. # This function encapsulates the configuration generation of a single new Galera VM
  49. #
  50. Function Get-CustomVM
  51. {
  52. Param (
  53. [string]$customVmName,
  54. [string]$machineIpAddress,
  55. [int]$externalSshPortNumber,
  56. [string] $storageAccountName = $storageContext.StorageAccountName
  57. )
  58.  
  59. #
  60. # configure the VM object
  61. #
  62. $vm = New-AzureVMConfig `
  63. -Name $customVmName `
  64. -InstanceSize $instanceSize `
  65. -ImageName $imageName `
  66. -AvailabilitySetName $availabilityset `
  67. -MediaLocation "https://$storageAccountName.blob.core.windows.net/vhds/$customVmName-OSDisk.vhd" `
  68. -HostCaching "Read" `
  69. | `
  70. Add-AzureProvisioningConfig `
  71. -Linux `
  72. -LinuxUser $adminuser `
  73. -Password $adminpass `
  74. | `
  75. Set-AzureSubnet -SubnetNames $subnetname `
  76. | `
  77. Set-AzureStaticVNetIP -IPAddress $machineIpAddress `
  78. | `
  79. Remove-AzureEndpoint `
  80. -Name SSH `
  81. | `
  82. Add-AzureEndpoint `
  83. -Name SSH `
  84. -LocalPort 22 `
  85. -PublicPort $externalSshPortNumber `
  86. -Protocol tcp `
  87. |`
  88. Add-AzureEndpoint `
  89. -Name mysql `
  90. -LocalPort 3306 `
  91. -PublicPort 3306 `
  92. -InternalLoadBalancerName $loadBalancerName `
  93. -Protocol tcp `
  94. -ProbePort 3306 `
  95. -ProbeProtocol "tcp" `
  96. -ProbeIntervalInSeconds 5 `
  97. -ProbeTimeoutInSeconds 11 `
  98. -LBSetName mysql
  99.  
  100. $vm
  101. }
  102.  
  103. #
  104. # 0. Create cloud service before instantiating internal load balancer
  105. #
  106. if ((Get-AzureService | where ServiceName -eq $servicename) -eq $null) {
  107. Write-Host "Create cloud service"
  108. New-AzureService -ServiceName $servicename -Location $datacenter
  109. }
  110.  
  111. #
  112. # 1. Create a dummyVM with an external endpoint so that the internal load balancer (which is in preview) is willing to be created
  113. #
  114. $dummyVM = New-AzureVMConfig -Name "placeholder" -InstanceSize ExtraSmall -ImageName $imageName `
  115. -MediaLocation "https://$storageAccountName.blob.core.windows.net/vhds/dummy-OSDisk.vhd" -HostCaching "ReadWrite" `
  116. | Add-AzureProvisioningConfig -Linux -LinuxUser $adminuser -Password $adminpass `
  117. | Set-AzureSubnet -SubnetNames $subnetname `
  118. | Set-AzureStaticVNetIP -IPAddress "10.0.1.200"
  119.  
  120. New-AzureVM -ServiceName $servicename -VNetName $vnetname -VMs $dummyVM
  121.  
  122. #
  123. # 2. Create the internal load balancer (no endpoints yet)
  124. #
  125. Add-AzureInternalLoadBalancer -ServiceName $servicename -InternalLoadBalancerName $loadBalancerName –SubnetName $subnetname –StaticVNetIPAddress $loadBalancerIP
  126. if ((Get-AzureInternalLoadBalancer -ServiceName $servicename) -ne $null) {
  127. Write-Host "Created load balancer"
  128. }
  129.  
  130. #
  131. # 3. Create the cluster machines and hook them up to the ILB (without mentioning "-Location $datacenter -VNetName $vnetname ", because the $dummyVM pinned these already
  132. #
  133. $vm1 = Get-CustomVM -customVmName "galera-a" -machineIpAddress "10.11.0.11" -externalSshPortNumber 40011
  134. $vm2 = Get-CustomVM -customVmName "galera-b" -machineIpAddress "10.11.0.12" -externalSshPortNumber 40012
  135. $vm3 = Get-CustomVM -customVmName "galera-c" -machineIpAddress "10.11.0.13" -externalSshPortNumber 40013
  136. New-AzureVM -ServiceName $servicename -VMs $vm1,$vm2,$vm3
  137.  
  138. #
  139. # 4. Delete the dummyVM
  140. #
  141. Remove-AzureVM -ServiceName $servicename -Name $dummyVM.RoleName -DeleteVHD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement