Skip to content

Commit f77a5d7

Browse files
committed
Autoscale and Racksapce cloud information
1 parent 9e6885c commit f77a5d7

File tree

5 files changed

+167
-3
lines changed

5 files changed

+167
-3
lines changed

README.md

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,125 @@
1-
autoscale_cloudinit
2-
===================
1+
victor.palma@ML3138FFT3  ~/Documents/development/autoscale/autoscale_cloudinit  cat readme.md
2+
#Rackspace Autoscale + cloudinit
3+
This document covers Rackspace autoscale and cloudinit. I will only cover the basic on creating a scaling group via curl. The web GUI method has been covered before, you can find a good article about it here:
4+
5+
http://www.rackspace.com/blog/start-using-auto-scale-today/
6+
7+
##Overview
8+
The product is offered for free to Rackspace customers, though you will still be charged for the cloud servers you utilize in scaling.
9+
10+
Setting up Auto Scale is simple as 1, 2, 3.
11+
12+
1. Create a Scaling Group — a group of servers that will grow, or shrink, in number according to your rules.
13+
14+
2. Create Scaling Rules using Monitoring – if you will use events rather than a schedule to trigger scaling — what thresholds or events to watch for (CPU load, queue length, req/sec, etc).
15+
16+
3. Create a Scaling Policy— this defines how much to grow or shrink capacity. For schedule-based scaling, you would also define when to do so. Rackspace Auto Scale will take care of the rest. With a caveat for scale down there is no graceful action that get's taken when spinning down servers.
17+
18+
19+
####Schedule-Based
20+
If expect significant additional demand on your application at specific times. For example:
21+
22+
* A holiday season sales boost on your e-commerce site
23+
* A major sales promotion on a specific day or for a period of time – ie. from a Super Bowl advertisement
24+
* During the day when more people are using your app, and during the night when most of your users are asleep
25+
26+
####Event-based
27+
Monitoring your servers and detect that you need to add or reduce capacity based on the load. For example:
28+
29+
* Use Rackspace Cloud Monitoring to monitor individual server load and trigger a policy based on a threshold
30+
* Use third party monitoring systems such as Nagios and trigger a policy based on a threshold
31+
* Use Rackspace Cloud Monitoring with an available plug-in to monitor queue length and trigger a policy based on threshold
32+
33+
34+
35+
###Create a Scaling Group
36+
37+
38+
First we will generate a auth token. If copying and pasting please modify the user name, and API key(aka password). Once it finishes you will generate a token, save that token as you will have to plug it in .
39+
<pre><code>
40+
curl -s -d\ '{ "auth": { "RAX-KSKEY:apiKeyCredentials": { "username": "MY USER NAME", "apiKey": "USER API KEY"} } }' \
41+
-H 'Content-Type: application/json'\
42+
'https://identity.api.rackspacecloud.com/v2.0/tokens'
43+
</pre>
44+
Next we will create an autoscale group that will spin up a maximum of 4 servers and minimum 1 server. These servers are using the default Ubuntu 13.10 (Saucy Salamander) (PVHVM) performance server with 2Gig of ram. Additionally it will insert a ssh key that has been previously uploaded. Each of the servers will be created with a prepend name of 'test-au-'.
45+
46+
Make sure to change the following variables with the corresponding values MY_TENANT_ID, MY_AUTH_TOKEN and MY_SSH_KEY (this is the name of the ssh key that was uploaded)).
47+
48+
49+
<pre><code>
50+
curl -i https://ord.autoscale.api.rackspacecloud.com/v1.0/MY_TENANT_ID/groups -X POST -H 'X-Auth-Project-Id: MY_TENANT_ID' -H 'User-Agent: pyrax/1.7.0' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'X-Auth-Token: MY_AUTH_TOKEN' -d '
51+
{
52+
"groupConfiguration": {
53+
"cooldown": 120,
54+
"maxEntities": 4,
55+
"metadata": {},
56+
"minEntities": 1,
57+
"name": "my_AutoScale_test1"
58+
},
59+
"launchConfiguration": {
60+
"args": {
61+
"server": {
62+
"OS-DCF:diskConfig" : "MANUAL",
63+
"config_drive" : true,
64+
"flavorRef": "performance1-2",
65+
"imageRef": "6110edfe-8589-4bb1-aa27-385f12242627",
66+
"key_name" : "MY_SSH_KEY",
67+
"user_data" : "I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CgogLSBhcGFjaGUyCiAtIHBocDUKIC0gcGhwNS1teXNxbAogLSBteXNxbC1zZXJ2ZXIKCnJ1bmNtZDoKCiAtIHdnZXQgaHR0cDovL3dvcmRwcmVzcy5vcmcvbGF0ZXN0LnRhci5neiAtUCAvdG1wLwogLSB0YXIgLXp4ZiAvdG1wL2xhdGVzdC50YXIuZ3ogLUMgL3Zhci93d3cvCiAtIG15c3FsIC1lICJjcmVhdGUgZGF0YWJhc2Ugd29yZHByZXNzOyBjcmVhdGUgdXNlciAnd3B1c2VyJ0AnbG9jYWxob3N0JyBpZGVudGlmaWVkIGJ5ICdjaGFuZ2VtZXRvbyc7IGdyYW50IGFsbCBwcml2aWxlZ2VzIG9uIHdvcmRwcmVzcyAuIFwqIHRvICd3cHVzZXInQCdsb2NhbGhvc3QnOyBmbHVzaCBwcml2aWxlZ2VzOyIKIC0gbXlzcWwgLWUgImRyb3AgZGF0YWJhc2UgdGVzdDsgZHJvcCB1c2VyICd0ZXN0J0AnbG9jYWxob3N0JzsgZmx1c2ggcHJpdmlsZWdlczsiCiAtIG15c3FsYWRtaW4gLXUgcm9vdCBwYXNzd29yZCAnY2hhbmdlbWUnCg==",
68+
"name": "test-au-"
69+
}
70+
},
71+
"type": "launch_server"
72+
},
73+
"scalingPolicies": []
74+
}'
75+
</pre>
76+
77+
Once this finishes(assuming everything worked and there were no errors) you should be able to view it on the cloud portal. It should also kick off a server that will execute the following cloud init config.
78+
<pre><code>
79+
#cloud-config
80+
81+
packages:
82+
83+
- apache2
84+
- php5
85+
- php5-mysql
86+
- mysql-server
87+
88+
runcmd:
89+
90+
- wget http://wordpress.org/latest.tar.gz -P /tmp/
91+
- tar -zxf /tmp/latest.tar.gz -C /var/www/
92+
- mysql -e "create database wordpress; create user 'wpuser'@'localhost' identified by 'changemetoo'; grant all privileges on wordpress . \* to 'wpuser'@'localhost'; flush privileges;"
93+
- mysql -e "drop database test; drop user 'test'@'localhost'; flush privileges;"
94+
- mysqladmin -u root password 'changeme'
95+
</pre>
96+
97+
One important thing to note is that the "user_data" used for server creation needs to be encoded in a b64 format. I have included two quick scripts that will encode and decode the file.
98+
99+
<pre><code>
100+
101+
</code></pre>
102+
#cloud-init
103+
104+
105+
There is a great article that talks about using cloud-init with rackspace cloud and you can find it below.
106+
107+
#####Links:
108+
http://developer.rackspace.com/blog/using-cloud-init-with-rackspace-cloud.html
109+
110+
http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Create_Server_with_configdrive.html
111+
112+
113+
114+
##Troubleshooting cloud-init
115+
This is a good segue into what happens if something goes wrong and you need to figure out what exploded.
116+
117+
Log files can typically be found in /var/log/cloud-init.log.
118+
119+
The copy of your cloud-config is stored here: /var/lib/cloud/instance/cloud-config.txt.
120+
121+
The /var/lib/cloud directory also has other useful information, such as files that let cloud-init know it’s already run once so you can rest easy cloud-init isn’t going to setup Apache again if you reboot your server
122+
123+
124+
3125

4-
Information on how to use cloudinit and Rackspace autoscale

cloud-config

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#cloud-config
2+
3+
packages:
4+
5+
- apache2
6+
- php5
7+
- php5-mysql
8+
- mysql-server
9+
10+
runcmd:
11+
12+
- wget http://wordpress.org/latest.tar.gz -P /tmp/
13+
- tar -zxf /tmp/latest.tar.gz -C /var/www/
14+
- mysql -e "create database wordpress; create user 'wpuser'@'localhost' identified by 'changemetoo'; grant all privileges on wordpress . \* to 'wpuser'@'localhost'; flush privileges;"
15+
- mysql -e "drop database test; drop user 'test'@'localhost'; flush privileges;"
16+
- mysqladmin -u root password 'changeme'

cloud-config.b64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I2Nsb3VkLWNvbmZpZwoKcGFja2FnZXM6CgogLSBhcGFjaGUyCiAtIHBocDUKIC0gcGhwNS1teXNxbAogLSBteXNxbC1zZXJ2ZXIKCnJ1bmNtZDoKCiAtIHdnZXQgaHR0cDovL3dvcmRwcmVzcy5vcmcvbGF0ZXN0LnRhci5neiAtUCAvdG1wLwogLSB0YXIgLXp4ZiAvdG1wL2xhdGVzdC50YXIuZ3ogLUMgL3Zhci93d3cvCiAtIG15c3FsIC1lICJjcmVhdGUgZGF0YWJhc2Ugd29yZHByZXNzOyBjcmVhdGUgdXNlciAnd3B1c2VyJ0AnbG9jYWxob3N0JyBpZGVudGlmaWVkIGJ5ICdjaGFuZ2VtZXRvbyc7IGdyYW50IGFsbCBwcml2aWxlZ2VzIG9uIHdvcmRwcmVzcyAuIFwqIHRvICd3cHVzZXInQCdsb2NhbGhvc3QnOyBmbHVzaCBwcml2aWxlZ2VzOyIKIC0gbXlzcWwgLWUgImRyb3AgZGF0YWJhc2UgdGVzdDsgZHJvcCB1c2VyICd0ZXN0J0AnbG9jYWxob3N0JzsgZmx1c2ggcHJpdmlsZWdlczsiCiAtIG15c3FsYWRtaW4gLXUgcm9vdCBwYXNzd29yZCAnY2hhbmdlbWUnCg==

decode.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
import sys, base64
3+
4+
if len(sys.argv) < 2:
5+
print """Usage: %s FILE_TO_DECODE
6+
7+
MFILE_TO_DECODE - The fle in b64 format, that you wan to decode
8+
9+
"""%sys.argv[0]
10+
sys.exit(0)
11+
12+
#base64.encode(open(sys.argv[1], 'rb'), open(sys.argv[2], 'wb'))
13+
print base64.b64decode(open(sys.argv[1], 'rb').read())

encode.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
import sys, base64
3+
4+
if len(sys.argv) < 2:
5+
print """Usage: %s FILE_TO_ENCODE
6+
7+
MFILE_TO_ENCODE - The fle you wan to encode in Base64
8+
9+
"""%sys.argv[0]
10+
sys.exit(0)
11+
12+
#base64.encode(open(sys.argv[1], 'rb'), open(sys.argv[2], 'wb'))
13+
print base64.b64encode(open(sys.argv[1], 'rb').read())

0 commit comments

Comments
 (0)