Skip to content

Instantly share code, notes, and snippets.

@kordless
Created November 8, 2012 02:12
Show Gist options
  • Select an option

  • Save kordless/4036123 to your computer and use it in GitHub Desktop.

Select an option

Save kordless/4036123 to your computer and use it in GitHub Desktop.
Taking OpenStack for a Spin for StackGeek
title: Taking OpenStack for a Spin
author: http://github.com/kordless
summary: Dive into taking OpenStack Essex for a spin on a VMWare Fusion Ubuntu image.
type: post
published: 1329826332

OpenStack is an Open Source cloud computing infrastructure platform originally authored by NASA and RackSpace. OpenStack provides similar services to Amazon's AWS infrastructure platform, except without selling your first born to pay for Amazon's hellaciously expensive instance time.

OpenStack's components are mostly written in Python and include Nova, a fabric controller similar to what EC2 provides, Swift, a S3-like storage system, and Glance, a service for providing services for virtual disk images. Other OpenStack projects include Keystone, an identity service, and Horizon, a Django-based UI framework which ties all these services together in a single webpage view.

As of this writing, the most current version of OpenStack is Essex. Essex is currently in release candidate phase, with RC1 available for download for each of the components listed above. The git repository for the components is available on Github.

I floundered around for a few days trying to download and run the various independent components of OpenStack. The instability of the early versions of Essex and the maze of configuration files you have to tweak make a difficult time of getting it running, at least for me. Thankfully, a bit of Googling revealed a script written by the fine folks over at Rackspace called DevStack, which does all the heavy lifting for getting Openstack running.

Note: Rackspace doesn't recommend using DevStack for production deployments, but it works great if you just want to give OpenStack a test drive and do some quick development on the instances you start.

Getting Started

I've put together a 14 minute step-by-step video guide for getting OpenStack installed on an Oneiric instance running on VMWare Fusion under OSX. The video also guides you through launching an instance and accessing it with a ssh terminal.

<iframe src="http://player.vimeo.com/video/39055026?byline=0&portrait=0" width="420" height="348" frameborder="0"> </iframe>

You can download Oneiric from Ubuntu's website. Get it running on a VM or a bare metal box and make sure you install the OpenSSH server so you can ssh into it.

Using VMWare Fusion

I'm running OpenStack on a dedicated box, but if you run OpenStack on a VM you'll need to ensure you have enough CPU/memory to start instances. You'll need at least 1.5GB to launch a tiny instance. Keep in mind that instance will be a bit slow because it's running a VM on top of another VM.

Here's a screenshot of my VMWare Fusion config set up with a bridged network and about 4GB of RAM with 2 cores assigned:

Checking Out Code

Now that you have a fresh install running, you'll need git installed on your new box. Go ahead and login and do an aptitude update and install it:

sudo apt-get update
sudo apt-get install git

Now let's check out the DevStack code from Github:

git clone https://github.com/openstack-dev/devstack.git

We need to do a couple of things to configuration files before we fire up DevStack, so let's talk about networking for a second.

Networking

Nova does the management for your instance's network. This is similar to the way AWS manages assigning private and public IPs to instances on EC2. IPs are managed across a set of machines on which you run OpenStack, but you'll still need to configure your routing to make these available to your existing network.

If you have a router that can handle static routes, you could simply map the Nova managed network to the interface on the hypervisor (the base host box) to be able to talk to the instances you launch. I have an Airport Extreme at my house and it doesn't have a way to do static routes, so I'm going to explain how to work around that limitation. We'll set it up so our Nova install will get its own network, but we'll use allocated IPs from the existing network so we can provision and map them to the instances we launch with Nova.

Here's are the configs I used in my install. You'll want to put these in a new file called localrc in the devstack directory you just checked out above.

HOST_IP=10.0.1.20
FLAT_INTERFACE=eth0
FIXED_RANGE=10.0.2.0/24
FIXED_NETWORK_SIZE=256
FLOATING_RANGE=10.0.1.224/27

Change the HOST_IP to the address of your hypervisor box (the box on which you are running the devstack script). You can leave the FIXED_RANGE value alone assuming you aren't using 10.0.2.0/24 on your network.

Change the FLOATING_RANGE to whatever IPs you run on your local network, but only use the top end of the network by using a /27 and starting at the 224 octet. Usually you could use an entire /24 (253 addresses from 10.0.2.1 thru 10.0.2.254), but I'm purposely using the /27 so Nova won't start allocating IPs down low at 10.0.1.1, which is my router.

Speaking of routers, be sure to block out these upper IPs; my Airport has a max range setting in it that I set to 200, to prevent IP address overlap with the ones Nova will start at 225.

Add the Oneiric Image

By default devstack only installs a small Cirros distro. I'm an Ubuntu guy, so I hacked up the stackrc file to include a cloud build of Oneiric which will be downloaded when you run the devstack stack.sh script. Scroll down to the bottom of the stackrc file and delete/replace the following lines:

case "$LIBVIRT_TYPE" in
    lxc) # the cirros root disk in the uec tarball is empty, so it will not work for lxc
	IMAGE_URLS="http://cloud-images.ubuntu.com/releases/oneiric/release/ubuntu-11.10-server-cloudimg-amd64.tar.gz,http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-rootfs.img.gz";;
    *)  # otherwise, use the uec style image (with kernel, ramdisk, disk)
	IMAGE_URLS="http://cloud-images.ubuntu.com/releases/oneiric/release/ubuntu-11.10-server-cloudimg-amd64.tar.gz,http://launchpad.net/cirros/trunk/0.3.0/+download/cirros-0.3.0-x86_64-uec.tar.gz";;
esac

Start the Script

The stack.sh script inside the devstack directory will do the rest of the configuration for you. It'll download all the components needed to run OpenStack and stuff them in /opt/stack/. It also downloads the images above and uploads them into Glance so you will have an Ubuntu image you can launch. Start the install process by running the script:

cd devstack
./stack.sh

The script will prompt you for multiple passwords to use for the various components. I used the same pass/key for all the prompts, and suggest you do the same. After the script runs, it'll append the passwords to the localrc file you created earlier:

HOST_IP=10.0.1.20
FLAT_INTERFACE=eth0
FIXED_RANGE=10.0.2.0/24
FIXED_NETWORK_SIZE=256
FLOATING_RANGE=10.0.1.224/27
MYSQL_PASSWORD=f00bar
RABBIT_PASSWORD=f00bar
SERVICE_TOKEN=f00bar
SERVICE_PASSWORD=f00bar
ADMIN_PASSWORD=f00bar

Managing Using the Horizon UI

Once devstack has OpenStack running, you can connect to Horizon, the management UI. The stack.sh script will spit out the URL for you to access the UI:

Horizon is now available at http://10.0.1.x/

Plug this into your browser and then use admin and f00bar for your user/pass. If you made your passwords something else, then obviously use that password here instead of f00bar.

Create Keypairs/Floating IPs/Security Groups

  1. Click on the Project tab on the left side of the screen and then click on Access & Security.
  2. Click on the Allocate IP to Project button at the top and then the Allocate IP button at the bottom of the dialog that pops up. You should see a message that a new IP has been allocated and it should show up in the list of Floating IPs.
  3. Now click on the Create Keypairbutton under Keypairs. Create a key named default and accept the download of the private side of the key to save it on your local machine. You'll need this key later to log into the instance you'll start in a minute.
  4. Finally, click on the Edit Rules button on the default security group under Security Groups. Under Add Rule add rules for pings, ssh and the default web port:

Launch an Instance

Click on the Images & Snapshots tab to view the images you have available. Click on the Launch button next to the flavor of OS you want to launch. In the dialog that pops up, enter the server name and select the default keypair you created earlier. You can also paste in a script in the User Data textbox, which will be run after the machine boots. Here's the one I used to figure out the login user:

#!/bin/bash
cat /etc/passwd

Click on the Launch Instance button at the bottom to launch your instance. You should be taken to the Instances & Volumes tab and shown the status of the instance:

Assign a Floating IP to the Instance

If you are running a network where you can't map static routes in your router, you'll need to assign one of the floating IPs from your network. Click on the Access & Security tab and then click on the Associate IP next to the IP address to assign to the instance.

Click Associate IP to finish assigning the IP to the new instance.

Using Your Instance

Remember the default.pem key that got downloaded earlier? You'll need to go find it and copy it somewhere you won't lose it. You'll also need to change the permissions on it before you use it to login to your new instance:

$ mv default.pem /Users/kord/.ssh/
$ cd /Users/kord/.ssh
$ ssh -i default.pem ubuntu@10.0.1.226
Welcome to Ubuntu 11.10 (GNU/Linux 3.0.0-16-virtual x86_64)

  System information as of Thu Mar 22 22:20:13 UTC 2012

  System load:  0.0              Processes:           57
  Usage of /:   9.8% of 9.84GB   Users logged in:     0
  Memory usage: 20%              IP address for eth0: 10.0.2.2
  Swap usage:   0%

ubuntu@ubuntu:~$ uptime
22:20:32 up 3 days,  2:28,  1 user,  load average: 0.00, 0.01, 0.05

Once you are logged in you can set up your own account and ssh keys to access the box. It took me a bit of floundering to figure out the default user for the cloud version of Oreiric was ubuntu.

More Networking!

If you are running a cluster of servers, you'll need some type of reverse proxy to direct the traffic. It doesn't appear that OpenStack provides this or load balancer features (yet), but there are a few projects that could have APIs added to them to enable future integration into the OpenStack deployment infrastructure.

In the meantime, check out Nodejitsu's Node based HTTP proxy on Github. It's fairly easy to configure and the performance is decent. Here's a version I'm running for reference:

var util = require('util'),
    http = require('http'),
    httpProxy = require('./http-proxy');

//
// Http Proxy Server with Proxy Table
//
httpProxy.createServer({
  router: {
    'spurt.stackgeek.com': '10.0.1.226:80',
    'house.geekceo.com': '10.0.1.19:8080'
  }
}).listen(80);

//
// Target Http Server
//
http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
  console.print("foo");
}).listen(9000);

Maintenance

The OpenStack repos on Github get updated all the time. If you want to stay up-to-date with these changes, I recommend periodically doing a git pull request in each of the directories that get stuffed into /opt/stack/. You can kill your instance of OpenStack before you do this by doing a killall screen.

You can also use the rejoin-stack.sh script if you've already run the script and are wanting to fire it back up again after killing it.

That's about . Be sure to leave comments if you have questions or found errors in the guide!

Happy stacking!

@padrian
Copy link
Copy Markdown

padrian commented Aug 15, 2020

nyce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment