diff --git a/extensions/server_beta.sh b/extensions/server_beta.sh new file mode 100755 index 0000000..fa6691b --- /dev/null +++ b/extensions/server_beta.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +echo "Running server.sh" + +version=$1 +adminUsername=$2 +adminPassword=$3 +uniqueString=$4 +location=$5 +analyticsNodesMod=$6 + +echo "Using the settings:" +echo version \'$version\' +echo adminUsername \'$adminUsername\' +echo adminPassword \'$adminPassword\' +echo uniqueString \'$uniqueString\' +echo location \'$location\' + +echo "Installing prerequisites..." +apt-get update +apt-get -y install python-httplib2 +apt-get -y install jq + +echo "Installing Couchbase Server..." +wget http://packages.couchbase.com/releases/${version}/couchbase-server-enterprise_${version}-ubuntu14.04_amd64.deb +dpkg -i couchbase-server-enterprise_${version}-ubuntu14.04_amd64.deb +apt-get update +apt-get -y install couchbase-server + +echo "Calling util.sh..." +source util.sh +formatDataDisk +turnOffTransparentHugepages +setSwappinessToZero +adjustTCPKeepalive + +echo "Configuring Couchbase Server..." + +# We can get the index directly with this, but unsure how to test for sucess. Come back to later... +#nodeIndex = `curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute/name?api-version=2017-04-02&format=text"` +# good example here https://github.com/bonggeek/Samples/blob/master/imds/imds.sh + +nodeIndex="null" +while [[ $nodeIndex == "null" ]] +do + nodeIndex=`curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-04-02" \ + | jq ".name" \ + | sed 's/.*_//' \ + | sed 's/"//'` +done + +nodeDNS='vm'$nodeIndex'.server-'$uniqueString'.'$location'.cloudapp.azure.com' +rallyDNS='vm0.server-'$uniqueString'.'$location'.cloudapp.azure.com' + +echo "Adding an entry to /etc/hosts to simulate split brain DNS..." +echo " +# Simulate split brain DNS for Couchbase +127.0.0.1 ${nodeDNS} +" >> /etc/hosts + +cd /opt/couchbase/bin/ + +echo "Running couchbase-cli node-init" +./couchbase-cli node-init \ + --cluster=$nodeDNS \ + --node-init-hostname=$nodeDNS \ + --node-init-data-path=/datadisk/data \ + --node-init-index-path=/datadisk/index \ + --user=$adminUsername \ + --pass=$adminPassword + +if [[ $nodeIndex == "0" ]] +then + totalRAM=$(grep MemTotal /proc/meminfo | awk '{print $2}') + dataRAM=$((50 * $totalRAM / 100000)) + indexRAM=$((15 * $totalRAM / 100000)) + + echo "Running couchbase-cli cluster-init" + ./couchbase-cli cluster-init \ + --cluster=$nodeDNS \ + --cluster-ramsize=$dataRAM \ + --cluster-index-ramsize=$indexRAM \ + --cluster-username=$adminUsername \ + --cluster-password=$adminPassword \ + --services=data,index,query,fts,analytics +else + echo "Running couchbase-cli server-add" + output="" + while [[ $output != "Server $nodeDNS:8091 added" && ! $output =~ "Node is already part of cluster." ]] + do + if [[ (analyticsNodesMod % ($nodeIndex + 1)) -ne 0 ]] + then + output=`./couchbase-cli server-add \ + --cluster=$rallyDNS \ + --user=$adminUsername \ + --pass=$adminPassword \ + --server-add=$nodeDNS \ + --server-add-username=$adminUsername \ + --server-add-password=$adminPassword \ + --services=data,index,query,fts` + else + output=`./couchbase-cli server-add \ + --cluster=$rallyDNS \ + --user=$adminUsername \ + --pass=$adminPassword \ + --server-add=$nodeDNS \ + --server-add-username=$adminUsername \ + --server-add-password=$adminPassword \ + --services=analytics` + fi + echo server-add output \'$output\' + sleep 10 + done + + echo "Running couchbase-cli rebalance" + output="" + while [[ ! $output =~ "SUCCESS" ]] + do + output=`./couchbase-cli rebalance \ + --cluster=$rallyDNS \ + --user=$adminUsername \ + --pass=$adminPassword` + echo rebalance output \'$output\' + sleep 10 + done + +fi diff --git a/simple/deploy_beta.sh b/simple/deploy_beta.sh new file mode 100755 index 0000000..e70c381 --- /dev/null +++ b/simple/deploy_beta.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +RESOURCE_GROUP=$1 + +az group create --name $RESOURCE_GROUP --location westus --output table +az group deployment create --verbose --template-file mainTemplate_beta.json --parameters @mainTemplateParameters_beta.json --resource-group $RESOURCE_GROUP --output table diff --git a/simple/mainTemplateParameters_beta.json b/simple/mainTemplateParameters_beta.json new file mode 100644 index 0000000..81fc3d8 --- /dev/null +++ b/simple/mainTemplateParameters_beta.json @@ -0,0 +1,32 @@ +{ + "serverNodeCount": { + "value": 2 + }, + "analyticsNodeCount": { + "value": 2 + }, + "serverDiskSize": { + "value": 32 + }, + "serverVersion": { + "value": "6.0.0-beta" + }, + "syncGatewayNodeCount": { + "value": 0 + }, + "syncGatewayVersion": { + "value": "2.1.0" + }, + "vmSize": { + "value": "Standard_DS3_v2" + }, + "adminUsername": { + "value": "couchbase" + }, + "adminPassword": { + "value": "foo123!" + }, + "license": { + "value": "byol" + } +} diff --git a/simple/mainTemplate_beta.json b/simple/mainTemplate_beta.json new file mode 100644 index 0000000..1ca6825 --- /dev/null +++ b/simple/mainTemplate_beta.json @@ -0,0 +1,441 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "serverNodeCount": { + "type": "int" + }, + "analyticsNodeCount": { + "type": "int" + }, + "serverDiskSize": { + "type": "int" + }, + "serverVersion": { + "type": "string" + }, + "syncGatewayNodeCount": { + "type": "int" + }, + "syncGatewayVersion": { + "type": "string" + }, + "vmSize": { + "type": "string" + }, + "adminUsername": { + "type": "string" + }, + "adminPassword": { + "type": "securestring" + }, + "license": { + "type": "string" + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + } + }, + "variables": { + "extensionUrl": "https://raw.githubusercontent.com/couchbase-partners/azure-resource-manager-couchbase/master/extensions/", + "uniqueString": "[uniquestring(resourceGroup().id, deployment().name)]" + }, + "resources": [ + { + "apiVersion": "2017-05-10", + "type": "Microsoft.Resources/deployments", + "name": "pid-bac94ebc-cc78-4dbd-bc39-4b5433e1014c", + "properties": { + "mode": "Incremental", + "template": { + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "resources": [] + } + } + }, + { + "apiVersion": "2016-06-01", + "type": "Microsoft.Network/networkSecurityGroups", + "name": "networksecuritygroups", + "location": "[parameters('location')]", + "properties": { + "securityRules": [ + { + "name": "SSH", + "properties": { + "description": "SSH", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "22", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 100, + "direction": "Inbound" + } + }, + { + "name": "ErlangPortMapper", + "properties": { + "description": "Erlang Port Mapper (epmd)", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "4369", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 101, + "direction": "Inbound" + } + }, + { + "name": "SyncGateway", + "properties": { + "description": "Sync Gateway", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "4984-4985", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 102, + "direction": "Inbound" + } + }, + { + "name": "Server", + "properties": { + "description": "Server", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "8091-8096", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 103, + "direction": "Inbound" + } + }, + { + "name": "Index", + "properties": { + "description": "Index", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "9100-9105", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 104, + "direction": "Inbound" + } + }, + { + "name": "Analytics", + "properties": { + "description": "Analytics", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "9110-9122", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 105, + "direction": "Inbound" + } + }, + { + "name": "Internal", + "properties": { + "description": "Internal", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "9998-9999", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 106, + "direction": "Inbound" + } + }, + { + "name": "XDCR", + "properties": { + "description": "XDCR", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "11207-11215", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 107, + "direction": "Inbound" + } + }, + { + "name": "SSL", + "properties": { + "description": "SSL", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "18091-18096", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 108, + "direction": "Inbound" + } + }, + { + "name": "NodeDataExchange", + "properties": { + "description": "Node data exchange", + "protocol": "Tcp", + "sourcePortRange": "*", + "destinationPortRange": "21100-21299", + "sourceAddressPrefix": "Internet", + "destinationAddressPrefix": "*", + "access": "Allow", + "priority": 109, + "direction": "Inbound" + } + } + ] + } + }, + { + "name": "vnet", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2015-06-15", + "location": "[parameters('location')]", + "dependsOn": [ + "Microsoft.Network/networkSecurityGroups/networksecuritygroups" + ], + "properties": { + "addressSpace": { + "addressPrefixes": [ + "10.0.0.0/8" + ] + }, + "subnets": [ + { + "name": "subnet", + "properties": { + "addressPrefix": "10.0.0.0/16", + "networkSecurityGroup": { + "id": "[resourceId('Microsoft.Network/networkSecurityGroups', 'networksecuritygroups')]" + } + } + } + ] + } + }, + { + "type": "Microsoft.Compute/virtualMachineScaleSets", + "name": "server", + "location": "[parameters('location')]", + "apiVersion": "2017-03-30", + "dependsOn": [ + "Microsoft.Network/virtualNetworks/vnet" + ], + "plan": { + "publisher": "couchbase", + "product": "couchbase-server-enterprise", + "name": "[parameters('license')]" + }, + "sku": { + "name": "[parameters('vmSize')]", + "tier": "Standard", + "capacity": "[mul(parameters('serverNodeCount'), parameters('analyticsNodeCount'))]" + }, + "properties": { + "overprovision": false, + "upgradePolicy": { + "mode": "Manual" + }, + "virtualMachineProfile": { + "storageProfile": { + "osDisk": { + "createOption": "FromImage" + }, + "imageReference": { + "publisher": "couchbase", + "offer": "couchbase-server-enterprise", + "sku": "[parameters('license')]", + "version": "latest" + }, + "dataDisks": [ + { + "lun": "0", + "createOption": "empty", + "managedDisk": { + "storageAccountType": "Premium_LRS" + }, + "caching": "None", + "diskSizeGB": "[parameters('serverDiskSize')]" + } + ] + }, + "osProfile": { + "computerNamePrefix": "server", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "networkProfile": { + "networkInterfaceConfigurations": [ + { + "name": "nic", + "properties": { + "primary": true, + "ipConfigurations": [ + { + "name": "ipconfig", + "properties": { + "subnet": { + "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', 'vnet'), '/subnets/subnet')]" + }, + "publicipaddressconfiguration": { + "name": "public", + "properties": { + "idleTimeoutInMinutes": 30, + "dnsSettings": { + "domainNameLabel": "[concat('server-', variables('uniqueString'))]" + } + } + } + } + } + ] + } + } + ] + }, + "extensionProfile": { + "extensions": [ + { + "name": "extension", + "properties": { + "publisher": "Microsoft.Azure.Extensions", + "type": "CustomScript", + "typeHandlerVersion": "2.0", + "autoUpgradeMinorVersion": true, + "settings": { + "fileUris": [ + "[concat(variables('extensionUrl'), 'server_beta.sh')]", + "[concat(variables('extensionUrl'), 'util.sh')]" + ], + "commandToExecute": "[concat('bash server.sh ', parameters('serverVersion'), ' ', parameters('adminUsername'), ' ', parameters('adminPassword'), ' ', variables('uniqueString'), ' ', parameters('location'), ' ', parameters('analyticsNodeCount'))]" + } + } + } + ] + } + } + } + }, + { + "type": "Microsoft.Compute/virtualMachineScaleSets", + "name": "syncgateway", + "location": "[parameters('location')]", + "apiVersion": "2017-03-30", + "dependsOn": [ + "Microsoft.Network/virtualNetworks/vnet" + ], + "plan": { + "publisher": "couchbase", + "product": "couchbase-sync-gateway-enterprise", + "name": "[parameters('license')]" + }, + "sku": { + "name": "[parameters('vmSize')]", + "tier": "Standard", + "capacity": "[parameters('syncGatewayNodeCount')]" + }, + "properties": { + "overprovision": false, + "upgradePolicy": { + "mode": "Manual" + }, + "virtualMachineProfile": { + "storageProfile": { + "osDisk": { + "createOption": "FromImage" + }, + "imageReference": { + "publisher": "couchbase", + "offer": "couchbase-sync-gateway-enterprise", + "sku": "[parameters('license')]", + "version": "latest" + } + }, + "osProfile": { + "computerNamePrefix": "syncgateway", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "networkProfile": { + "networkInterfaceConfigurations": [ + { + "name": "nic", + "properties": { + "primary": "true", + "ipConfigurations": [ + { + "name": "ipconfig", + "properties": { + "subnet": { + "id": "[concat(resourceId('Microsoft.Network/virtualNetworks/', 'vnet'), '/subnets/subnet')]" + }, + "publicipaddressconfiguration": { + "name": "public", + "properties": { + "idleTimeoutInMinutes": 30, + "dnsSettings": { + "domainNameLabel": "[concat('syncgateway-', variables('uniqueString'))]" + } + } + } + } + } + ] + } + } + ] + }, + "extensionProfile": { + "extensions": [ + { + "name": "extension", + "properties": { + "publisher": "Microsoft.Azure.Extensions", + "type": "CustomScript", + "typeHandlerVersion": "2.0", + "autoUpgradeMinorVersion": true, + "settings": { + "fileUris": [ + "[concat(variables('extensionUrl'), 'syncGateway.sh')]", + "[concat(variables('extensionUrl'), 'util.sh')]" + ], + "commandToExecute": "[concat('bash syncGateway.sh ', parameters('syncGatewayVersion'))]" + } + } + } + ] + } + } + } + } + ], + "outputs": { + "serverAdminURL": { + "type": "string", + "value": "[concat('http://vm0.server-', variables('uniqueString'), '.', parameters('location'), '.cloudapp.azure.com:8091')]" + }, + "syncGatewayAdminURL": { + "type": "string", + "value": "[concat('http://vm0.syncgateway-', variables('uniqueString'), '.', parameters('location'), '.cloudapp.azure.com:4985/_admin/')]" + } + } +}