diff --git a/generator/deploy.sh b/generator/deploy.sh index f904737..3d4fd2f 100755 --- a/generator/deploy.sh +++ b/generator/deploy.sh @@ -7,20 +7,20 @@ STACK_NAME=$2 python generator.py parameters/${PARAMETERS_FILE}.yaml TEMPLATE_BODY="file://generated.template" -REGION=`aws configure get region` - -Username="couchbase" -Password="foo123!" -KeyName="couchbase-${REGION}" -License="BYOL" - -aws cloudformation create-stack \ ---capabilities CAPABILITY_IAM \ ---template-body ${TEMPLATE_BODY} \ ---stack-name ${STACK_NAME} \ ---region ${REGION} \ ---parameters \ -ParameterKey=Username,ParameterValue=${Username} \ -ParameterKey=Password,ParameterValue=${Password} \ -ParameterKey=KeyName,ParameterValue=${KeyName} \ -ParameterKey=License,ParameterValue=${License} +# REGION=`aws configure get region` +# +# Username="couchbase" +# Password="foo123!" +# KeyName="couchbase-${REGION}" +# License="BYOL" +# +# aws cloudformation create-stack \ +# --capabilities CAPABILITY_IAM \ +# --template-body ${TEMPLATE_BODY} \ +# --stack-name ${STACK_NAME} \ +# --region ${REGION} \ +# --parameters \ +# ParameterKey=Username,ParameterValue=${Username} \ +# ParameterKey=Password,ParameterValue=${Password} \ +# ParameterKey=KeyName,ParameterValue=${KeyName} \ +# ParameterKey=License,ParameterValue=${License} diff --git a/generator/generator.py b/generator/generator.py index 9ec5df9..38a5daa 100644 --- a/generator/generator.py +++ b/generator/generator.py @@ -26,10 +26,26 @@ def main(): "Description": "Name of an existing EC2 KeyPair", "Type": "AWS::EC2::KeyPair::KeyName" }, + "VpcId": { + "Type": "AWS::EC2::VPC::Id", + "Description": "VpcId of your existing Virtual Private Cloud (VPC)", + "ConstraintDescription": "must be the VPC Id of an existing Virtual Private Cloud." + }, + "Subnets": { + "Type": "List", + "Description": "The list of PRIVATE SubnetIds in your Virtual Private Cloud (VPC)", + "ConstraintDescription": "must be a list of at least two existing subnets associated with at least two different availability zones. They should be residing in the selected Virtual Private Cloud." + }, + "CidrIpVPC": { + "Type": "String", + "Description": "CIDR Block for existing VPC. Traffic would be allowed from this only", + "ConstraintDescription": "must be the VPC Id of an existing Virtual Private Cloud." + }, "License": { "Description": "License model can be BYOL or HourlyPricing", "Type": "String", - "Default": "HourlyPricing" + "Default": "BYOL", + "ConstraintDescription": "Select BYOL only for GLP as these are pre baked images" } }, "Mappings": {}, @@ -37,10 +53,10 @@ def main(): } serverVersion = parameters['serverVersion'] - syncGatewayVersion = parameters['syncGatewayVersion'] + # syncGatewayVersion = parameters['syncGatewayVersion'] cluster = parameters['cluster'] - template['Mappings'] = dict(template['Mappings'].items() + generateMappings(serverVersion, syncGatewayVersion).items()) + template['Mappings'] = dict(template['Mappings'].items() + generateMappings(serverVersion).items()) template['Resources'] = dict(template['Resources'].items() + generateMiscResources().items()) template['Resources'] = dict(template['Resources'].items() + generateCluster(cluster).items()) @@ -48,25 +64,25 @@ def main(): file.write(json.dumps(template, sort_keys=True, indent=4, separators=(',', ': ')) + '\n') file.close() -def generateMappings(serverVersion, syncGatewayVersion): +def generateMappings(serverVersion): allMappings = { "CouchbaseServer": { - "4.6.4": { - "us-east-1": { "BYOL": "ami-63af9f19", "HourlyPricing": "ami-279faf5d" }, - "us-east-2": { "BYOL": "ami-d17742b4", "HourlyPricing": "ami-f4704591" }, - "us-west-1": { "BYOL": "ami-018d8061", "HourlyPricing": "ami-b88d80d8" }, - "us-west-2": { "BYOL": "ami-eea11e96", "HourlyPricing": "ami-b99728c1" }, - "ca-central-1": { "BYOL": "ami-4723a623", "HourlyPricing": "ami-492ca92d" }, - "eu-central-1": { "BYOL": "ami-82079eed", "HourlyPricing": "ami-d63ca5b9" }, - "eu-west-1": { "BYOL": "ami-1c88ef65", "HourlyPricing": "ami-fc99fe85" }, - "eu-west-2": { "BYOL": "ami-12445e76", "HourlyPricing": "ami-cb455faf" }, - "eu-west-3": { "BYOL": "ami-86d96ffb", "HourlyPricing": "ami-d3dd6bae" }, - "ap-southeast-1": { "BYOL": "ami-6fed9513", "HourlyPricing": "ami-17ed956b" }, - "ap-southeast-2": { "BYOL": "ami-3b0ef059", "HourlyPricing": "ami-c30ef0a1" }, - "ap-south-1": { "BYOL": "ami-83b1e0ec", "HourlyPricing": "ami-c8b0e1a7" }, - "ap-northeast-1": { "BYOL": "ami-1eea8778", "HourlyPricing": "ami-75e78a13" }, - "ap-northeast-2": { "BYOL": "ami-b19330df", "HourlyPricing": "ami-888e2de6" }, - "sa-east-1": { "BYOL": "ami-f4551998", "HourlyPricing": "ami-d3571bbf" } + "4.6.3": { + "us-east-1": { "BYOL": "ami-a693a3dc", "HourlyPricing": "ami-ef95a595" }, + "us-east-2": { "BYOL": "ami-d97441bc", "HourlyPricing": "ami-62764307" }, + "us-west-1": { "BYOL": "ami-cf8c81af", "HourlyPricing": "ami-c08c81a0" }, + "us-west-2": { "BYOL": "ami-380dfa40", "HourlyPricing": "ami-49a11e31" }, + "ca-central-1": { "BYOL": "ami-9822a7fc", "HourlyPricing": "ami-2e22a74a" }, + "eu-central-1": { "BYOL": "ami-8438a1eb", "HourlyPricing": "ami-9939a0f6" }, + "eu-west-1": { "BYOL": "ami-078aed7e", "HourlyPricing": "ami-7797f00e" }, + "eu-west-2": { "BYOL": "ami-dd455fb9", "HourlyPricing": "ami-be7b61da" }, + "eu-west-3": { "BYOL": "ami-d5dd6ba8", "HourlyPricing": "ami-5bc77126" }, + "ap-southeast-1": { "BYOL": "ami-33ec944f", "HourlyPricing": "ami-13eb936f" }, + "ap-southeast-2": { "BYOL": "ami-8910eeeb", "HourlyPricing": "ami-ec11ef8e" }, + "ap-south-1": { "BYOL": "aami-0d8ddc62", "HourlyPricing": "ami-5db1e032" }, + "ap-northeast-1": { "BYOL": "ami-b0e489d6", "HourlyPricing": "ami-47e48921" }, + "ap-northeast-2": { "BYOL": "ami-ec8d2e82", "HourlyPricing": "ami-e78c2f89" }, + "sa-east-1": { "BYOL": "ami-995519f5", "HourlyPricing": "ami-f5551999" } }, "5.0.1": { "us-east-1": { "BYOL": "ami-a693a3dc", "HourlyPricing": "ami-ef95a595" }, @@ -108,7 +124,7 @@ def generateMappings(serverVersion, syncGatewayVersion): } mappings = { "CouchbaseServer": allMappings["CouchbaseServer"][serverVersion], - "CouchbaseSyncGateway": allMappings["CouchbaseSyncGateway"][syncGatewayVersion] + # "CouchbaseSyncGateway": allMappings["CouchbaseSyncGateway"][syncGatewayVersion] } return mappings @@ -136,9 +152,16 @@ def generateMiscResources(): "Statement": [{ "Effect": "Allow", "Action": [ - "ec2:CreateTags", - "ec2:DescribeInstances", - "autoscaling:DescribeAutoScalingGroups" + "ec2:CreateTags", + "ec2:Describe*", + "autoscaling:DescribeAutoScalingGroups", + "cloudwatch:PutMetricData", + "cloudwatch:PutDashboard", + "cloudwatch:PutMetricAlarm", + "cloudwatch:GetMetricStatistics", + "cloudwatch:ListMetrics", + "ec2:DescribeTags", + "autoscaling:DescribeAutoScalingGroups" ], "Resource": "*" }] @@ -151,16 +174,19 @@ def generateMiscResources(): "Properties": { "GroupDescription" : "Enable SSH and Couchbase Ports", "SecurityGroupIngress": [ - { "IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 4369, "ToPort": 4369, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 4984, "ToPort": 4985, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 8091, "ToPort": 8094, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 9100, "ToPort": 9105, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 9998, "ToPort": 9999, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 11207, "ToPort": 11215, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 18091, "ToPort": 18093, "CidrIp": "0.0.0.0/0" }, - { "IpProtocol": "tcp", "FromPort": 21100, "ToPort": 21299, "CidrIp": "0.0.0.0/0" } - ] + { "IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 4369, "ToPort": 4369, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 4984, "ToPort": 4985, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 8091, "ToPort": 8094, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 9100, "ToPort": 9105, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 9998, "ToPort": 9999, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 11207, "ToPort": 11215, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 18091, "ToPort": 18093, "CidrIp": { "Ref": "CidrIpVPC" } }, + { "IpProtocol": "tcp", "FromPort": 21100, "ToPort": 21299, "CidrIp": { "Ref": "CidrIpVPC" } } + ], + "VpcId": { + "Ref": "VpcId" + } } } } @@ -194,7 +220,7 @@ def generateSyncGateway(group, rallyAutoScalingGroup): "AvailabilityZones": { "Fn::GetAZs": "" }, "LaunchConfigurationName": { "Ref": groupName + "LaunchConfiguration" }, "MinSize": 0, - "MaxSize": 100, + "MaxSize": 30, "DesiredCapacity": nodeCount } }, @@ -222,8 +248,8 @@ def generateSyncGateway(group, rallyAutoScalingGroup): "stackName=", { "Ref": "AWS::StackName" }, "\n", "baseURL=https://raw.githubusercontent.com/couchbase-partners/amazon-cloud-formation-couchbase/master/scripts/\n", "wget ${baseURL}syncGateway.sh\n", - "chmod +x *.sh\n", - "./syncGateway.sh ${stackName}\n" + "chmod +x *.sh\n" + # "./syncGateway.sh ${stackName}\n" ]] } } @@ -247,11 +273,13 @@ def generateServer(group, rallyAutoScalingGroup): command = [ "#!/bin/bash\n", "echo 'Running startup script...'\n", + "echo 'Install aws-cli...'\n" + "yum install -y aws-cli \n" "adminUsername=", { "Ref": "Username" }, "\n", "adminPassword=", { "Ref": "Password" }, "\n", "services=" + servicesParameter + "\n", "stackName=", { "Ref": "AWS::StackName" }, "\n", - "baseURL=https://raw.githubusercontent.com/couchbase-partners/amazon-cloud-formation-couchbase/master/scripts/\n", + "baseURL=https://raw.githubusercontent.com/GloballogicPractices/amazon-cloud-formation-couchbase/master/scripts/\n", "wget ${baseURL}server.sh\n", "wget ${baseURL}util.sh\n", "chmod +x *.sh\n", @@ -268,10 +296,12 @@ def generateServer(group, rallyAutoScalingGroup): groupName + "AutoScalingGroup": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { - "AvailabilityZones": { "Fn::GetAZs": "" }, + # "VpcId" : { "Ref" : "vpcId" }, + # "AvailabilityZones": { "Fn::GetAZs": { "Ref" : "AWS::Region" }}, + "VPCZoneIdentifier": { "Ref": "Subnets" }, "LaunchConfigurationName": { "Ref": groupName + "LaunchConfiguration" }, "MinSize": 1, - "MaxSize": 100, + "MaxSize": 30, "DesiredCapacity": nodeCount } }, @@ -280,6 +310,7 @@ def generateServer(group, rallyAutoScalingGroup): "Properties": { "ImageId": { "Fn::FindInMap": [ "CouchbaseServer", { "Ref": "AWS::Region" }, { "Ref": "License" } ] }, "InstanceType": nodeType, + "AssociatePublicIpAddress": False, "SecurityGroups": [ { "Ref": "CouchbaseSecurityGroup" } ], "KeyName": { "Ref": "KeyName" }, "EbsOptimized": True, diff --git a/generator/parameters/granular.yaml b/generator/parameters/granular.yaml index 3209e38..91202c0 100644 --- a/generator/parameters/granular.yaml +++ b/generator/parameters/granular.yaml @@ -1,32 +1,32 @@ serverVersion: 5.0.1 -syncGatewayVersion: 1.5.1 +#syncGatewayVersion: 1.5.1 cluster: - group: data nodeCount: 2 nodeType: m4.4xlarge - dataDiskSize: 100 + dataDiskSize: 200 services: - data - group: query - nodeCount: 2 + nodeCount: 1 nodeType: m4.4xlarge - dataDiskSize: 100 + dataDiskSize: 5 services: - query - group: index nodeCount: 2 nodeType: m4.4xlarge - dataDiskSize: 100 + dataDiskSize: 200 services: - index - - group: fts - nodeCount: 2 - nodeType: m4.4xlarge - dataDiskSize: 100 - services: - - fts - - group: syncgateway - nodeCount: 2 - nodeType: m4.4xlarge - services: - - syncGateway + # - group: fts + # nodeCount: 2 + # nodeType: m4.4xlarge + # dataDiskSize: 100 + # services: + # - fts + # - group: syncgateway + # nodeCount: 2 + # nodeType: m4.4xlarge + # services: + # - syncGateway diff --git a/generator/parameters/simple.yaml b/generator/parameters/simple.yaml index 0fb7d78..b17b701 100644 --- a/generator/parameters/simple.yaml +++ b/generator/parameters/simple.yaml @@ -1,12 +1,12 @@ serverVersion: 5.0.1 -syncGatewayVersion: 1.5.1 +# syncGatewayVersion: 1.5.1 cluster: - group: group1 - nodeCount: 5 + nodeCount: 1 nodeType: m4.4xlarge - dataDiskSize: 100 + dataDiskSize: 200 services: - data - query - index - - fts + # - fts diff --git a/scripts/cloudwatch-alarms.sh b/scripts/cloudwatch-alarms.sh new file mode 100644 index 0000000..3017da1 --- /dev/null +++ b/scripts/cloudwatch-alarms.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash +#=========================================================================================================================== +# +# FILE: create-cloudwatch-alarms.sh +# Pre-requisite - Disk and Mem Utlization Custom metrices should be implemented first in order to create Alarm on them. +# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html +# DESCRIPTION: Script creates 4 alarms for instance with PRIVATE_IP +# It does follow steps: +# 1. Creates high cpu usage alarm +# 2. Creates instance statusCheck alarm +# 3. Create Alarm to check disk utilization +# 4. Create Alarm on Memory utilization +#============================================================================================================================ + +echo "Running cloudwatch-alarms.sh" +envVar=$1 + +if [ "${envVar}" = "Pre-prod" ] +then +echo "Getting Instance ID and name tag..." + +# Get instance id and name tag +export EC2_HOME=/opt/aws/apitools/ec2 +export JAVA_HOME=/usr/ +PRIVATE_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4) +INSTANCE_ID=$(curl http://169.254.169.254/latest/meta-data/instance-id) +INSTANCE_NAME=$(/opt/aws/bin/ec2-describe-tags --region $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e "s/.$//") --filter resource-id=$(curl --silent http://169.254.169.254/latest/meta-data/instance-id) | head -1 | awk '{print $5}') + +echo "${PRIVATE_IP}" | grep -q -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" + +if [ $? -ne 0 ] +then + echo "### Usage: $0 $PRIVATE_IP" + echo "### IP address have to be presented in format X.X.X.X" + exit 1 +fi + +# Trying auto-detect AWS region +AWS_DEFAULT_REGION=$(curl -s --connect-timeout 2 http://169.254.169.254/latest/meta-data/placement/availability-zone | sed -e 's/\([1-9]\).$/\1/g') + +# Export environment variables for awscli +export AWS_DEFAULT_REGION +export AWS_DEFAULT_OUTPUT="text" + +#if [ "${INSTANCE_NAME}" = "None" ] +#then +# echo "### Could not find instance with IP ${PRIVATE_IP}" +# exit 1 +#fi + +echo "Using variables:" +echo envVar \'$envVar\' +# 1) Create high CPU usage metric +ARN_OF_SNS_TOPIC="arn:aws:sns:us-west-2:953030164212:SNS" +CPU_USAGE=70 + +aws cloudwatch put-metric-alarm \ + --alarm-name "${INSTANCE_ID}-${INSTANCE_NAME}-cpu"\ + --alarm-description "Alarm when CPU exceeds ${CPU_USAGE}%"\ + --actions-enabled\ + --ok-actions "${ARN_OF_SNS_TOPIC}"\ + --alarm-actions "${ARN_OF_SNS_TOPIC}"\ + --insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\ + --metric-name CPUUtilization\ + --namespace AWS/EC2\ + --statistic Average\ + --dimensions Name=InstanceId,Value=${INSTANCE_ID}\ + --period 60\ + --threshold ${CPU_USAGE}\ + --comparison-operator GreaterThanThreshold\ + --evaluation-periods 15\ + --unit Percent + +# 2) Create status check metric +aws cloudwatch put-metric-alarm \ + --alarm-name "${INSTANCE_ID}-${INSTANCE_NAME}-status"\ + --alarm-description "Alarm when statusCheck failed"\ + --actions-enabled\ + --ok-actions "${ARN_OF_SNS_TOPIC}"\ + --alarm-actions "${ARN_OF_SNS_TOPIC}"\ + --insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\ + --metric-name StatusCheckFailed\ + --namespace AWS/EC2\ + --statistic Maximum\ + --dimensions Name=InstanceId,Value=${INSTANCE_ID}\ + --period 60\ + --threshold 1\ + --comparison-operator GreaterThanOrEqualToThreshold\ + --evaluation-periods 15\ + --unit Count + +# 3) Create Alarm to check disk utilization +aws cloudwatch put-metric-alarm \ + --alarm-name "${INSTANCE_ID}-${INSTANCE_NAME}-Disk-Utl"\ + --alarm-description "Alarm when Disk usage exceed 85 percent"\ + --actions-enabled \ + --ok-actions "${ARN_OF_SNS_TOPIC}"\ + --alarm-actions "${ARN_OF_SNS_TOPIC}"\ + --insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\ + --metric-name DiskSpaceUtilization\ + --namespace System/Linux \ + --statistic Maximum\ + --dimensions Name=InstanceId,Value=${INSTANCE_ID} Name=MountPath,Value=/ Name=Filesystem,Value=/dev/xvda1\ + --period 60\ + --threshold 85\ + --comparison-operator GreaterThanOrEqualToThreshold\ + --evaluation-periods 15\ + --unit Percent +# 4) Creat Alarm on Memory utilization + + +aws cloudwatch put-metric-alarm \ + --alarm-name "${INSTANCE_ID}-${INSTANCE_NAME}-Mem-Utl"\ + --alarm-description "Alarm when Memory usage exceed 85 percent"\ + --actions-enabled \ + --ok-actions "${ARN_OF_SNS_TOPIC}"\ + --alarm-actions "${ARN_OF_SNS_TOPIC}"\ + --insufficient-data-actions "${ARN_OF_SNS_TOPIC}"\ + --metric-name MemoryUtilization\ + --namespace System/Linux \ + --statistic Maximum\ + --dimensions Name=InstanceId,Value=${INSTANCE_ID}\ + --period 60\ + --threshold 85\ + --comparison-operator GreaterThanOrEqualToThreshold\ + --evaluation-periods 15\ + --unit Percent + +echo "CloudWatch Alarm Setup completed on $envVar" +else +echo "$envVar does not require CloudWatch Alarms" +fi diff --git a/scripts/server.sh b/scripts/server.sh index 2152723..46e7b6d 100755 --- a/scripts/server.sh +++ b/scripts/server.sh @@ -16,12 +16,12 @@ yum -y install jq if [ -z "$5" ] then echo "This node is part of the autoscaling group that contains the rally point." - rallyPublicDNS=`getRallyPublicDNS` + rallyPrivateDNS=`getrallyPrivateDNS` else rallyAutoScalingGroup=$5 echo "This node is not the rally point and not part of the autoscaling group that contains the rally point." echo rallyAutoScalingGroup \'$rallyAutoScalingGroup\' - rallyPublicDNS=`getRallyPublicDNS ${rallyAutoScalingGroup}` + rallyPrivateDNS=`getrallyPrivateDNS ${rallyAutoScalingGroup}` fi region=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document \ @@ -32,29 +32,29 @@ instanceID=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/doc | jq '.instanceId' \ | sed 's/^"\(.*\)"$/\1/' ) -nodePublicDNS=`curl http://169.254.169.254/latest/meta-data/public-hostname` +nodePrivateDNS=`curl http://169.254.169.254/latest/meta-data/hostname` echo "Using the settings:" echo adminUsername \'$adminUsername\' echo adminPassword \'$adminPassword\' echo services \'$services\' echo stackName \'$stackName\' -echo rallyPublicDNS \'$rallyPublicDNS\' +echo rallyPrivateDNS \'$rallyPrivateDNS\' echo region \'$region\' echo instanceID \'$instanceID\' -echo nodePublicDNS \'$nodePublicDNS\' +echo nodePrivateDNS \'$nodePrivateDNS\' -if [[ ${rallyPublicDNS} == ${nodePublicDNS} ]] +if [[ ${rallyPrivateDNS} == ${nodePrivateDNS} ]] then aws ec2 create-tags \ --region ${region} \ --resources ${instanceID} \ - --tags Key=Name,Value=${stackName}-ServerRally + --tags Key=Name,Value=${stackName}-ServerRally Key=Role,Value=couchbase else aws ec2 create-tags \ --region ${region} \ --resources ${instanceID} \ - --tags Key=Name,Value=${stackName}-Server + --tags Key=Name,Value=${stackName}-Server Key=Role,Value=couchbase fi cd /opt/couchbase/bin/ @@ -64,8 +64,8 @@ output="" while [[ ! $output =~ "SUCCESS" ]] do output=`./couchbase-cli node-init \ - --cluster=$nodePublicDNS \ - --node-init-hostname=$nodePublicDNS \ + --cluster=$nodePrivateDNS \ + --node-init-hostname=$nodePrivateDNS \ --node-init-data-path=/mnt/datadisk/data \ --node-init-index-path=/mnt/datadisk/index \ --user=$adminUsername \ @@ -74,7 +74,7 @@ do sleep 10 done -if [[ $rallyPublicDNS == $nodePublicDNS ]] +if [[ $rallyPrivateDNS == $nodePrivateDNS ]] then totalRAM=$(grep MemTotal /proc/meminfo | awk '{print $2}') dataRAM=$((50 * $totalRAM / 100000)) @@ -82,7 +82,7 @@ then echo "Running couchbase-cli cluster-init" ./couchbase-cli cluster-init \ - --cluster=$nodePublicDNS \ + --cluster=$nodePrivateDNS \ --cluster-username=$adminUsername \ --cluster-password=$adminPassword \ --cluster-ramsize=$dataRAM \ @@ -91,13 +91,13 @@ then else echo "Running couchbase-cli server-add" output="" - while [[ $output != "Server $nodePublicDNS:8091 added" && ! $output =~ "Node is already part of cluster." ]] + while [[ $output != "Server $nodePrivateDNS:8091 added" && ! $output =~ "Node is already part of cluster." ]] do output=`./couchbase-cli server-add \ - --cluster=$rallyPublicDNS \ + --cluster=$rallyPrivateDNS \ --user=$adminUsername \ --pass=$adminPassword \ - --server-add=$nodePublicDNS \ + --server-add=$nodePrivateDNS \ --server-add-username=$adminUsername \ --server-add-password=$adminPassword \ --services=${services}` @@ -110,7 +110,7 @@ else while [[ ! $output =~ "SUCCESS" ]] do output=`./couchbase-cli rebalance \ - --cluster=$rallyPublicDNS \ + --cluster=$rallyPrivateDNS \ --user=$adminUsername \ --pass=$adminPassword` echo rebalance output \'$output\' diff --git a/scripts/util.sh b/scripts/util.sh index bf5c91f..4342887 100644 --- a/scripts/util.sh +++ b/scripts/util.sh @@ -21,8 +21,9 @@ formatDataDisk () chgrp couchbase $MOUNTPOINT } -getRallyPublicDNS () +getrallyPrivateDNS () { + region=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document \ | jq '.region' \ | sed 's/^"\(.*\)"$/\1/' ) @@ -62,11 +63,11 @@ getRallyPublicDNS () fi done - rallyPublicDNS=$(aws ec2 describe-instances \ + rallyPrivateDNS=$(aws ec2 describe-instances \ --region ${region} \ - --query 'Reservations[0].Instances[0].NetworkInterfaces[0].Association.PublicDnsName' \ + --query 'Reservations[0].Instances[0].NetworkInterfaces[0].PrivateDnsName' \ --instance-ids ${rallyInstanceID} \ --output text) - echo ${rallyPublicDNS} + echo ${rallyPrivateDNS} }