Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Set up three VMs for a Galera Cluster
- #
- # Azure Cmdlet Reference
- # http://msdn.microsoft.com/library/azure/jj554330.aspx
- $subscriptionId = "<your subscription ID here>"
- $imageLabel = "Ubuntu Server 14.04 LTS" # One from Get-AzureVMImage | select Label
- $datacenter = "West Europe" # change this to your preferred data center, your VNET and storage account have to be set up there as well
- $adminuser = "<your linux user name here>"
- $adminpass = "<a linux password>"
- $instanceSize = "ExtraSmall" # ExtraSmall,Small,Medium,Large,ExtraLarge,A5,A6,A7,A8,A9,Basic_A0,Basic_A1,Basic_A2,Basic_A3,Basic_A4
- $storageAccountName = "<the storage account name for the vm harddisk files>"
- $vnetname = "<the name of your vnet>"
- $subnetname = "<the name of the subnet for the database servers>"
- $loadBalancerName = "galera-ilb" # should be changed if there are multiple galera clusters
- $loadBalancerIP = "10.11.0.10"
- $servicename = "<your service name>" # all machines will be created in this service
- $availabilityset = "galera-as" # should be changed if there are multiple galera clusters
- #
- # Calculate a bunch of properties
- #
- $subscriptionName = (Get-AzureSubscription | `
- select SubscriptionName, SubscriptionId | `
- Where-Object SubscriptionId -eq $subscriptionId | `
- Select-Object SubscriptionName)[0].SubscriptionName
- Select-AzureSubscription -SubscriptionName $subscriptionName -Current
- $imageName = (Get-AzureVMImage | Where Label -eq $imageLabel | Sort-Object -Descending PublishedDate)[0].ImageName
- $storageAccountKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary
- $storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
- #
- # Fix the local subscription object
- #
- Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $storageAccountName
- #
- # This function encapsulates the configuration generation of a single new Galera VM
- #
- Function Get-CustomVM
- {
- Param (
- [string]$customVmName,
- [string]$machineIpAddress,
- [int]$externalSshPortNumber,
- [string] $storageAccountName = $storageContext.StorageAccountName
- )
- #
- # configure the VM object
- #
- $vm = New-AzureVMConfig `
- -Name $customVmName `
- -InstanceSize $instanceSize `
- -ImageName $imageName `
- -AvailabilitySetName $availabilityset `
- -MediaLocation "https://$storageAccountName.blob.core.windows.net/vhds/$customVmName-OSDisk.vhd" `
- -HostCaching "Read" `
- | `
- Add-AzureProvisioningConfig `
- -Linux `
- -LinuxUser $adminuser `
- -Password $adminpass `
- | `
- Set-AzureSubnet -SubnetNames $subnetname `
- | `
- Set-AzureStaticVNetIP -IPAddress $machineIpAddress `
- | `
- Remove-AzureEndpoint `
- -Name SSH `
- | `
- Add-AzureEndpoint `
- -Name SSH `
- -LocalPort 22 `
- -PublicPort $externalSshPortNumber `
- -Protocol tcp `
- |`
- Add-AzureEndpoint `
- -Name mysql `
- -LocalPort 3306 `
- -PublicPort 3306 `
- -InternalLoadBalancerName $loadBalancerName `
- -Protocol tcp `
- -ProbePort 3306 `
- -ProbeProtocol "tcp" `
- -ProbeIntervalInSeconds 5 `
- -ProbeTimeoutInSeconds 11 `
- -LBSetName mysql
- $vm
- }
- #
- # 0. Create cloud service before instantiating internal load balancer
- #
- if ((Get-AzureService | where ServiceName -eq $servicename) -eq $null) {
- Write-Host "Create cloud service"
- New-AzureService -ServiceName $servicename -Location $datacenter
- }
- #
- # 1. Create a dummyVM with an external endpoint so that the internal load balancer (which is in preview) is willing to be created
- #
- $dummyVM = New-AzureVMConfig -Name "placeholder" -InstanceSize ExtraSmall -ImageName $imageName `
- -MediaLocation "https://$storageAccountName.blob.core.windows.net/vhds/dummy-OSDisk.vhd" -HostCaching "ReadWrite" `
- | Add-AzureProvisioningConfig -Linux -LinuxUser $adminuser -Password $adminpass `
- | Set-AzureSubnet -SubnetNames $subnetname `
- | Set-AzureStaticVNetIP -IPAddress "10.0.1.200"
- New-AzureVM -ServiceName $servicename -VNetName $vnetname -VMs $dummyVM
- #
- # 2. Create the internal load balancer (no endpoints yet)
- #
- Add-AzureInternalLoadBalancer -ServiceName $servicename -InternalLoadBalancerName $loadBalancerName –SubnetName $subnetname –StaticVNetIPAddress $loadBalancerIP
- if ((Get-AzureInternalLoadBalancer -ServiceName $servicename) -ne $null) {
- Write-Host "Created load balancer"
- }
- #
- # 3. Create the cluster machines and hook them up to the ILB (without mentioning "-Location $datacenter -VNetName $vnetname ", because the $dummyVM pinned these already
- #
- $vm1 = Get-CustomVM -customVmName "galera-a" -machineIpAddress "10.11.0.11" -externalSshPortNumber 40011
- $vm2 = Get-CustomVM -customVmName "galera-b" -machineIpAddress "10.11.0.12" -externalSshPortNumber 40012
- $vm3 = Get-CustomVM -customVmName "galera-c" -machineIpAddress "10.11.0.13" -externalSshPortNumber 40013
- New-AzureVM -ServiceName $servicename -VMs $vm1,$vm2,$vm3
- #
- # 4. Delete the dummyVM
- #
- Remove-AzureVM -ServiceName $servicename -Name $dummyVM.RoleName -DeleteVHD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement