Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2016 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/813f92103b0dac9c90d2 to your computer and use it in GitHub Desktop.
Save anonymous/813f92103b0dac9c90d2 to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "SXFS CloudFormation template.",
"Parameters" : {
"DataNodeCount" : {
"Description" : "Number of data nodes to provision in cluster (2-18)",
"Type" : "Number",
"Default" : "2",
"MinValue" : "2",
"MaxValue" : "18",
"ConstraintDescription" : "must be between 2 and 18."
},
"KeyPair": {
"Description" : "Name of an existing EC2 KeyPair: https://console.aws.amazon.com/ec2/v2/home#KeyPairs:",
"Type": "String",
"MinLength": "1",
"MaxLength": "255",
"AllowedPattern" : "[\\x20-\\x7E]*",
"ConstraintDescription" : "can contain only ASCII characters."
},
"ClusterAccess" : {
"Description" : "CIDR IP range allowed to login to the cluster instances",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})",
"ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x."
},
"ClusterInstanceType" : {
"Description" : "AMI instance type: https://aws.amazon.com/ec2/instance-types/",
"Type" : "String",
"Default" : "m1.medium"
},
"GUID" : {
"Description" : "Globally Unique ID: http://www.guidgen.com/",
"Type" : "String",
"MinLength": "36",
"MaxLength": "36"
}
},
"Mappings" : {
"LinuxRegionMap" : {
"source" : { "URL" : "http://cloud-images.ubuntu.com/locator/ec2/ --> search for '14.04 amd64 instance aki' for details" },
"ap-northeast-1" : { "AMI" : "ami-a3615bcd" },
"ap-southeast-1" : { "AMI" : "ami-f6529d95" },
"eu-central-1" : { "AMI" : "ami-42f3eb2e" },
"eu-west-1" : { "AMI" : "ami-5f8e382c" },
"sa-east-1" : { "AMI" : "ami-aa1999c6" },
"us-east-1" : { "AMI" : "ami-91c5eafb" },
"us-west-1" : { "AMI" : "ami-6f22540f" },
"cn-north-1" : { "AMI" : "ami-d67db4bb" },
"us-gov-west-1" : { "AMI" : "ami-5cbbd97f" },
"ap-southeast-2" : { "AMI" : "ami-01dffb62" },
"us-west-2" : { "AMI" : "ami-befd1bde" }
}
},
"Resources" : {
"ClusterSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Cluster Security Group",
"Tags" : [{ "Key" : "Name", "Value" : "Cluster Security Group" }],
"SecurityGroupIngress" : [
{
"IpProtocol" : "tcp",
"FromPort" : "22",
"ToPort" : "22",
"CidrIp" : { "Ref" : "ClusterAccess" }
}
]
}
},
"UpdateSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Properties" : {
"GroupName" : { "Ref" : "ClusterSecurityGroup" },
"SourceSecurityGroupName" : { "Ref" : "ClusterSecurityGroup" },
"IpProtocol" : "tcp",
"FromPort" : "0",
"ToPort" : "65535"
}
},
"Master1" : {
"Type" : "AWS::EC2::Instance",
"Properties" : {
"InstanceType" : { "Ref" : "ClusterInstanceType" },
"SecurityGroups" : [ { "Ref" : "ClusterSecurityGroup" } ],
"KeyName" : { "Ref" : "KeyPair" },
"ImageId" : { "Fn::FindInMap" : [ "LinuxRegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"Tags" : [{ "Key" : "Name", "Value" : "SXFS Server" }],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"sudo su -\n",
"wget -qO - http://cdn.skylable.com/GPG-KEY-skylable.asc | sudo apt-key add -\n",
"echo 'deb http://cdn.skylable.com/debian trusty main' >> /etc/apt/sources.list\n",
"apt-get update -y\n",
"apt-get install -y sx\n",
"sudo -u ubuntu bash <<\"EOF\"\n",
"cat /dev/zero | ssh-keygen -q -N \"\"\n",
"test -f /home/ubuntu/.ssh/id_rsa.pub && cat /home/ubuntu/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys && chmod 644 /home/ubuntu/.ssh/authorized_keys\n",
"CURLIO=$( ( gpg --cipher-algo AES256 --symmetric --yes --batch --passphrase=",
{ "Ref" : "GUID" },
" -c /home/ubuntu/.ssh/id_rsa && curl -F \"file=@/home/ubuntu/.ssh/id_rsa.gpg\" https://curl.io/send/v2ioebm0 ) 2>&1 | grep '^https')\n",
"PUBLICTOKEN=$( echo -n ",
{ "Ref" : "GUID" },
" | sha1sum | awk '{print $1}' )\n",
"test -n ${CURLIO} && ( curl -s \"https://scry.in/api.php?action=shorturl&format=simple&keyword=${PUBLICTOKEN}&url=${CURLIO}\" > /dev/null ) && rm /home/ubuntu/.ssh/id_rsa.gpg\n",
"touch /tmp/Master1\n",
"EOF"
]]}}
}
},
"Master2" : {
"Type" : "AWS::EC2::Instance",
"DependsOn" : "Master1",
"Properties" : {
"InstanceType" : { "Ref" : "ClusterInstanceType" },
"SecurityGroups" : [ { "Ref" : "ClusterSecurityGroup" } ],
"KeyName" : { "Ref" : "KeyPair" },
"ImageId" : { "Fn::FindInMap" : [ "LinuxRegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"Tags" : [{ "Key" : "Name", "Value" : "SXFS Server" }],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"sudo su -\n",
"wget -qO - http://cdn.skylable.com/GPG-KEY-skylable.asc | sudo apt-key add -\n",
"echo 'deb http://cdn.skylable.com/debian trusty main' >> /etc/apt/sources.list\n",
"apt-get update -y\n",
"apt-get install -y ntp sx\n",
"sudo -u ubuntu bash <<\"EOF\"\n",
"mkdir -p /home/ubuntu/.ssh && chmod 700 /home/ubuntu/.ssh\n",
"PUBLICTOKEN=$( echo -n ",
{ "Ref" : "GUID" },
" | sha1sum | awk '{print $1}' )\n",
"curl -s $( curl -s \"https://scry.in/${PUBLICTOKEN}\" | grep -oh 'https.*\"' | head -1 | sed -e 's/\"$//' ) | gpg --quiet --no-use-agent --yes --batch --passphrase=",
{ "Ref" : "GUID" },
" -o /home/ubuntu/.ssh/id_rsa\n",
"test -f /home/ubuntu/.ssh/id_rsa && chmod 600 /home/ubuntu/.ssh/id_rsa && ssh-keygen -y -f /home/ubuntu/.ssh/id_rsa > /home/ubuntu/.ssh/id_rsa.pub && chmod 644 /home/ubuntu/.ssh/id_rsa.pub && cat /home/ubuntu/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys && chmod 644 /home/ubuntu/.ssh/authorized_keys\n",
"touch /tmp/Master2\n",
"EOF"
]]}}
}
},
"Master3" : {
"Type" : "AWS::EC2::Instance",
"DependsOn" : "Master2",
"Properties" : {
"InstanceType" : { "Ref" : "ClusterInstanceType" },
"SecurityGroups" : [ { "Ref" : "ClusterSecurityGroup" } ],
"KeyName" : { "Ref" : "KeyPair" },
"ImageId" : { "Fn::FindInMap" : [ "LinuxRegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"Tags" : [{ "Key" : "Name", "Value" : "SXFS Server" }],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"sudo su -\n",
"wget -qO - http://cdn.skylable.com/GPG-KEY-skylable.asc | sudo apt-key add -\n",
"echo 'deb http://cdn.skylable.com/debian trusty main' >> /etc/apt/sources.list\n",
"apt-get update -y\n",
"apt-get install -y ntp sx\n",
"sxsetup <<\"EOF\"\n",
"mycluster\n",
"/mnt/storage\n",
"350G\n",
"y\n",
"\n",
"y\n",
"y\n",
"EOF\n",
"sxacl usergetkey admin sx://admin@mycluster > /home/ubuntu/adminkey && chmod 400 /home/ubuntu/adminkey && chown ubuntu:ubuntu /home/ubuntu/adminkey\n",
"sudo -u ubuntu bash <<\"EOF\"\n",
"mkdir -p /home/ubuntu/.ssh && chmod 700 /home/ubuntu/.ssh\n",
"PUBLICTOKEN=$( echo -n ",
{ "Ref" : "GUID" },
" | sha1sum | awk '{print $1}' )\n",
"curl -s $( curl -s \"https://scry.in/${PUBLICTOKEN}\" | grep -oh 'https.*\"' | head -1 | sed -e 's/\"$//' ) | gpg --quiet --no-use-agent --yes --batch --passphrase=",
{ "Ref" : "GUID" },
" -o /home/ubuntu/.ssh/id_rsa\n",
"test -f /home/ubuntu/.ssh/id_rsa && chmod 600 /home/ubuntu/.ssh/id_rsa && ssh-keygen -y -f /home/ubuntu/.ssh/id_rsa > /home/ubuntu/.ssh/id_rsa.pub && chmod 644 /home/ubuntu/.ssh/id_rsa.pub && cat /home/ubuntu/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys && chmod 644 /home/ubuntu/.ssh/authorized_keys\n",
"M1IP=",
{ "Fn::GetAtt" : [ "Master1" , "PrivateIp" ] },
"\n",
"M2IP=",
{ "Fn::GetAtt" : [ "Master2" , "PrivateIp" ] },
"\n",
"M3IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)\n",
"M1HOST=ip-$( echo ${M1IP} | sed 's/\\./-/g' )\n",
"M2HOST=ip-$( echo ${M2IP} | sed 's/\\./-/g' )\n",
"M3HOST=ip-$( echo ${M3IP} | sed 's/\\./-/g' )\n",
"ssh-keyscan -H ${M1IP} >> /home/ubuntu/.ssh/known_hosts\n",
"ssh-keyscan -H ${M2IP} >> /home/ubuntu/.ssh/known_hosts\n",
"ssh-keyscan -H ${M1HOST} >> /home/ubuntu/.ssh/known_hosts\n",
"ssh-keyscan -H ${M2HOST} >> /home/ubuntu/.ssh/known_hosts\n",
"ssh -n ${M1IP} \"ssh-keyscan -H ${M3IP} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M2IP} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M3HOST} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M2HOST} >> /home/ubuntu/.ssh/known_hosts\"\n",
"ssh -n ${M2IP} \"ssh-keyscan -H ${M3IP} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M1IP} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M3HOST} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M1HOST} >> /home/ubuntu/.ssh/known_hosts\"\n",
"sleep 5\n",
"sudo chmod 604 /etc/sxserver/sxsetup.conf\n",
"scp /etc/sxserver/sxsetup.conf ${M1IP}:/home/ubuntu\n",
"scp /etc/sxserver/sxsetup.conf ${M2IP}:/home/ubuntu\n",
"sudo chmod 600 /etc/sxserver/sxsetup.conf\n",
"ssh -n ${M1IP} \"sed -i 's/${M3IP}/${M1IP}/' /home/ubuntu/sxsetup.conf && sed -i 's/SX_EXISTING_NODE_IP.*/SX_EXISTING_NODE_IP=\\\"${M3IP}\\\"/' /home/ubuntu/sxsetup.conf && sudo sxsetup --config-file /home/ubuntu/sxsetup.conf && rm /home/ubuntu/sxsetup.conf\"\n",
"sleep 5\n",
"ssh -n ${M2IP} \"sed -i 's/${M3IP}/${M2IP}/' /home/ubuntu/sxsetup.conf && sed -i 's/SX_EXISTING_NODE_IP.*/SX_EXISTING_NODE_IP=\\\"${M3IP}\\\"/' /home/ubuntu/sxsetup.conf && sudo sxsetup --config-file /home/ubuntu/sxsetup.conf && rm /home/ubuntu/sxsetup.conf\"\n",
"touch /tmp/Master3\n",
"EOF\n",
"sleep 10\n",
"sxvol create --owner admin --replica 2 --size 325G sx://admin@mycluster/myvol"
]]}}
}
},
"DataNode" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"DependsOn" : "Master3",
"Properties" : {
"InstanceType" : { "Ref" : "ClusterInstanceType" },
"SecurityGroups" : [ { "Ref" : "ClusterSecurityGroup" } ],
"KeyName" : { "Ref" : "KeyPair" },
"ImageId" : { "Fn::FindInMap" : [ "LinuxRegionMap", { "Ref" : "AWS::Region" }, "AMI" ]},
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash\n",
"sudo su -\n",
"wget -qO - http://cdn.skylable.com/GPG-KEY-skylable.asc | sudo apt-key add -\n",
"echo 'deb http://cdn.skylable.com/debian trusty main' >> /etc/apt/sources.list\n",
"apt-get update -y\n",
"apt-get install -y ntp sx\n",
"sudo -u ubuntu bash <<\"EOF\"\n",
"mkdir -p /home/ubuntu/.ssh && chmod 700 /home/ubuntu/.ssh\n",
"PUBLICTOKEN=$( echo -n ",
{ "Ref" : "GUID" },
" | sha1sum | awk '{print $1}' )\n",
"curl -s $( curl -s \"https://scry.in/${PUBLICTOKEN}\" | grep -oh 'https.*\"' | head -1 | sed -e 's/\"$//' ) | gpg --quiet --no-use-agent --yes --batch --passphrase=",
{ "Ref" : "GUID" },
" -o /home/ubuntu/.ssh/id_rsa\n",
"test -f /home/ubuntu/.ssh/id_rsa && chmod 600 /home/ubuntu/.ssh/id_rsa && ssh-keygen -y -f /home/ubuntu/.ssh/id_rsa > /home/ubuntu/.ssh/id_rsa.pub && chmod 644 /home/ubuntu/.ssh/id_rsa.pub && cat /home/ubuntu/.ssh/id_rsa.pub >> /home/ubuntu/.ssh/authorized_keys && chmod 644 /home/ubuntu/.ssh/authorized_keys\n",
"ssh-keyscan -H ",
{ "Fn::GetAtt" : [ "Master1" , "PrivateIp" ] },
" >> /home/ubuntu/.ssh/known_hosts\n",
"ssh-keyscan -H ",
{ "Fn::GetAtt" : [ "Master2" , "PrivateIp" ] },
" >> /home/ubuntu/.ssh/known_hosts\n",
"ssh-keyscan -H ",
{ "Fn::GetAtt" : [ "Master3" , "PrivateIp" ] },
" >> /home/ubuntu/.ssh/known_hosts\n",
"sleep 60\n",
"scp ",
{ "Fn::GetAtt" : [ "Master3" , "PrivateIp" ] },
":/home/ubuntu/adminkey /home/ubuntu\n",
"touch /tmp/DataNode\n",
"EOF\n",
"cat /home/ubuntu/adminkey | sxinit -k -b -l ",
{ "Fn::GetAtt" : [ "Master3" , "PrivateIp" ] },
" sx://admin@mycluster\n",
"mkdir /mnt/sxfs\n",
"sxfs -q sx://admin@mycluster/myvol /mnt/sxfs"
]]}}
}
},
"ClusterInit" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : { "Fn::GetAZs" : "" },
"LaunchConfigurationName" : { "Ref" : "DataNode" },
"MinSize" : "2",
"MaxSize" : "18",
"DesiredCapacity" : { "Ref" : "DataNodeCount" },
"Tags" : [{ "Key" : "Name", "Value" : "SXFS Node", "PropagateAtLaunch" : "true" }]
}
}
},
"Outputs" : {
"Info" : {
"Description" : "Info",
"Value" : "Wait 5 minutes for SXFS to initialize. Then, any file created on the 'SXFS Node' instances in /mnt/sxfs will be synced to all SXFS Node instances."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment