diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml new file mode 100644 index 0000000..efebc00 --- /dev/null +++ b/.idea/codeStyleSettings.xml @@ -0,0 +1,34 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2877737 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 HelloTech + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 9abeeb7..a13826c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,64 @@ -# Azure Patroni Deployment - - + - \ No newline at end of file +http://armviz.io/#/?load=https%3A%2F%2Fraw.githubusercontent.com%2Fhellotech%2Fazure_postgres%2Fmaster%2Ftemplate.json" target="_blank"> + + +# Highly-Available PostgreSQL Cluster (Patroni) on Azure + +This one click deployment of a Highly-Available PostgreSQL Cluster on Azure has automated replication, server management and leader election. This project contains a modified deployment version of Haufe's [blog post](http://dev.haufe.com/PostgreSQL-Cluster-Azure/). + +This Azure template generates two sets of machines both running Ubuntu 16.04 LTS. The first set of three machines are used to run the distributed configuration store [ZooKeeper](https://zookeeper.apache.org/), while the second set is running PostgreSQL 9.6 together with [Patroni](https://github.com/zalando/patroni) providing a high-availability customizable PostgreSQL cluster deployment. This deployment also includes [PL/V8 v.2.0.0](https://github.com/plv8/plv8). + +# Parameters + +This template provides the following parameters, so you can customize your deployment to your needs: + + +* clusterName: What your cluster will be named. + +* _artifactsLocation: The repo name from which you are deploying. Default("https://raw.githubusercontent.com/HelloTech/azure_postgres/master") + +* newVnet: Whether or not you want to create a new vnet. Default("yes") + +* vnetGroup: The resource group in which the vnet is located. If you select yes on newVnet this needs to be set to the resource group in which you are deploying. + +* lbType: Whether you want to create an external or internal load balancer. If set to internal the load balancer will only be accessible from inside the virtual network. Default("internal") + +* vnetName: If newVnet is set to yes, this will be name of the created vnet. Otherwise, this is the name of already existing vnet to which the deployment will be associated. + +* zookeeperNetName: If newVnet is set to yes, this will be name of the created subnet for the zookeeper machines, otherwise this is the name of already existing subnet that will contain the zookeeper vm's. + +* postgresNetName: If newVnet is set to yes, this will be name of the created subnet for the postgres machines, otherwise this is the name of already existing subnet that will contain the postgres vm's. + +* zookeeperVMSize: The size of zookeeper vms. + +* postgresVMSize: The size of the postgres vms. + +* postgresDataSize: The size of the ssd used for pg_data for the postgres vms. + +* instanceCount: The number of postgres vms. + +* adminUsername: The Ubuntu username. + +* adminPassword: The Ubuntu password. + + +# Scripts + +### Zookeeper +The creation of the zookeeper instances is handled by the [zookeeper_startup.sh](https://github.com/HelloTech/azure_postgres/blob/custom_deploy/zookeeper_startup.sh) script. If you would like to make any changes to what is installed on those vm's modify this file. + +### Mounts +The mounting of the data ssds is handled by the [autopart.sh](https://github.com/HelloTech/azure_postgres/blob/custom_deploy/autopart.sh) script. + +### Postgres +The creation of the postgres instance is handles by the [postgres_startup.sh](https://github.com/HelloTech/azure_postgres/blob/custom_deploy/postgres_startup.sh) script. If you would like to make any changes to what is installed on those vm's modify that script. + +### Notes +This deployment can take anywhere from 90 to 120 minutes to complete due to long build time for plv8. + +# License + +Released under the MIT license. See the LICENSE file for more info. \ No newline at end of file diff --git a/backup.json b/backup.json index 3a8ad51..ab89f52 100644 --- a/backup.json +++ b/backup.json @@ -1,556 +1,556 @@ { - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "clusterName": { - "type": "String" - }, - "instanceCount": { - "defaultValue": 2, - "minValue": 2, - "maxValue": 5, - "type": "Int", - "metadata": { - "description": "Number of postgreSQL servers in the cluster." - } - }, - "adminUsername": { - "type": "String" - }, - "adminPassword": { - "type": "SecureString" - } - }, - "variables": { - "storageAccountSuffix": "[concat('vmds', parameters('clusterName'))]", - "storageAccountPrefix": [ - "a", - "g", - "m", - "s", - "y" - ], - "storageAccountType": "Standard_LRS", - "ipName": "[concat(parameters('clusterName'), '-ip')]", - "ipId": "[resourceId('Microsoft.Network/publicIPAddresses/', variables('ipName'))]", - "lbName": "postgresLoadBalancer", - "lbId": "[resourceId('Microsoft.Network/loadBalancers/', variables('lbName'))]", - "vnetName": "[concat(parameters('clusterName'), '-net')]", - "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]", - "zookeeperNetName": "zookeeper-subnet", - "zookeeperInstanceCount": 3, - "postgresNetName": "postgres-subnet", - "postgresInstanceCount": "[parameters('instanceCount')]", - "osType": { - "publisher": "Canonical", - "offer": "UbuntuServer", - "sku": "16.04.0-LTS", - "version": "latest" - } - }, - "resources": [ - { - "type": "Microsoft.Network/virtualNetworks", - "name": "[variables('vnetName')]", - "apiVersion": "2015-06-15", - "location": "[resourceGroup().location]", - "tags": {}, - "properties": { - "addressSpace": { - "addressPrefixes": [ - "10.0.0.0/16" - ] + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "clusterName": { + "type": "String" }, - "subnets": [ - { - "name": "[variables('zookeeperNetName')]", - "properties": { - "addressPrefix": "10.0.100.0/24" - } - }, - { - "name": "[variables('postgresNetName')]", - "properties": { - "addressPrefix": "10.0.101.0/24" - } - } - ] - }, - "dependsOn": [] - }, - { - "type": "Microsoft.Storage/storageAccounts", - "name": "[concat(variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", - "apiVersion": "2015-06-15", - "location": "[resourceGroup().location]", - "copy": { - "name": "storageLoop", - "count": "[length(variables('storageAccountPrefix'))]" - }, - "properties": { - "accountType": "[variables('storageAccountType')]" - } - }, - { - "type": "Microsoft.Storage/storageAccounts", - "name": "[concat(variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix'))]", - "apiVersion": "2015-06-15", - "location": "[resourceGroup().location]", - "copy": { - "name": "storageDataLoop", - "count": "[length(variables('storageAccountPrefix'))]" - }, - "properties": { - "accountType": "Premium_LRS" - } - }, - { - "type": "Microsoft.Network/publicIPAddresses", - "name": "[variables('ipName')]", - "apiVersion": "2016-03-30", - "location": "[resourceGroup().location]", - "properties": { - "publicIPAllocationMethod": "Dynamic", - "dnsSettings": { - "domainNameLabel": "[parameters('clusterName')]" - } - } - }, - { - "type": "Microsoft.Compute/availabilitySets", - "name": "postgresAvailabilitySet", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "properties": {} - }, - { - "type": "Microsoft.Compute/availabilitySets", - "name": "zookeeperAvailabilitySet", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "properties": {} - }, - { - "type": "Microsoft.Network/networkInterfaces", - "name": "[concat('zookeeper', copyIndex(), '-nic')]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "zookeeperNicLoop", - "count": "[variables('zookeeperInstanceCount')]" - }, - "properties": { - "ipConfigurations": [ - { - "name": "zookeeperIp", - "properties": { - "privateIPAllocationMethod": "Static", - "privateIPAddress": "[concat('10.0.100.', copyIndex(10))]", - "subnet": { - "id": "[concat(variables('vnetId'), '/subnets/', variables('zookeeperNetName'))]" - } + "instanceCount": { + "defaultValue": 2, + "minValue": 2, + "maxValue": 5, + "type": "Int", + "metadata": { + "description": "Number of postgreSQL servers in the cluster." } - } - ] - }, - "dependsOn": [ - "[variables('vnetId')]", - "[variables('lbId')]" - ] - }, - { - "type": "Microsoft.Compute/virtualMachines", - "name": "[concat('zookeeper', copyIndex())]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "zookeeperVmLoop", - "count": "[variables('zookeeperInstanceCount')]" - }, - "properties": { - "availabilitySet": { - "id": "[resourceId('Microsoft.Compute/availabilitySets', 'zookeeperAvailabilitySet')]" - }, - "hardwareProfile": { - "vmSize": "Standard_A2" }, - "osProfile": { - "computerName": "[concat('zookeeper', copyIndex())]", - "adminUsername": "[parameters('adminUserName')]", - "adminPassword": "[parameters('adminPassword')]" - }, - "storageProfile": { - "imageReference": { - "publisher": "Canonical", - "offer": "UbuntuServer", - "sku": "16.04.0-LTS", - "version": "latest" - }, - "osDisk": { - "name": "osdisk", - "vhd": { - "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'zookeeperosdisk', copyIndex(), '.vhd')]" - }, - "caching": "ReadWrite", - "createOption": "FromImage" - } + "adminUsername": { + "type": "String" }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', concat('zookeeper', copyIndex(), '-nic'))]" - } - ] - } - }, - "dependsOn": [ - "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", - "[concat('Microsoft.Network/networkInterfaces/', 'zookeeper', copyIndex(), '-nic')]", - "[concat('Microsoft.Compute/availabilitySets/', 'zookeeperAvailabilitySet')]" - ] - }, - { - "type": "Microsoft.Compute/virtualMachines/extensions", - "name": "[concat('zookeeper', copyIndex(), '/zookeeperExtension')]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "zookeeperExtLoop", - "count": "[variables('zookeeperInstanceCount')]" - }, - "properties": { - "publisher": "Microsoft.OSTCExtensions", - "type": "CustomScriptForLinux", - "typeHandlerVersion": "1.2", - "settings": { - "fileUris": [ - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/zookeeper_startup.sh" - ], - "commandToExecute": "[concat('sh zookeeper_startup.sh ', copyIndex(), ' ', variables('zookeeperInstanceCount'))]" + "adminPassword": { + "type": "SecureString" } - }, - "dependsOn": [ - "[concat('Microsoft.Compute/virtualMachines/', 'zookeeper', copyIndex())]" - ] }, - { - "type": "Microsoft.Network/networkInterfaces", - "name": "[concat('postgres', copyIndex(), '-nic')]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "postgresNicLoop", - "count": "[variables('postgresInstanceCount')]" - }, - "properties": { - "ipConfigurations": [ - { - "name": "postgresIp", - "properties": { - "privateIPAllocationMethod": "Static", - "privateIPAddress": "[concat('10.0.101.', copyIndex(10))]", - "subnet": { - "id": "[concat(variables('vnetId'), '/subnets/', variables('postgresNetName'))]" - }, - "loadBalancerBackendAddressPools": [ - { - "id": "[concat(variables('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" - } - ], - "loadBalancerInboundNatRules": [ - { - "id": "[concat(variables('lbId'), '/inboundNatRules/postgresSsh', copyIndex())]" - } - ] - } - } - ] - }, - "dependsOn": [ - "[variables('vnetId')]", - "[variables('lbId')]" - ] - }, - { - "type": "Microsoft.Compute/virtualMachines", - "name": "[concat('postgres', copyIndex())]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "postgresVmLoop", - "count": "[variables('postgresInstanceCount')]" - }, - "properties": { - "availabilitySet": { - "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresAvailabilitySet')]" - }, - "hardwareProfile": { - "vmSize": "Standard_DS1" - }, - "osProfile": { - "computerName": "[concat('postgres', copyIndex())]", - "adminUsername": "[parameters('adminUserName')]", - "adminPassword": "[parameters('adminPassword')]" - }, - "storageProfile": { - "imageReference": { + "variables": { + "storageAccountSuffix": "[concat('vmds', parameters('clusterName'))]", + "storageAccountPrefix": [ + "a", + "g", + "m", + "s", + "y" + ], + "storageAccountType": "Standard_LRS", + "ipName": "[concat(parameters('clusterName'), '-ip')]", + "ipId": "[resourceId('Microsoft.Network/publicIPAddresses/', variables('ipName'))]", + "lbName": "postgresLoadBalancer", + "lbId": "[resourceId('Microsoft.Network/loadBalancers/', variables('lbName'))]", + "vnetName": "[concat(parameters('clusterName'), '-net')]", + "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]", + "zookeeperNetName": "zookeeper-subnet", + "zookeeperInstanceCount": 3, + "postgresNetName": "postgres-subnet", + "postgresInstanceCount": "[parameters('instanceCount')]", + "osType": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "16.04.0-LTS", "version": "latest" - }, - "osDisk": { - "name": "osdisk", - "vhd": { - "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'postgresosdisk', copyIndex(), '.vhd')]" - }, - "caching": "ReadWrite", - "createOption": "FromImage" - }, - "dataDisks": [ - { - "name": "data0", - "diskSizeGB": "128", - "lun": 0, - "vhd": { - "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'data0', copyIndex(), '.vhd')]" - }, - "createOption": "Empty" - } - ] - }, - "networkProfile": { - "networkInterfaces": [ - { - "id": "[resourceId('Microsoft.Network/networkInterfaces', concat('postgres', copyIndex(), '-nic'))]" - } - ] } - }, - "dependsOn": [ - "storageLoop", - "storageDataLoop", - "zookeeperVmLoop", - "zookeeperExtLoop", - "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", - "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix'))]", - "[concat('Microsoft.Network/networkInterfaces/', 'postgres', copyIndex(), '-nic')]", - "[concat('Microsoft.Compute/availabilitySets/', 'postgresAvailabilitySet')]" - ] }, - { - "type": "Microsoft.Compute/virtualMachines/extensions", - "name": "[concat('postgres', copyIndex(), '/postgresExtension')]", - "apiVersion": "2015-05-01-preview", - "location": "[resourceGroup().location]", - "copy": { - "name": "postgresExtLoop", - "count": "[variables('postgresInstanceCount')]" - }, - "properties": { - "publisher": "Microsoft.OSTCExtensions", - "type": "CustomScriptForLinux", - "typeHandlerVersion": "1.2", - "settings": { - "fileUris": [ - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/autopart.sh", - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/postgres_startup.sh" - ], - "commandToExecute": "[concat('sh postgres_startup.sh ', parameters('clusterName'), ' ', variables('zookeeperInstanceCount'), ' ', variables('postgresInstanceCount'), ' ', copyIndex(), ' ', parameters('adminUsername'), ' \"', parameters('adminPassword'), '\" ')]" - } - }, - "dependsOn": [ - "[concat('Microsoft.Compute/virtualMachines/', 'postgres', copyIndex())]" - ] - }, - { - "type": "Microsoft.Network/loadBalancers", - "name": "[variables('lbName')]", - "apiVersion": "2015-06-15", - "location": "[resourceGroup().location]", - "properties": { - "availabilitySet": { - "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresHaAvailabilitySet')]" - }, - "frontendIPConfigurations": [ - { - "name": "loadBalancerFrontEnd", - "properties": { - "publicIPAddress": { - "id": "[variables('ipId')]" - } - } - } - ], - "backendAddressPools": [ - { - "name": "loadBalancerBackEnd" - } - ], - "loadBalancingRules": [ - { - "name": "postgresLbRule", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "backendAddressPool": { - "id": "[concat(variables('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 5432, - "backendPort": 5000, - "probe": { - "id": "[concat(variables('lbId'), '/probes/postgresProbe')]" - } - } - } - ], - "probes": [ - { - "name": "postgresProbe", + "resources": [ + { + "type": "Microsoft.Network/virtualNetworks", + "name": "[variables('vnetName')]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", + "tags": {}, "properties": { - "protocol": "Tcp", - "port": 5000, - "intervalInSeconds": 5, - "numberOfProbes": 2 - } - } - ], - "inboundNatRules": [ - { - "name": "postgresSsh0", + "addressSpace": { + "addressPrefixes": [ + "10.0.0.0/16" + ] + }, + "subnets": [ + { + "name": "[variables('zookeeperNetName')]", + "properties": { + "addressPrefix": "10.0.100.0/24" + } + }, + { + "name": "[variables('postgresNetName')]", + "properties": { + "addressPrefix": "10.0.101.0/24" + } + } + ] + }, + "dependsOn": [] + }, + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[concat(variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", + "copy": { + "name": "storageLoop", + "count": "[length(variables('storageAccountPrefix'))]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10110, - "backendPort": 22 + "accountType": "[variables('storageAccountType')]" } - }, - { - "name": "postgresSsh1", + }, + { + "type": "Microsoft.Storage/storageAccounts", + "name": "[concat(variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix'))]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", + "copy": { + "name": "storageDataLoop", + "count": "[length(variables('storageAccountPrefix'))]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10111, - "backendPort": 22 + "accountType": "Premium_LRS" } - }, - { - "name": "postgresSsh2", + }, + { + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('ipName')]", + "apiVersion": "2016-03-30", + "location": "[resourceGroup().location]", "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10112, - "backendPort": 22 + "publicIPAllocationMethod": "Dynamic", + "dnsSettings": { + "domainNameLabel": "[parameters('clusterName')]" + } } - }, - { - "name": "postgresSsh3", + }, + { + "type": "Microsoft.Compute/availabilitySets", + "name": "postgresAvailabilitySet", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "properties": {} + }, + { + "type": "Microsoft.Compute/availabilitySets", + "name": "zookeeperAvailabilitySet", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "properties": {} + }, + { + "type": "Microsoft.Network/networkInterfaces", + "name": "[concat('zookeeper', copyIndex(), '-nic')]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "zookeeperNicLoop", + "count": "[variables('zookeeperInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10113, - "backendPort": 22 - } - }, - { - "name": "postgresSsh4", + "ipConfigurations": [ + { + "name": "zookeeperIp", + "properties": { + "privateIPAllocationMethod": "Static", + "privateIPAddress": "[concat('10.0.100.', copyIndex(10))]", + "subnet": { + "id": "[concat(variables('vnetId'), '/subnets/', variables('zookeeperNetName'))]" + } + } + } + ] + }, + "dependsOn": [ + "[variables('vnetId')]", + "[variables('lbId')]" + ] + }, + { + "type": "Microsoft.Compute/virtualMachines", + "name": "[concat('zookeeper', copyIndex())]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "zookeeperVmLoop", + "count": "[variables('zookeeperInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10114, - "backendPort": 22 - } - }, - { - "name": "postgresSsh5", + "availabilitySet": { + "id": "[resourceId('Microsoft.Compute/availabilitySets', 'zookeeperAvailabilitySet')]" + }, + "hardwareProfile": { + "vmSize": "Standard_A2" + }, + "osProfile": { + "computerName": "[concat('zookeeper', copyIndex())]", + "adminUsername": "[parameters('adminUserName')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "Canonical", + "offer": "UbuntuServer", + "sku": "16.04.0-LTS", + "version": "latest" + }, + "osDisk": { + "name": "osdisk", + "vhd": { + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'zookeeperosdisk', copyIndex(), '.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + } + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces', concat('zookeeper', copyIndex(), '-nic'))]" + } + ] + } + }, + "dependsOn": [ + "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", + "[concat('Microsoft.Network/networkInterfaces/', 'zookeeper', copyIndex(), '-nic')]", + "[concat('Microsoft.Compute/availabilitySets/', 'zookeeperAvailabilitySet')]" + ] + }, + { + "type": "Microsoft.Compute/virtualMachines/extensions", + "name": "[concat('zookeeper', copyIndex(), '/zookeeperExtension')]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "zookeeperExtLoop", + "count": "[variables('zookeeperInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10115, - "backendPort": 22 - } - }, - { - "name": "postgresSsh6", + "publisher": "Microsoft.OSTCExtensions", + "type": "CustomScriptForLinux", + "typeHandlerVersion": "1.2", + "settings": { + "fileUris": [ + "https://raw.githubusercontent.com/HelloTech/azure_postgres/master/zookeeper_startup.sh" + ], + "commandToExecute": "[concat('sh zookeeper_startup.sh ', copyIndex(), ' ', variables('zookeeperInstanceCount'))]" + } + }, + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', 'zookeeper', copyIndex())]" + ] + }, + { + "type": "Microsoft.Network/networkInterfaces", + "name": "[concat('postgres', copyIndex(), '-nic')]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "postgresNicLoop", + "count": "[variables('postgresInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10116, - "backendPort": 22 - } - }, - { - "name": "postgresSsh7", + "ipConfigurations": [ + { + "name": "postgresIp", + "properties": { + "privateIPAllocationMethod": "Static", + "privateIPAddress": "[concat('10.0.101.', copyIndex(10))]", + "subnet": { + "id": "[concat(variables('vnetId'), '/subnets/', variables('postgresNetName'))]" + }, + "loadBalancerBackendAddressPools": [ + { + "id": "[concat(variables('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" + } + ], + "loadBalancerInboundNatRules": [ + { + "id": "[concat(variables('lbId'), '/inboundNatRules/postgresSsh', copyIndex())]" + } + ] + } + } + ] + }, + "dependsOn": [ + "[variables('vnetId')]", + "[variables('lbId')]" + ] + }, + { + "type": "Microsoft.Compute/virtualMachines", + "name": "[concat('postgres', copyIndex())]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "postgresVmLoop", + "count": "[variables('postgresInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10117, - "backendPort": 22 - } - }, - { - "name": "postgresSsh8", + "availabilitySet": { + "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresAvailabilitySet')]" + }, + "hardwareProfile": { + "vmSize": "Standard_DS1" + }, + "osProfile": { + "computerName": "[concat('postgres', copyIndex())]", + "adminUsername": "[parameters('adminUserName')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "Canonical", + "offer": "UbuntuServer", + "sku": "16.04.0-LTS", + "version": "latest" + }, + "osDisk": { + "name": "osdisk", + "vhd": { + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'postgresosdisk', copyIndex(), '.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + }, + "dataDisks": [ + { + "name": "data0", + "diskSizeGB": "128", + "lun": 0, + "vhd": { + "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'data0', copyIndex(), '.vhd')]" + }, + "createOption": "Empty" + } + ] + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces', concat('postgres', copyIndex(), '-nic'))]" + } + ] + } + }, + "dependsOn": [ + "storageLoop", + "storageDataLoop", + "zookeeperVmLoop", + "zookeeperExtLoop", + "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", + "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix'))]", + "[concat('Microsoft.Network/networkInterfaces/', 'postgres', copyIndex(), '-nic')]", + "[concat('Microsoft.Compute/availabilitySets/', 'postgresAvailabilitySet')]" + ] + }, + { + "type": "Microsoft.Compute/virtualMachines/extensions", + "name": "[concat('postgres', copyIndex(), '/postgresExtension')]", + "apiVersion": "2015-05-01-preview", + "location": "[resourceGroup().location]", + "copy": { + "name": "postgresExtLoop", + "count": "[variables('postgresInstanceCount')]" + }, "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10118, - "backendPort": 22 - } - }, - { - "name": "postgresSsh9", + "publisher": "Microsoft.OSTCExtensions", + "type": "CustomScriptForLinux", + "typeHandlerVersion": "1.2", + "settings": { + "fileUris": [ + "https://raw.githubusercontent.com/HelloTech/azure_postgres/master/autopart.sh", + "https://raw.githubusercontent.com/HelloTech/azure_postgres/master/postgres_startup.sh" + ], + "commandToExecute": "[concat('sh postgres_startup.sh ', parameters('clusterName'), ' ', variables('zookeeperInstanceCount'), ' ', variables('postgresInstanceCount'), ' ', copyIndex(), ' ', parameters('adminUsername'), ' \"', parameters('adminPassword'), '\" ')]" + } + }, + "dependsOn": [ + "[concat('Microsoft.Compute/virtualMachines/', 'postgres', copyIndex())]" + ] + }, + { + "type": "Microsoft.Network/loadBalancers", + "name": "[variables('lbName')]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10119, - "backendPort": 22 - } - } - ] - }, - "dependsOn": [ - "[variables('ipId')]" - ] - } - ], - "outputs": { - "fqdn": { - "type": "String", - "value": "[reference(variables('ipName')).dnsSettings.fqdn]" - }, - "port": { - "type": "Int", - "value": 5432 - }, - "postgresUser": { - "type": "String", - "value": "admin" - }, - "postgresUserPassword": { - "type": "SecureString", - "value": "[parameters('adminPassword')]" + "availabilitySet": { + "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresHaAvailabilitySet')]" + }, + "frontendIPConfigurations": [ + { + "name": "loadBalancerFrontEnd", + "properties": { + "publicIPAddress": { + "id": "[variables('ipId')]" + } + } + } + ], + "backendAddressPools": [ + { + "name": "loadBalancerBackEnd" + } + ], + "loadBalancingRules": [ + { + "name": "postgresLbRule", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "backendAddressPool": { + "id": "[concat(variables('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 5432, + "backendPort": 5000, + "probe": { + "id": "[concat(variables('lbId'), '/probes/postgresProbe')]" + } + } + } + ], + "probes": [ + { + "name": "postgresProbe", + "properties": { + "protocol": "Tcp", + "port": 5000, + "intervalInSeconds": 5, + "numberOfProbes": 2 + } + } + ], + "inboundNatRules": [ + { + "name": "postgresSsh0", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10110, + "backendPort": 22 + } + }, + { + "name": "postgresSsh1", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10111, + "backendPort": 22 + } + }, + { + "name": "postgresSsh2", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10112, + "backendPort": 22 + } + }, + { + "name": "postgresSsh3", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10113, + "backendPort": 22 + } + }, + { + "name": "postgresSsh4", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10114, + "backendPort": 22 + } + }, + { + "name": "postgresSsh5", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10115, + "backendPort": 22 + } + }, + { + "name": "postgresSsh6", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10116, + "backendPort": 22 + } + }, + { + "name": "postgresSsh7", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10117, + "backendPort": 22 + } + }, + { + "name": "postgresSsh8", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10118, + "backendPort": 22 + } + }, + { + "name": "postgresSsh9", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10119, + "backendPort": 22 + } + } + ] + }, + "dependsOn": [ + "[variables('ipId')]" + ] + } + ], + "outputs": { + "fqdn": { + "type": "String", + "value": "[reference(variables('ipName')).dnsSettings.fqdn]" + }, + "port": { + "type": "Int", + "value": 5432 + }, + "postgresUser": { + "type": "String", + "value": "admin" + }, + "postgresUserPassword": { + "type": "SecureString", + "value": "[parameters('adminPassword')]" + } } - } } \ No newline at end of file diff --git a/nestedtemplates/empty-resources.json b/nestedtemplates/empty-resources.json new file mode 100644 index 0000000..23a54f2 --- /dev/null +++ b/nestedtemplates/empty-resources.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "vnetName": { + "type": "String", + "defaultValue": "" + }, + "zookeeperNetName": { + "type": "String", + "defaultValue": "" + }, + "postgresNetName": { + "type": "String", + "defaultValue": "" + } + }, + "variables": {}, + "resources": [], + "outputs": {} +} diff --git a/nestedtemplates/external-lb.json b/nestedtemplates/external-lb.json new file mode 100644 index 0000000..3c57da1 --- /dev/null +++ b/nestedtemplates/external-lb.json @@ -0,0 +1,215 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "clusterName": { + "type": "String", + "defaultValue": "" + }, + "lbName": { + "type": "String", + "defaultValue": "" + }, + "lbId": { + "type": "String", + "defaultValue": "" + }, + "vnetId": { + "type": "String", + "defaultValue": "" + }, + "postgresNetName": { + "defaultValue": "", + "type": "String" + } + }, + "variables": { + "ipName": "[concat(parameters('clusterName'), '-ip')]", + "ipId": "[resourceId('Microsoft.Network/publicIPAddresses/', variables('ipName'))]" + }, + "resources": [ + { + "type": "Microsoft.Network/publicIPAddresses", + "name": "[variables('ipName')]", + "apiVersion": "2016-03-30", + "location": "[resourceGroup().location]", + "properties": { + "publicIPAllocationMethod": "Dynamic", + "dnsSettings": { + "domainNameLabel": "[parameters('clusterName')]" + } + } + }, + { + "type": "Microsoft.Network/loadBalancers", + "name": "[parameters('lbName')]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", + "properties": { + "availabilitySet": { + "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresHaAvailabilitySet')]" + }, + "frontendIPConfigurations": [ + { + "name": "loadBalancerFrontEnd", + "properties": { + "publicIPAddress": { + "id": "[variables('ipId')]" + } + } + } + ], + "backendAddressPools": [ + { + "name": "loadBalancerBackEnd" + } + ], + "loadBalancingRules": [ + { + "name": "postgresLbRule", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "backendAddressPool": { + "id": "[concat(parameters('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 5432, + "backendPort": 5000, + "probe": { + "id": "[concat(parameters('lbId'), '/probes/postgresProbe')]" + } + } + } + ], + "probes": [ + { + "name": "postgresProbe", + "properties": { + "protocol": "Tcp", + "port": 5000, + "intervalInSeconds": 5, + "numberOfProbes": 2 + } + } + ], + "inboundNatRules": [ + { + "name": "postgresSsh0", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10110, + "backendPort": 22 + } + }, + { + "name": "postgresSsh1", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10111, + "backendPort": 22 + } + }, + { + "name": "postgresSsh2", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10112, + "backendPort": 22 + } + }, + { + "name": "postgresSsh3", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10113, + "backendPort": 22 + } + }, + { + "name": "postgresSsh4", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10114, + "backendPort": 22 + } + }, + { + "name": "postgresSsh5", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10115, + "backendPort": 22 + } + }, + { + "name": "postgresSsh6", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10116, + "backendPort": 22 + } + }, + { + "name": "postgresSsh7", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10117, + "backendPort": 22 + } + }, + { + "name": "postgresSsh8", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10118, + "backendPort": 22 + } + }, + { + "name": "postgresSsh9", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10119, + "backendPort": 22 + } + } + ] + }, + "dependsOn": [ + "[variables('ipId')]" + ] + } + ] +} \ No newline at end of file diff --git a/nestedtemplates/internal-lb.json b/nestedtemplates/internal-lb.json new file mode 100644 index 0000000..5be73e4 --- /dev/null +++ b/nestedtemplates/internal-lb.json @@ -0,0 +1,199 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "clusterName": { + "type": "String", + "defaultValue": "" + }, + "lbName": { + "type": "String", + "defaultValue": "" + }, + "lbId": { + "type": "String", + "defaultValue": "" + }, + "vnetId": { + "type": "String", + "defaultValue": "" + }, + "postgresNetName": { + "defaultValue": "", + "type": "String" + } + }, + "variables": {}, + "resources": [ + { + "type": "Microsoft.Network/loadBalancers", + "name": "[parameters('lbName')]", + "apiVersion": "2015-06-15", + "location": "[resourceGroup().location]", + "properties": { + "availabilitySet": { + "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresHaAvailabilitySet')]" + }, + "frontendIPConfigurations": [ + { + "name": "LoadBalancerFrontEnd", + "properties": { + "privateIPAddress": "10.0.101.4", + "privateIPAllocationMethod": "Static", + "subnet": { + "id": "[concat(parameters('vnetId'), '/subnets/', parameters('postgresNetName'))]" + } + } + } + ], + "backendAddressPools": [ + { + "name": "loadBalancerBackEnd" + } + ], + "loadBalancingRules": [ + { + "name": "postgresLbRule", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "backendAddressPool": { + "id": "[concat(parameters('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 5432, + "backendPort": 5000, + "probe": { + "id": "[concat(parameters('lbId'), '/probes/postgresProbe')]" + } + } + } + ], + "probes": [ + { + "name": "postgresProbe", + "properties": { + "protocol": "Tcp", + "port": 5000, + "intervalInSeconds": 5, + "numberOfProbes": 2 + } + } + ], + "inboundNatRules": [ + { + "name": "postgresSsh0", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10110, + "backendPort": 22 + } + }, + { + "name": "postgresSsh1", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10111, + "backendPort": 22 + } + }, + { + "name": "postgresSsh2", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10112, + "backendPort": 22 + } + }, + { + "name": "postgresSsh3", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10113, + "backendPort": 22 + } + }, + { + "name": "postgresSsh4", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10114, + "backendPort": 22 + } + }, + { + "name": "postgresSsh5", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10115, + "backendPort": 22 + } + }, + { + "name": "postgresSsh6", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10116, + "backendPort": 22 + } + }, + { + "name": "postgresSsh7", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10117, + "backendPort": 22 + } + }, + { + "name": "postgresSsh8", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10118, + "backendPort": 22 + } + }, + { + "name": "postgresSsh9", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(parameters('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" + }, + "protocol": "Tcp", + "frontendPort": 10119, + "backendPort": 22 + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/nestedtemplates/network-resources.json b/nestedtemplates/network-resources.json new file mode 100644 index 0000000..cdb9014 --- /dev/null +++ b/nestedtemplates/network-resources.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "vnetName": { + "type": "String", + "defaultValue": "" + }, + "zookeeperNetName": { + "type": "String", + "defaultValue": "" + }, + "postgresNetName": { + "type": "String", + "defaultValue": "" + } + }, + "variables": { + }, + "resources": [ + { + "type": "Microsoft.Network/virtualNetworks", + "name": "[parameters('vnetName')]", + "apiVersion": "2016-03-30", + "location": "[resourceGroup().location]", + "tags": {}, + "properties": { + "addressSpace": { + "addressPrefixes": [ + "10.0.0.0/16" + ] + }, + "subnets": [ + { + "name": "[parameters('zookeeperNetName')]", + "properties": { + "addressPrefix": "10.0.100.0/24" + } + }, + { + "name": "[parameters('postgresNetName')]", + "properties": { + "addressPrefix": "10.0.101.0/24" + } + } + ] + }, + "dependsOn": [] + } + ] +} \ No newline at end of file diff --git a/postgres_startup.sh b/postgres_startup.sh index 3aae507..71c9d83 100644 --- a/postgres_startup.sh +++ b/postgres_startup.sh @@ -25,6 +25,8 @@ sudo chmod +x ./autopart.sh >> /usr/local/startup.log sudo ./autopart.sh >> /usr/local/startup.log sudo mkdir /media/data1/data sudo chmod 777 /media/data1/data +echo "/media/data1/data partition created" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # create RAID #sudo apt-get --assume-yes -qq install mdadm @@ -38,7 +40,10 @@ sudo chmod 777 /media/data1/data sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add - sudo apt-get -qq update +sudo apt-get --assume-yes -qq install jq echo "apt-get update exited with: $?" +echo "updated packages" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # install python @@ -72,16 +77,30 @@ sudo pip -q install tzlocal echo "pip tzlocal exited with: $?" sudo pip -q install python-dateutil echo "pip python-dateutil exited with: $?" - +echo "installed python" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # install postgres # prevent postgres from autostart #sudo touch /usr/sbin/policy-rc.d #sudo chmod 777 /usr/sbin/policy-rc.d #echo exit 101 > /usr/sbin/policy-rc.d -sudo apt-get --assume-yes --force-yes -qq install postgresql postgresql-contrib -echo "apt-get postgresql postgresql-contrib exited with: $?" +sudo apt-get --assume-yes --force-yes -qq install postgresql postgresql-contrib postgresql-server-dev-9.6 +echo "apt-get postgresql postgresql-server-dev-9.6 postgresql-contrib exited with: $?" export PATH=/usr/lib/postgresql/9.6/bin:$PATH +echo "installed postgres" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log + +#install plv8 +wget https://github.com/plv8/plv8/archive/v2.0.0.tar.gz +tar -xvzf v2.0.0.tar.gz +cd plv8-2.0.0 +make static +sudo cp plv8.so /usr/lib/postgresql/9.6/lib/ +sudo cp plv8.control /usr/share/postgresql/9.6/extension/ +sudo cp plv8--2.0.0.sql /usr/share/postgresql/9.6/extension/ +echo "installed plv8" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # download patroni sudo apt-get --assume-yes -qq install unzip @@ -90,6 +109,8 @@ cd /usr/local sudo wget -O /usr/local/patroni-master.zip https://github.com/zalando/patroni/archive/master.zip sudo unzip patroni-master.zip cd patroni-master +echo "download patroni" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # write configuration sudo touch $patroniCfg @@ -120,32 +141,32 @@ echo "" >> $patroniCfg if [ $myIndex -eq 0 ] then echo "bootstrap:" >> $patroniCfg - echo " dcs:" >> $patroniCfg - echo " ttl: *ttl" >> $patroniCfg - echo " loop_wait: *loop_wait" >> $patroniCfg - echo " retry_timeout: *loop_wait" >> $patroniCfg - echo " maximum_lag_on_failover: 1048576" >> $patroniCfg - echo " postgresql:" >> $patroniCfg - echo " use_pg_rewind: true" >> $patroniCfg - echo " use_slots: true" >> $patroniCfg - echo " parameters:" >> $patroniCfg - echo " archive_mode: \"on\"" >> $patroniCfg - echo " archive_timeout: 1800s" >> $patroniCfg - echo " archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f" >> $patroniCfg - echo " recovery_conf:" >> $patroniCfg - echo " restore_command: cp ../wal_archive/%f %p" >> $patroniCfg - echo " initdb:" >> $patroniCfg - echo " - encoding: UTF8" >> $patroniCfg - echo " - data-checksums" >> $patroniCfg - echo " pg_hba:" >> $patroniCfg - echo " - host replication all 0.0.0.0/0 md5" >> $patroniCfg - echo " - host all all 0.0.0.0/0 md5" >> $patroniCfg - echo " users:" >> $patroniCfg - echo " admin:" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " options:" >> $patroniCfg - echo " - createrole" >> $patroniCfg - echo " - createdb" >> $patroniCfg + echo " dcs:" >> $patroniCfg + echo " ttl: *ttl" >> $patroniCfg + echo " loop_wait: *loop_wait" >> $patroniCfg + echo " retry_timeout: *loop_wait" >> $patroniCfg + echo " maximum_lag_on_failover: 1048576" >> $patroniCfg + echo " postgresql:" >> $patroniCfg + echo " use_pg_rewind: true" >> $patroniCfg + echo " use_slots: true" >> $patroniCfg + echo " parameters:" >> $patroniCfg + echo " archive_mode: \"on\"" >> $patroniCfg + echo " archive_timeout: 1800s" >> $patroniCfg + echo " archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f" >> $patroniCfg + echo " recovery_conf:" >> $patroniCfg + echo " restore_command: cp ../wal_archive/%f %p" >> $patroniCfg + echo " initdb:" >> $patroniCfg + echo " - encoding: UTF8" >> $patroniCfg + echo " - data-checksums" >> $patroniCfg + echo " pg_hba:" >> $patroniCfg + echo " - host replication all 0.0.0.0/0 md5" >> $patroniCfg + echo " - host all all 0.0.0.0/0 md5" >> $patroniCfg + echo " users:" >> $patroniCfg + echo " admin:" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " options:" >> $patroniCfg + echo " - createrole" >> $patroniCfg + echo " - createdb" >> $patroniCfg fi echo "" >> $patroniCfg echo "tags:" >> $patroniCfg @@ -161,57 +182,60 @@ fi echo " listen: '*:5433'" >> $patroniCfg echo " connect_address: 10.0.101.$(($myIndex + 10)):5433" >> $patroniCfg echo " data_dir: /media/data1/data/postgresql" >> $patroniCfg +echo " bin_dir: /usr/lib/postgresql/9.6/bin" >> $patroniCfg echo " pgpass: /tmp/pgpass" >> $patroniCfg if [ $myIndex -ne 0 ] then echo " maximum_lag_on_failover: 1048576" >> $patroniCfg - echo " use_slots: true" >> $patroniCfg - echo " initdb:" >> $patroniCfg - echo " - encoding: UTF8" >> $patroniCfg - echo " - data-checksums" >> $patroniCfg - echo " pg_rewind:" >> $patroniCfg - echo " username: postgres" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " pg_hba:" >> $patroniCfg - echo " - host replication all 0.0.0.0/0 md5" >> $patroniCfg - echo " - host all all 0.0.0.0/0 md5" >> $patroniCfg - echo " replication:" >> $patroniCfg - echo " username: replicator" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " superuser:" >> $patroniCfg - echo " username: postgres" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " admin:" >> $patroniCfg - echo " username: admin" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " create_replica_method:" >> $patroniCfg - echo " - basebackup" >> $patroniCfg - echo " recovery_conf:" >> $patroniCfg - echo " restore_command: cp ../wal_archive/%f %p" >> $patroniCfg - echo " parameters:" >> $patroniCfg - echo " archive_mode: \"on\"" >> $patroniCfg - echo " wal_level: hot_standby" >> $patroniCfg - echo " archive_command: mkdir -r ../wal_archive && test ! -f ../wal_archive/%f && cp %cp ../wal_archive/%f" >> $patroniCfg - echo " max_wal_senders: 10" >> $patroniCfg - echo " wal_keep_segments: 8" >> $patroniCfg - echo " archive_timeout: 1800s" >> $patroniCfg - echo " max_replication_slots: 10" >> $patroniCfg - echo " hot_standby: \"on\"" >> $patroniCfg - echo " wal_log_hints: \"on\"" >> $patroniCfg - echo " unix_socket_directories: '.'" >> $patroniCfg + echo " use_slots: true" >> $patroniCfg + echo " initdb:" >> $patroniCfg + echo " - encoding: UTF8" >> $patroniCfg + echo " - data-checksums" >> $patroniCfg + echo " pg_rewind:" >> $patroniCfg + echo " username: postgres" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " pg_hba:" >> $patroniCfg + echo " - host replication all 0.0.0.0/0 md5" >> $patroniCfg + echo " - host all all 0.0.0.0/0 md5" >> $patroniCfg + echo " replication:" >> $patroniCfg + echo " username: replicator" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " superuser:" >> $patroniCfg + echo " username: postgres" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " admin:" >> $patroniCfg + echo " username: admin" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " create_replica_method:" >> $patroniCfg + echo " - basebackup" >> $patroniCfg + echo " recovery_conf:" >> $patroniCfg + echo " restore_command: cp ../wal_archive/%f %p" >> $patroniCfg + echo " parameters:" >> $patroniCfg + echo " archive_mode: \"on\"" >> $patroniCfg + echo " wal_level: hot_standby" >> $patroniCfg + echo " archive_command: mkdir -r ../wal_archive && test ! -f ../wal_archive/%f && cp %cp ../wal_archive/%f" >> $patroniCfg + echo " max_wal_senders: 10" >> $patroniCfg + echo " wal_keep_segments: 8" >> $patroniCfg + echo " archive_timeout: 1800s" >> $patroniCfg + echo " max_replication_slots: 10" >> $patroniCfg + echo " hot_standby: \"on\"" >> $patroniCfg + echo " wal_log_hints: \"on\"" >> $patroniCfg + echo " unix_socket_directories: '.'" >> $patroniCfg else echo " authentication:" >> $patroniCfg - echo " replication:" >> $patroniCfg - echo " username: replicator" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " superuser:" >> $patroniCfg - echo " username: postgres" >> $patroniCfg - echo " password: \"$adminPassword\"" >> $patroniCfg - echo " parameters:" >> $patroniCfg - echo " unix_socket_directories: '.'" >> $patroniCfg + echo " replication:" >> $patroniCfg + echo " username: replicator" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " superuser:" >> $patroniCfg + echo " username: postgres" >> $patroniCfg + echo " password: \"$adminPassword\"" >> $patroniCfg + echo " parameters:" >> $patroniCfg + echo " unix_socket_directories: '.'" >> $patroniCfg fi - - +echo "setup patroni configuration" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log + + # install HA PROXY sudo apt-get --assume-yes install haproxy # write configuration @@ -242,15 +266,46 @@ do echo " server Postgres$i 10.0.101.$(($i + 10)):5433 maxconn 100 check port 8008" >> $hacfgFile i=$(($i+1)) done +echo "installed haproxy" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # start ha as deamon sudo haproxy -D -f $hacfgFile +echo "started haproxy" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # prepare patroni to restart after reboot -sudo chmod 777 /etc/rc.local -echo "sudo haproxy -D -f /usr/local/patroni-master/$hacfgFile" > /etc/rc.local -echo "su -s /bin/bash -c 'export PATH=/usr/lib/postgresql/9.6/bin:\$PATH; /usr/local/patroni-master/patroni.py /usr/local/patroni-master/$patroniCfg >> /usr/local/startup.log' $adminUsername" >> /etc/rc.local -echo "exit 0" >> /etc/rc.local +sudo touch /etc/systemd/system/patroni.service +sudo chmod 777 /etc/systemd/system/patroni.service +echo "[Unit]" > /etc/systemd/system/patroni.service +echo "Description=patroni script" >> /etc/systemd/system/patroni.service +echo "" >> /etc/systemd/system/patroni.service +echo "[Service]" >> /etc/systemd/system/patroni.service +echo "User=$adminUsername" >> /etc/systemd/system/patroni.service +echo "WorkingDirectory=usr/local/patroni-master" >> /etc/systemd/system/patroni.service +echo "ExecStart=/usr/bin/python /usr/local/patroni-master/patroni.py /usr/local/patroni-master/postgres.yml >> /usr/local/startup.log" >> /etc/systemd/system/patroni.service +echo "Restart=always" >> /etc/systemd/system/patroni.service +echo "" >> /etc/systemd/system/patroni.service +echo "[Install]" >> /etc/systemd/system/patroni.service +echo "WantedBy=multi-user.target" >> /etc/systemd/system/patroni.service +sudo systemctl enable patroni.service +echo "setup reboot script for patroni" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log + +# prepare haproxy to restart after reboot +sudo chmod 777 /etc/default/haproxy +echo "ENABLED=1" >> /etc/default/haproxy +echo "CONFIG=\"/usr/local/patroni-master/postgresha.cfg\"" >> /etc/default/haproxy +sudo chmod 644 /etc/default/haproxy +echo "setup reboot config for haproxy" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log + +# start haproxy +sudo haproxy -D -f /usr/local/patroni-master/postgresha.cfg +echo "started haproxy" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log # start patroni -su -c "export PATH=/usr/lib/postgresql/9.6/bin:$PATH; ./patroni.py $patroniCfg >> /usr/local/startup.log" $adminUsername & echo "spawned" +sudo systemctl start patroni.service +echo "started patroni" >> /usr/local/startup.log +echo "" >> /usr/local/startup.log \ No newline at end of file diff --git a/template.json b/template.json index e97d107..76adb15 100644 --- a/template.json +++ b/template.json @@ -5,6 +5,119 @@ "clusterName": { "type": "String" }, + "_artifactsLocation": { + "type": "string", + "defaultValue": "https://raw.githubusercontent.com/HelloTech/azure_postgres/master", + "metadata": { + "description": "Change this value to your repo name if deploying from a fork" + } + }, + "vnetGroup": { + "type": "String", + "metadata": { + "description": "VNET Resource Group." + } + }, + "newVnet": { + "type": "string", + "defaultValue": "yes", + "allowedValues": [ + "yes", + "no" + ], + "metadata": { + "description": "Would you like to create a new vnet?" + } + }, + "lbType": { + "type": "string", + "defaultValue": "internal", + "allowedValues": [ + "internal", + "external" + ], + "metadata": { + "description": "Would you like to create an internal or external load balancer?" + } + }, + "vnetName": { + "defaultValue": "", + "type": "String", + "metadata": { + "description": "Name of the vnet you would like to create, or that you would like to deploy this into." + } + }, + "zookeeperNetName": { + "defaultValue": "dcos-agentPublicSubnet", + "type": "String", + "metadata": { + "description": "Name you would like to give to zookeeper's subnet." + } + }, + "postgresNetName": { + "defaultValue": "dcos-agentPublicSubnet", + "type": "String", + "metadata": { + "description": "Name you would like to give to postgres' subnet." + } + }, + "zookeeperVMSize": { + "type": "string", + "defaultValue": "Standard_A3", + "allowedValues": [ + "Standard_D2_v2", + "Standard_D3_v2", + "Standard_D4_v2", + "Standard_D12_v2", + "Standard_A2", + "Standard_A3", + "Standard_A4", + "Standard_A5", + "Standard_A6", + "Standard_A7", + "Standard_DS2", + "Standard_DS3", + "Standard_DS4", + "Standard_DS12", + "Standard_DS13", + "Standard_DS14" + ], + "metadata": { + "description": "Size of the zookeeper vm's" + } + }, + "postgresVMSize": { + "type": "string", + "defaultValue": "Standard_DS12", + "allowedValues": [ + "Standard_D2_v2", + "Standard_D3_v2", + "Standard_D4_v2", + "Standard_D12_v2", + "Standard_A2", + "Standard_A3", + "Standard_A4", + "Standard_A5", + "Standard_A6", + "Standard_A7", + "Standard_DS2", + "Standard_DS3", + "Standard_DS4", + "Standard_DS12", + "Standard_DS13", + "Standard_DS14" + ], + "metadata": { + "description": "Size of the postgres vm's" + } + }, + "postgresDataSize": { + "defaultValue": 256, + "type": "Int", + "metadata": { + "description": "Size of the postgres data ssd in GB." + } + }, "instanceCount": { "defaultValue": 2, "minValue": 2, @@ -30,15 +143,20 @@ "s", "y" ], + "nestedTemplates": "[concat(parameters('_artifactsLocation'), '/nestedtemplates/')]", "storageAccountType": "Standard_LRS", "lbName": "postgresLoadBalancer", + "vnetFile": { + "yes": "network-resources.json", + "no": "empty-resources.json" + }, + "lbFile": { + "external": "external-lb.json", + "internal": "internal-lb.json" + }, "lbId": "[resourceId('Microsoft.Network/loadBalancers/', variables('lbName'))]", - "vnetName": "dcos-vnet-F0547AD4", - "vnetGroup": "testht", - "vnetId": "[resourceId(variables('vnetGroup'), 'Microsoft.Network/virtualNetworks', variables('vnetName'))]", - "zookeeperNetName": "dcos-agentPublicSubnet", + "vnetId": "[resourceId(parameters('vnetGroup'), 'Microsoft.Network/virtualNetworks', parameters('vnetName'))]", "zookeeperInstanceCount": 3, - "postgresNetName": "dcos-agentPublicSubnet", "postgresInstanceCount": "[parameters('instanceCount')]", "osType": { "publisher": "Canonical", @@ -48,6 +166,29 @@ } }, "resources": [ + { + "type": "Microsoft.Resources/deployments", + "name": "vnet", + "apiVersion": "2015-01-01", + "properties": { + "mode": "Incremental", + "templateLink": { + "uri": "[concat(variables('nestedTemplates'), variables('vnetFile')[parameters('newVnet')])]", + "contentVersion": "1.0.0.0" + }, + "parameters": { + "vnetName": { + "value": "[parameters('vnetName')]" + }, + "zookeeperNetName": { + "value": "[parameters('zookeeperNetName')]" + }, + "postgresNetName": { + "value": "[parameters('postgresNetName')]" + } + } + } + }, { "type": "Microsoft.Storage/storageAccounts", "name": "[concat(variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", @@ -105,14 +246,15 @@ "privateIPAllocationMethod": "Static", "privateIPAddress": "[concat('10.0.100.', copyIndex(10))]", "subnet": { - "id": "[concat(variables('vnetId'), '/subnets/', variables('zookeeperNetName'))]" + "id": "[concat(variables('vnetId'), '/subnets/', parameters('zookeeperNetName'))]" } } } ] }, "dependsOn": [ - "[variables('lbId')]" + "[resourceId('Microsoft.Resources/deployments', 'vnet')]", + "[resourceId('Microsoft.Resources/deployments', 'lb-temp')]" ] }, { @@ -129,7 +271,7 @@ "id": "[resourceId('Microsoft.Compute/availabilitySets', 'zookeeperAvailabilitySet')]" }, "hardwareProfile": { - "vmSize": "Standard_A2" + "vmSize": "[parameters('zookeeperVMSize')]" }, "osProfile": { "computerName": "[concat('zookeeper', copyIndex())]", @@ -163,6 +305,7 @@ "dependsOn": [ "[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], variables('storageAccountSuffix'))]", "[concat('Microsoft.Network/networkInterfaces/', 'zookeeper', copyIndex(), '-nic')]", + "[resourceId('Microsoft.Resources/deployments', 'vnet')]", "[concat('Microsoft.Compute/availabilitySets/', 'zookeeperAvailabilitySet')]" ] }, @@ -181,7 +324,7 @@ "typeHandlerVersion": "1.2", "settings": { "fileUris": [ - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/zookeeper_startup.sh" + "[concat(parameters('_artifactsLocation'), '/zookeeper_startup.sh')]" ], "commandToExecute": "[concat('sh zookeeper_startup.sh ', copyIndex(), ' ', variables('zookeeperInstanceCount'))]" } @@ -207,7 +350,7 @@ "privateIPAllocationMethod": "Static", "privateIPAddress": "[concat('10.0.101.', copyIndex(10))]", "subnet": { - "id": "[concat(variables('vnetId'), '/subnets/', variables('postgresNetName'))]" + "id": "[concat(variables('vnetId'), '/subnets/', parameters('postgresNetName'))]" }, "loadBalancerBackendAddressPools": [ { @@ -224,7 +367,8 @@ ] }, "dependsOn": [ - "[variables('lbId')]" + "[resourceId('Microsoft.Resources/deployments', 'vnet')]", + "[resourceId('Microsoft.Resources/deployments', 'lb-temp')]" ] }, { @@ -241,7 +385,7 @@ "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresAvailabilitySet')]" }, "hardwareProfile": { - "vmSize": "Standard_DS1" + "vmSize": "[parameters('postgresVMSize')]" }, "osProfile": { "computerName": "[concat('postgres', copyIndex())]", @@ -266,7 +410,7 @@ "dataDisks": [ { "name": "data0", - "diskSizeGB": "128", + "diskSizeGB": "[parameters('postgresDataSize')]", "lun": 0, "vhd": { "uri": "[concat(reference(concat('Microsoft.Storage/storageAccounts/', variables('storageAccountPrefix')[copyIndex()], 'd', variables('storageAccountSuffix')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).primaryEndpoints.blob, 'vhds/', 'data0', copyIndex(), '.vhd')]" @@ -309,8 +453,8 @@ "typeHandlerVersion": "1.2", "settings": { "fileUris": [ - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/autopart.sh", - "https://raw.githubusercontent.com/HelloTech/azure_patroni/master/postgres_startup.sh" + "[concat(parameters('_artifactsLocation'), '/autopart.sh')]", + "[concat(parameters('_artifactsLocation'), '/postgres_startup.sh')]" ], "commandToExecute": "[concat('sh postgres_startup.sh ', parameters('clusterName'), ' ', variables('zookeeperInstanceCount'), ' ', variables('postgresInstanceCount'), ' ', copyIndex(), ' ', parameters('adminUsername'), ' \"', parameters('adminPassword'), '\" ')]" } @@ -320,174 +464,36 @@ ] }, { - "type": "Microsoft.Network/loadBalancers", - "name": "[variables('lbName')]", - "apiVersion": "2015-06-15", - "location": "[resourceGroup().location]", + "type": "Microsoft.Resources/deployments", + "name": "lb-temp", + "apiVersion": "2015-01-01", "properties": { - "availabilitySet": { - "id": "[resourceId('Microsoft.Compute/availabilitySets', 'postgresHaAvailabilitySet')]" + "mode": "Incremental", + "templateLink": { + "uri": "[concat(variables('nestedTemplates'), variables('lbFile')[parameters('lbType')])]", + "contentVersion": "1.0.0.0" }, - "frontendIPConfigurations": [ - { - "name": "LoadBalancerFrontEnd", - "properties": { - "privateIPAddress": "10.0.101.4", - "privateIPAllocationMethod": "Static", - "subnet": { - "id": "[concat(variables('vnetId'), '/subnets/', variables('zookeeperNetName'))]" - } - } - } - ], - "backendAddressPools": [ - { - "name": "loadBalancerBackEnd" - } - ], - "loadBalancingRules": [ - { - "name": "postgresLbRule", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "backendAddressPool": { - "id": "[concat(variables('lbId'), '/backendAddressPools/loadBalancerBackEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 5432, - "backendPort": 5000, - "probe": { - "id": "[concat(variables('lbId'), '/probes/postgresProbe')]" - } - } - } - ], - "probes": [ - { - "name": "postgresProbe", - "properties": { - "protocol": "Tcp", - "port": 5000, - "intervalInSeconds": 5, - "numberOfProbes": 2 - } - } - ], - "inboundNatRules": [ - { - "name": "postgresSsh0", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10110, - "backendPort": 22 - } - }, - { - "name": "postgresSsh1", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10111, - "backendPort": 22 - } - }, - { - "name": "postgresSsh2", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10112, - "backendPort": 22 - } - }, - { - "name": "postgresSsh3", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10113, - "backendPort": 22 - } - }, - { - "name": "postgresSsh4", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10114, - "backendPort": 22 - } + "parameters": { + "clusterName": { + "value": "[parameters('clusterName')]" }, - { - "name": "postgresSsh5", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10115, - "backendPort": 22 - } + "lbName": { + "value": "[variables('lbName')]" }, - { - "name": "postgresSsh6", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10116, - "backendPort": 22 - } - }, - { - "name": "postgresSsh7", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10117, - "backendPort": 22 - } + "lbId": { + "value": "[variables('lbId')]" }, - { - "name": "postgresSsh8", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10118, - "backendPort": 22 - } + "vnetId": { + "value": "[variables('vnetId')]" }, - { - "name": "postgresSsh9", - "properties": { - "frontendIPConfiguration": { - "id": "[concat(variables('lbId'), '/frontendIPConfigurations/loadBalancerFrontEnd')]" - }, - "protocol": "Tcp", - "frontendPort": 10119, - "backendPort": 22 - } + "postgresNetName": { + "value": "[parameters('postgresNetName')]" } - ] - } + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Resources/deployments', 'vnet')]" + ] } ], "outputs": {