Skip to content

Instantly share code, notes, and snippets.

@gerad
Created September 15, 2010 05:45
Show Gist options
  • Save gerad/580290 to your computer and use it in GitHub Desktop.
Save gerad/580290 to your computer and use it in GitHub Desktop.
setup openinviter on ec2

setup the instance

locally

go to the amazon web interface

note your AWS_USER_ID in the upper right hand corner. create a new AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

edit ~/.ec2/aws-keys

> vi ~/.ec2/aws-keys

and save the information

export AWS_USER_ID=XXXX-XXXX-XXXX
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=xXxXXXxxXXXxXxxxXxxXXXXxXxXXxXxXxxXXxXxX

create a new X.509 certificate, download the private key and certificate files, and then save the files in $HOME/.ec2/

> mv ~/Downloads/*.pem ~/.ec2/

setup permissions on ~/.ec2

chmod 0600 ~/.ec2/*
chmod 0700 ~/.ec2

if needed, install the tools for working with ec2

> brew install ec2-api-tools
> brew install ec2-ami-tools

add the following lines to your .profile

export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home"
export EC2_PRIVATE_KEY="$(/bin/ls $HOME/.ec2/pk-*.pem)"
export EC2_CERT="$(/bin/ls $HOME/.ec2/cert-*.pem)"
export EC2_AMITOOL_HOME="/usr/local/Cellar/ec2-ami-tools/1.3-45758/jars"
export EC2_HOME="/usr/local/Cellar/ec2-api-tools/1.3-53907/jars"

open a new shell, or

> source ~/.profile

create a new key pair for sever auth

> ec2-add-keypair identified-openinviter > identified-openinviter.pem
> chmod 0600 identified-openinviter.pem

copy that key to ~/.ec2/ as well

> cp identified-openinviter.pem ~/.ec2/

start-up a canonical provided ubuntu image (list of latest images available at: http://uec-images.ubuntu.com/releases/lucid/release/), here's the choice I made

  • us-east-1 - cheaper colo

  • 32-bit - more compatible

  • ebs - simpler storage, micro instances require it note: we're setting up the instance on a small (rather than micro) platform because we need /mnt (not available on micro) to do the bundling. Once we have our new instance handy, we will move it to micro.

    ec2-run-instances ami-1234de7b --instance-type m1.small --region us-east-1 --key identified-openinviter

wait until it's running by watching ec2-describe-instances for the string running

> ec2-describe-instances 

edit your ~/.ssh/config file to make it easy to ssh into the new instance note: the HostName and HostKeyAlias will change based on the output provided by ec2-describe-instances.

Host identified-openinviter
  HostName ec2-184-73-59-131.compute-1.amazonaws.com
  HostKeyAlias ec2-184-73-59-131.compute-1.amazonaws.com
  User ubuntu
  IdentityFile ~/.ec2/identified-openinviter.pem

download OpenInviter (the general, non-hosted version) from: http://openinviter.com/download.php

copy openinviter to the server

> scp ~/Downloads/openinviter.tar.gz identified-openinviter:

ssh into your instance

> ssh identified-openinviter

on the remote machine

set it up as a basic server

> sudo tasksel --server

The settings I used

* Basic Ubuntu server - left unchanged (enabled)
* OpenSSH server - left unchanged (enabled)
* Ubuntu Enterprise Cloud (instance) - DISABLED

install php5

> sudo apt-get install php5 php5-cli php5-curl

install openinviter

> tar xzf openinviter.tar.gz
> sudo mv OpenInviter/ /var/www/openinviter

setup permissions correctly

> sudo chown -R root:root /var/www/openinviter
> sudo find /var/www/openinviter -type d | sudo xargs chmod 0755
> sudo find /var/www/openinviter -type f | sudo xargs chmod 0644

run the install script

> sudo php5 /var/www/openinviter/postinstall.php

remove the postinstall script

> sudo mv /var/www/openinviter/postinstall.php /var/www/openinviter/postinstall.php.removed

move the suggested config script into place

> sudo mv config.php /var/www/openinviter/config.php

install apache2

> sudo apt-get install apache2

create an apache site config for openinviter

> sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/openinviter

note: you should almost certainly setup ssl in production

edit the file

> sudo vi /etc/apache2/sites-available/openinviter

give it reasonable defaults

<VirtualHost *:80>
        ServerAdmin webmaster@identified.com

        DocumentRoot /var/www/openinviter
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
</VirtualHost>

enable the new site

> sudo a2dissite default
> sudo a2ensite openinviter
> sudo /etc/init.d/apache2 reload

locally

http://ec2-184-73-59-131.compute-1.amazonaws.com/example.php (the domain will be different) to make sure it works

bundle the instance

locally

copy your aws auth to the remote instance

> scp -r ~/.ec2 identified-openinviter:ec2

on the remote machine

move the auth keys to /mnt/

sudo mv ec2 /mnt/

enable multiverse, edit /etc/apt/sources.list

> sudo vi /etc/apt/sources.list

and replace the universe lines with multiverse lines

# deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid main universe
# deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid main universe
# deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid-updates main universe
# deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid-updates main universe
# deb http://security.ubuntu.com/ubuntu lucid-security main universe
# deb-src http://security.ubuntu.com/ubuntu lucid-security main universe

deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid main multiverse
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid main multiverse
deb http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid-updates main multiverse
deb-src http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ lucid-updates main multiverse
deb http://security.ubuntu.com/ubuntu lucid-security main multiverse
deb-src http://security.ubuntu.com/ubuntu lucid-security main multiverse

install ec2-api-tools

> sudo apt-get install ec2-ami-tools
> sudo apt-get install ec2-api-tools

get it ready for micro, comment out the following line in /etc/fstab

> sudo vi /etc/fstab
# /dev/sda2	/mnt	auto	defaults,comment=cloudconfig	0	0

for more, see

  1. http://stackoverflow.com/questions/3679156/ec2-small-to-micro-instance-downgrade-problems
  2. http://www.mail-archive.com/ubuntu-bugs@lists.ubuntu.com/msg2480051.html

setup environment variables

source /mnt/ec2/aws-keys
export EC2_PRIVATE_KEY=/mnt/ec2/pk-*.pem
export EC2_CERT=/mnt/ec2/cert-*.pem
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/

clean up after yourself before you save your tracks forever

> history -c && sudo rm -f /root/.*hist* /home/ubuntu/.*hist*

This link has been useful for the next few steps: http://alestic.com/2009/06/ec2-ami-bundle

Bundle the files on the current instance into a copy of the image under /mnt note: this takes a while so you may want to run it under screen.

> sudo ec2-bundle-vol                   \
  -r i386                               \
  -k $EC2_PRIVATE_KEY                   \
  -c $EC2_CERT                          \
  -u $AWS_USER_ID                       \
  -d /mnt                               \
  -p openinviter-ebs                    \
  -e /mnt,/root/.ssh,/home/ubuntu/.ssh

Upload the bundle to a bucket on S3

> ec2-upload-bundle                     \
  -b openinviter.fortnightlabs.com      \
  -m /mnt/openinviter-ebs.manifest.xml  \
  -a $AWS_ACCESS_KEY_ID                 \
  -s $AWS_SECRET_ACCESS_KEY

register the image as a new AMI.

> ec2-register                                                \
  --name openinviter.fortnightlabs.com/openinviter-ebs        \
  -K $EC2_PRIVATE_KEY                                         \
  -C $EC2_CERT                                                \
  openinviter.fortnightlabs.com/openinviter-ebs.manifest.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment