-
-
Save anonymous/257fd013ebff1031fb4e to your computer and use it in GitHub Desktop.
SheepFS CloudFormation script -- NOT WORKING !!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AWSTemplateFormatVersion" : "2010-09-09", | |
"Description" : "SheepFS 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" : "SheepFS Server" }], | |
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ | |
"#!/bin/bash\n", | |
"sudo su -\n", | |
"apt-get update -y\n", | |
"apt-get install -y zookeeper zookeeperd autoconf pkg-config build-essential liburcu-dev libtool libcorosync-common-dev libcpg-dev libcfg-dev yasm libzookeeper-mt-dev libfuse-dev\n", | |
"sed -i 's/nobootwait/nobootwait,user_xattr/' /etc/fstab\n", | |
"mount -o remount,user_xattr /mnt\n", | |
"cd /tmp\n", | |
"wget -O sheepdog-v0.9.3.tar.gz https://github.com/sheepdog/sheepdog/archive/v0.9.3.tar.gz\n", | |
"tar xvzf sheepdog-v0.9.3.tar.gz\n", | |
"cd sheepdog-0.9.3\n", | |
"./autogen.sh\n", | |
"./configure --enable-zookeeper\n", | |
"make install\n", | |
"cd ..\n", | |
"echo 1 > /etc/zookeeper/conf/myid\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" : "SheepFS Server" }], | |
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ | |
"#!/bin/bash\n", | |
"sudo su -\n", | |
"apt-get update -y\n", | |
"apt-get install -y zookeeper zookeeperd autoconf pkg-config build-essential liburcu-dev libtool libcorosync-common-dev libcpg-dev libcfg-dev yasm libzookeeper-mt-dev libfuse-dev\n", | |
"sed -i 's/nobootwait/nobootwait,user_xattr/' /etc/fstab\n", | |
"mount -o remount,user_xattr /mnt\n", | |
"cd /tmp\n", | |
"wget -O sheepdog-v0.9.3.tar.gz https://github.com/sheepdog/sheepdog/archive/v0.9.3.tar.gz\n", | |
"tar xvzf sheepdog-v0.9.3.tar.gz\n", | |
"cd sheepdog-0.9.3\n", | |
"./autogen.sh\n", | |
"./configure --enable-zookeeper\n", | |
"make install\n", | |
"cd ..\n", | |
"echo 2 > /etc/zookeeper/conf/myid\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" : "SheepFS Server" }], | |
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ | |
"#!/bin/bash\n", | |
"sudo su -\n", | |
"apt-get update -y\n", | |
"apt-get install -y zookeeper zookeeperd autoconf pkg-config build-essential liburcu-dev libtool libcorosync-common-dev libcpg-dev libcfg-dev yasm libzookeeper-mt-dev libfuse-dev\n", | |
"sed -i 's/nobootwait/nobootwait,user_xattr/' /etc/fstab\n", | |
"mount -o remount,user_xattr /mnt\n", | |
"cd /tmp\n", | |
"wget -O sheepdog-v0.9.3.tar.gz https://github.com/sheepdog/sheepdog/archive/v0.9.3.tar.gz\n", | |
"tar xvzf sheepdog-v0.9.3.tar.gz\n", | |
"cd sheepdog-0.9.3\n", | |
"./autogen.sh\n", | |
"./configure --enable-zookeeper\n", | |
"make install\n", | |
"cd ..\n", | |
"echo 3 > /etc/zookeeper/conf/myid\n", | |
"echo 'server.1=", | |
{ "Fn::GetAtt" : [ "Master1" , "PrivateIp" ] }, | |
":2888:3888' >> /etc/zookeeper/conf/zoo.cfg\n", | |
"echo 'server.2=", | |
{ "Fn::GetAtt" : [ "Master2" , "PrivateIp" ] }, | |
":2888:3888' >> /etc/zookeeper/conf/zoo.cfg\n", | |
"echo \"server.3=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4):2888:3888\" >> /etc/zookeeper/conf/zoo.cfg\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", | |
"ssh-keyscan -H ${M1IP} >> /home/ubuntu/.ssh/known_hosts\n", | |
"ssh-keyscan -H ${M2IP} >> /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\"\n", | |
"ssh -n ${M2IP} \"ssh-keyscan -H ${M3IP} >> /home/ubuntu/.ssh/known_hosts ; ssh-keyscan -H ${M1IP} >> /home/ubuntu/.ssh/known_hosts\"\n", | |
"sleep 5\n", | |
"scp /etc/zookeeper/conf/zoo.cfg ${M1IP}:/home/ubuntu\n", | |
"scp /etc/zookeeper/conf/zoo.cfg ${M1IP}:/home/ubuntu\n", | |
"ssh -n ${M1IP} \"sudo chown root:root /home/ubuntu/zoo.cfg && sudo mv /home/ubuntu/zoo.cfg /etc/zookeeper/conf\"\n", | |
"ssh -n ${M2IP} \"sudo chown root:root /home/ubuntu/zoo.cfg && sudo mv /home/ubuntu/zoo.cfg /etc/zookeeper/conf\"\n", | |
"sleep 5\n", | |
"sudo service zookeeper restart\n", | |
"ssh -n ${M1IP} \"sudo service zookeeper restart\"\n", | |
"ssh -n ${M2IP} \"sudo service zookeeper restart\"\n", | |
"sleep 30\n", | |
"sudo sheep -n /var/lib/sheepdog,/mnt/sheepobj -c zookeeper:${M1IP}:2181,${M2IP}:2181,${M3IP}:2181\n", | |
"sleep 10\n", | |
"ssh -n ${M1IP} \"sudo sheep -n /var/lib/sheepdog,/mnt/sheepobj -c zookeeper:${M1IP}:2181,${M2IP}:2181,${M3IP}:2181\"\n", | |
"sleep 10\n", | |
"ssh -n ${M2IP} \"sudo sheep -n /var/lib/sheepdog,/mnt/sheepobj -c zookeeper:${M1IP}:2181,${M2IP}:2181,${M3IP}:2181\"\n", | |
"sleep 10\n", | |
"sudo dog cluster format --copies 2\n", | |
"touch /tmp/Master3\n", | |
"EOF" | |
]]}} | |
} | |
}, | |
"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", | |
"apt-get update -y\n", | |
"apt-get install -y autoconf pkg-config build-essential liburcu-dev libtool libcorosync-common-dev libcpg-dev libcfg-dev yasm libfuse-dev\n", | |
"sed -i 's/nobootwait/nobootwait,user_xattr/' /etc/fstab\n", | |
"mount -o remount,user_xattr /mnt\n", | |
"cd /tmp\n", | |
"wget -O sheepdog-v0.9.3.tar.gz https://github.com/sheepdog/sheepdog/archive/v0.9.3.tar.gz\n", | |
"tar xvzf sheepdog-v0.9.3.tar.gz\n", | |
"cd sheepdog-0.9.3\n", | |
"./autogen.sh\n", | |
"./configure\n", | |
"make install\n", | |
"cd ..\n", | |
"mkdir /mnt/sheepfs\n", | |
"sheepfs -a ", | |
{ "Fn::GetAtt" : [ "Master1" , "PrivateIp" ] }, | |
" /mnt/sheepfs" | |
]]}} | |
} | |
}, | |
"ClusterInit" : { | |
"Type" : "AWS::AutoScaling::AutoScalingGroup", | |
"Properties" : { | |
"AvailabilityZones" : { "Fn::GetAZs" : "" }, | |
"LaunchConfigurationName" : { "Ref" : "DataNode" }, | |
"MinSize" : "2", | |
"MaxSize" : "18", | |
"DesiredCapacity" : { "Ref" : "DataNodeCount" }, | |
"Tags" : [{ "Key" : "Name", "Value" : "SheepFS Node", "PropagateAtLaunch" : "true" }] | |
} | |
} | |
}, | |
"Outputs" : { | |
"Info" : { | |
"Description" : "Info", | |
"Value" : "Wait 5 minutes for SheepFS to initialize. Then, any file created on the 'SheepFS Node' instances in /mnt/sheepfs will be synced to all SheepFS Node instances." | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment