mattyw

whatever I've been playing around with lately

Taming the Cloud With Juju and Raspberry Pi

| Comments

The idea

We’re going to use a raspberry pi and juju to setup a wordpress blog on aws.

The raspberry pi is an amazing little gadget. Low power enough that I don’t feel guilty about leaving it turned on overnight, but flexible enough that I can shove leds into it to grab my attention if needed.

Juju is ubuntu’s answer to setting up services in the cloud. Once installed you simply setup your credentials with an existing cloud provider like aws or hp cloud and then deploy things into it. Setting up wordpress for example is as simple as

1
2
3
4
5
juju bootstrap # Setup the cloud environment
juju deploy wordpress # Start an instance and install wordpress on it
juju deploy mysql # Start an instance and install mysql on it
juju add-relation wordpress mysql # Connect wordpress and mysql together
juju expose wordpress #Allow wordpress to be accessed from a public ip

The Plan

  1. Install go onto the raspberry pi
  2. Install juju
  3. Deploy a wordpress blog

We’re going to be installing the latest version of juju which is written in go.

Installing Go

Dave Cheney has written an excellent article on Installing go on the raspberry pi. On my model B (1.0 revision) I had to update raspi-config so that I could select the 240M/16M memory split, but you might have to see how you get on here. I choose to skip the tests and just ran ./make.bash to build go rather than all.bash.

I was unable to build juju using go 1.0.3. I ended up building go 1.1.1 from source, which seemed to work fine. From memory I believe you need to setup a folder to be your GOPATH before you can install the latest version of go.

Installing Juju

Getting the latest tip of juju-core is easy using the go get command, it grabs all the dependencies for you, it does mean we’re grabbing tip, but there are ways to fix that later if we need to. juju-core is hosted on launchpad.net which uses bazaar for source control. This means you need to install it before you can run go get. I was able to install it on raspian using

1
2
sudo apt-get update
sudo apt-get bzr

Without doing the update I was unable to grab all of bzr’s dependencies, so I recommend running the update first.

Once bzr is installed you can install juju using go get:

1
2
sudo apt-get install libcurl4-gnutls-dev
go get launchpad.net/juju-core/...

When it’s finished you should find a juju binary installed. Mine ended up in my GOPATH, I think because I had something setup wrong somewhere. But if you’ve got this far I’m sure you’ll be able to find it.

Setting up Juju

There’s much better instructions for setting up juju here The basic steps come down to

  1. Setting up a public key
  2. Generating an environments.yaml file
  3. Filling the file in with the data for your cloud provider

I configured juju for aws. My ~/.juju/environments.yaml file looked like this:

1
2
3
4
5
6
7
8
default: amazon
environments:
  amazon:
    type: ec2
      access-key: MY AWS ACCESS KEY
      secret-key: MY AWS SECRET KEY
      control-bucket: mattyw-ec2-bucket
      admin-secret: mattyw-ec2-admin

Once you’ve done this, try running juju bootstrap. If it finishes without error wait a minute or so and run juju status, If all goes well you should see something like this

1
2
3
4
5
6
7
8
9
$ juju status
machines:
  "0":
    agent-state: started
    agent-version: 1.11.0
    dns-name: ec2-23-20-228-111.compute-1.amazonaws.com
    instance-id: i-0bfc3d64
    series: precise
services: {}

Now we can start the business of getting a blog up and running:

1
2
3
4
juju deploy wordpress
juju deploy mysql
juju add-relation wordpress mysql
juju expose wordpress

You might have to wait a few minutes for everything to start up, keep taking a look at the output of juju status until you see all the agent-states running and expose true on wordpress.

When it’s done you should see something like this in your juju status output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 wordpress:
    charm: cs:precise/wordpress-15
    exposed: true
    relations:
      db:
      - mysql
      loadbalancer:
      - wordpress
    units:
      wordpress/0:
        agent-state: started
        agent-version: 1.11.0
        machine: "1"
        public-address: ec2-54-234-76-38.compute-1.amazonaws.com

Now point your web browser to the url in public-address and there you go, you’re deploying stuff from your pi.

Juju doesn’t stop at just deploying blogs. Check out Juju to see what else it can do for you

Comments