Dashboard > CI Development > ... > Data Distribution Network > EC2 AMI creation
Log In   View a printable version of the current page.
CI Development
EC2 AMI creation
Added by Dorian Raymer , last edited by Dorian Raymer on Jan 27, 2009  (view change)
Labels: 
(None)

ERDDAP AMI

$ ec2-run-instances -k ooikeypair ami-1cd73375

$ adduser tomcat

upadate system and get java6-jdk

$ apt-get update && apt-get install sun-java6-jdk

download tomcat

$ wget http://www.eng.lsu.edu/mirrors/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
$ tar zxvf apache-tomcat-6.0.18.tar.gz
$ mv apache-tomcat-6.0.18.tar.gz /opt

$ wget http://amoeba.ucsd.edu/fileshare/scripts/mgmt_agent

edit the file, change agent.tac to erddap.tac

$ chmod +x mgmt_agent
$ cp mgmt_agent /etc/init.d/
$ update-rc.d mgmt_agent start 90 2 .

copy erddap-ooi-0.1.tar.gz from amoeba

$ wget http://amoeba.ucsd.edu/fileshare/apps/erddap-ooi-latest.tar.gz
$ tar zxvf erddap-ooi-0.1.tar.gz
$ mv erddap-ooi /opt/apache-tomcat-6.0.18/webapps/

$ mkdir /opt/apache-tomcat-6.0.18/content
$ cp -r /opt/apache-tomcat-6.0.18/webapps/erddap-ooi/content.def/erddap /opt/apache-tomcat-6.0.18/content

edit content/erddap/setup.xml (options listed in components page)
In "/opt/apache-tomcat-6.0.18/content/erddap/setup.xml":
set bigParentDirectory to /home/tomcat/
set baseUrl
set broker host

in webapps, ln -s erddap-ooi erddap:
$ ln -s /opt/apache-tomcat-6.0.18/webapps/erddap-ooi/ /opt/apache-tomcat-6.0.18/webapps/erddap

$ chown -R tomcat:tomcat /opt/apache-tomcat-6.0.18/

$ su tomcat

start tomcat
$ /opt/apache-tomcat-6.0.18/bin/startup.sh

RabbitMQ - Message Broker

Add this line:
"deb http://www.rabbitmq.com/debian/ testing main" to "/etc/apt/source.list"

Add rabbitmq key
wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc

$ apt-get update
$ apt-get install rabbitmq-server

Now that rabbitmq-server is installed, we have the script

/etc/init.d/rabbitmq-server

that gets run on boot.
(we are still having rabbitmq-server startup issues, possibly an EC2 hostname issue
see this rabbitmq-discuss thread: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2008-March/000973.html)

We have found that if rabbitmq gets in the above failed state, a "full restart" can be accomplished by the following:

#first kill all 'rabbitmq' processes
rm -rf /var/lib/rabbitmq/*
/etc/init.d/rabbitmq-server start
rabbitmqctl delete_user guest
rabbitmqctl add_user ddnuser pw4ddnpass
rabbitmqctl map_user_vhost ddnuser /
rabbitmqctl set_permissions ddnuser / /data all

=>It should be noted that there are possibly better solutions, but we don't have one yet

#by hand, one can start up the server:
/etc/init.d/rabbitmq-server start

#these commands must be run as user "rabbitmq":
$ rabbitmqctl_real status
$ rabbitmqctl_real delete_user guest
$ rabbitmqctl_real add_user ddnuser ddnpass
$ rabbitmqctl_real map_user_vhost ddnuser /
$ rabbitmqctl_real set_permissions ddnuser / /data all

Memcached

refs:
Distributed Caching with Memcached
mmcached - a hierarchical extension to memcached
http://www.ajohnstone.com/archives/installing-memcached/

$ apt-get update
$ apt-get install python-twisted build-essential

$ wget http://amoeba.ucsd.edu/fileshare/support/txamqp-rev3.tgz
$ tar xvzf txamqp-rev3.tgz
$ cd txamqp; python setup.py install
$ wget http://amoeba.ucsd.edu/fileshare/support/qpid-1.0-incubating-M2.1-python-src.tar.gz
$ tar zxvf qpid-1.0-incubating-M2.1-python-src.tar.gz; cd qpid-1.0-incubating-M2.1/python/; python setup.py install

$ wget http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
$ wget http://www.monkey.org/~provos/libevent-1.3e.tar.gz
$ tar xvfz libevent-1.3e.tar.gz
$ cd libevent-1.3e/
$ ./configure
$ make; make install
$ tar xvfz memcached-1.2.6.tar.gz
$ cd memcached-1.2.6/
$ ./configure
$ make; make install

$ adduser apps

get the mgmt agent, need to edit this once it's downloads!

$ wget http://amoeba.ucsd.edu/fileshare/scripts/mgmt_agent

$ chmod +x mgmt_agent
$ cp mgmt_agent /etc/init.d/
$ update-rc.d mgmt_agent start 90 2 .

Schedule Dispatcher

$ apt-get update
$ apt-get install python-twisted bzr
$ scp dev@amoeba.ucsd.edu:/home/dev/basic_txamqp_client.py . #get latest
$ scp dev@amoeba.ucsd.edu:/home/dev/schedule_dispatcher.py . #get latest
$ scp dev@amoeba.ucsd.edu:/home/dev/amqp0-8.xml .
$ wget http://amoeba.ucsd.edu/fileshare/support/txamqp-rev3.tgz
$ tar xvzf txamqp-rev3.tgz
$ cd txamqp; python setup.py install
$ wget http://www.apache.org/dist/incubator/qpid/M2.1-incubating/qpid-1.0-incubating-M2.1-python-src.tar.gz
$ tar zxvf qpid-1.0-incubating-M2.1-python-src.tar.gz; cd qpid-1.0-incubating-M2.1/python/; python setup.py install

$ adduser scheduler
$ mv amqp0-8.xml basic_txamqp_client.py schedule_dispatcher.py /home/scheduler/
$ cd /home/scheduler; chown scheduler:scheduler amqp0-8.xml basic_txamqp_client.py schedule_dispatcher.py
$ su scheduler
$ twistd -ny schedule_dispatcher.py


start_dispatcher.sh:
sudo -u scheduler /usr/bin/twistd --pidfile /home/scheduler/dispatcher.pid --logfile /home/scheduler/dispatcher.log -y /home/scheduler/schedule_dispatcher.py

chmod +x start_dispatcher.sh; mv start_dispatcher.sh /etc/init.d/; update-rc.d start_dispatcher.sh defaults

(NOTE: basic_txamqp_client.py needs 'SPECFILE' abspath)
import sys; sys.path.append("/home/scheduler/") OR export PYTHONPATH=${PYTHONPATH}:/home/scheduler/

Load Balancer / Reverse proxy

(will be assigned a Elastic IP so it remains constant)

$ apt-get update
$ apt-get install -y build-essential libssl-dev libpcre3-dev
$ wget http://sysoev.ru/nginx/nginx-0.7.19.tar.gz
$ wget amoeba.ucsd.edu/fileshare/support/nginx_upstream_hash-0.3.tar.gz
$ cd nginx-0.7.19; patch -p0 < ../nginx_upstream_hash-0.3/nginx.patch; ./configure --with-http_ssl_module --add-module=../nginx_upstream_hash-0.3/
$ make; make install

#start nginx:
$ /usr/local/nginx/sbin/nginx
#test the nginx conf file for validity:
$ /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
#hot reload
$ kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

#media files for registration app (served by nginx via /media)
$adduser registration

#needs to be dynamically added
$wget amoeba.ucsd.edu/fileshare/support/regapp-media.tar.gz

#tar zxvf regapp-media.tar.gz -> media -> (media/{css,js,img} and media/admin/{css,js,img})
#where 'media/admin/{css,js,img}' is from '/usr/lib/python2.5/site-packages/django/contrib/admin/media/'
tar zxf regapp-media.tar.gz; mv media /home/registration/; chown -R registration:registration /home/registration/media

Registration App

$ apt-get update
$ wget http://www.djangoproject.com/download/1.0/tarball/; python setup.py install
$ apt-get install -y python-mysqldb python-flup
$ wget amoeba.ucsd.edu/fileshare/apps/ddnregistration-latest.tar.gz

amqplib:

$ wget http://barryp.org/static/software/download/py-amqplib/0.5/amqplib-0.5.tgz
$ tar zxvf amqplib-0.5.tgz; python setup.py install
dap:
$ wget http://amoeba.ucsd.edu/fileshare/support/dap-2.2.6-ooi-pickleable.tar.gz
$ tar xvzf dap-2.2.6-ooi-pickleable.tar.gz
$ cd dap-2.2.6-ooi-pickleable
$ python setup.py install
memcached client
$ easy_install python-memcached

#start up reg app:
$ python manage.py runfcgi method=threaded host=$INTERNAL_IP port=8000

Data Mirror


Base, S3FS
...
apt-get update &&  apt-get install -y subversion build-essential libcurl4-openssl-dev libxml2-dev libfuse-dev
svn checkout http://s3fs.googlecode.com/svn/trunk/s3fs s3fs
make -C s3fs/
cp s3fs/s3fs /usr/local/bin/
*make a s3fs called 'ddnrepo':*
mkdir /mnt/ddnrepo
/usr/local/bin/s3fs ddnrepo \-o allow_other \-o accessKeyId=XXX \-o secretAccessKey=XXX /mnt/ddnrepo/


Tomcat, Thredds, ERDDAP, mgmt_agent, Dataset Utils
....


apt-get install sun-java6-jdk python-setuptools
easy_install dap
easy_install python-memcached

adduser tomcat
cd
wget http://www.eng.lsu.edu/mirrors/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
tar zxvf apache-tomcat-6.0.18.tar.gz
mv apache-tomcat-6.0.18 /opt

wget ftp://ftp.unidata.ucar.edu/pub/thredds/3.16/thredds.war
cp thredds.war /opt/apache-tomcat-6.0.18/webapps/

wget http://amoeba.ucsd.edu/fileshare/apps/erddap-ooi-latest.tar.gz
tar zxvf http://amoeba.ucsd.edu/fileshare/apps/erddap-ooi-latest.tar.gz
mv erddap-ooi /opt/apache-tomcat-6.0.18/webapps/

wget http://amoeba.ucsd.edu/fileshare/scripts/mgmt_agent
chmod +x mgmt_agent
cp mgmt_agent /etc/init.d/
update-rc.d mgmt_agent start 90 2 .

wget http://barryp.org/static/software/download/py-amqplib/0.5/amqplib-0.5.tgz
tar zxvf amqplib-0.5.tgz; cd amqplib-0.5; python setup.py install

wget http://amoeba.ucsd.edu/fileshare/support/erddap_dataset_util2.py
wget http://amoeba.ucsd.edu/fileshare/support/datasetXML.py
wget http://amoeba.ucsd.edu/fileshare/support/message_utils.py
wget http://amoeba.ucsd.edu/fileshare/support/thredds_utils.py
wget http://amoeba.ucsd.edu/fileshare/support/data_repo_actions.py

after writing some files in '/mnt/ddnrepo', view them with boto:

from boto.s3.connection import S3Connection
s3conn = S3Connection("AWS_ACCESS_KEY", "AWS_SECRET_KEY")
ddnrepo = s3.get_bucket("ddnrepo")
list(ddnrepo.list())

unmount the 'ddnrepo':
$ umount /mnt/ddnrepo

MySQL Cluster

API (mysqld) nodes

ami-id ami-4137d328

#do this on all mysqld api nodes:
$ mysql -u root -e "create database registration" -p
$ mysql -u root -e "GRANT ALL PRIVILEGES ON registration.* to 'reguser'@'%' IDENTIFIED by 's0me0o1reg_pass'" -p

Storage (ndb) nodes

ami-id ami-6737d30e

#EBS storage for the ndb nodes:
#1)first check to see if /dev/sdh exists - if the EBS volume is attached
#2) make a mount point and mount it
$ mkdir /mnt/ebs-drive
$ mkfs.ext3 /dev/sdh1
$ mount /dev/sdh1 /mnt/ebs-drive/
#now make symbolic link from the mysql-cluster data and the ebs-drive
$ ln -s /mnt/ebs-drive/ /var/lib/mysql-cluster


Provisioner - Provisions Cloud Resources

The provisioner will handle the initialization of all resources
(i.e. It will start each resource in an appropriate order - a process that depends on certain
returned values (e.g. the IP of the Message Broker),


Base AMI creation:

The AMI with id 'ami-1cd73375' is from alestic.com. It is also important to note that this is
an Ubuntu 8.04 base install, not a desktop. Base install start much faster and are leaner
all around.

$ ec2-run-instances -k your_keypair  ami-1cd73375

Bundling process

put your keys on the running instance that you want to bundle:

$ scp -i .ec2/your_keypair.private .ec2/cert-XXXX.pem .ec2/pk-XXXX.pem root@XXX.compute-1.amazonaws.com:/mnt

create the bundle ($AWS_ACCOUNT_NUMER can be found under 'Account Activity' inside the AWS account)

$ ec2-bundle-vol -d /mnt/ -k /mnt/pk-XXXX.pem -c /mnt/cert-XXXX.pem -u $AWS_ACCOUNT_NUMBER -r i386 -p _name-of-image_

name-of-image is something like: memcached-image, or erddap-ooi-image, etc.

save the bundle in the ooi-ddn-images bucket on S3:

$ ec2-upload-bundle -b ooi-ddn-images -m /mnt/image.manifest.xml -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY

now, on your local machine, using the api tools, register the AMI:

$ ec2-register ooi-ddn-images/_name-of-image_.manifest.xml

now check to see that is has appear in your images:

$ ec2-describe-images

DDN application packages on S3

Motivation: We want our application packages highly available and quickly downloadable
We are using 's3fs' to have a directory on amoeba map to a S3 bucket
The directory is '/mnt/ddn-packages', and was setup like so:
(first create a bucket on S3 called 'ddn-packages')
$ mkdir -p /mnt/ddn-packages
$ chown dev:dev /mnt/ddn-packages
$ sudo s3fs ddn-packages -o allow_other -o default_acl=public-read /mnt/ddn-packages/

Setting up EC2 AMI tools (for Debian based linux)

$ sudo apt-get install alien ruby libopenssl-ruby1.8 rsync curl
$ wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm
$ alien -i ec2-ami-tools.noarch.rpm
$ export RUBYLIB=/usr/lib/site_ruby #do this as root because 'ec2-bundle-vol' needs root
#ec2-bundle-vol, etc should now work

Contextualization

If you start an AMI with the '-d' flag, (e.g. ec2-run-instances -k your_keypair ami-1cd73375 -d "key=value")
then this data will be accesible via the following URL: "http://169.254.169.254/latest/user-data"

startup hooks:
http://groups.google.com/group/ec2ubuntu/browse_thread/thread/c228d509ef31c630/ff4e570caade4729
Look in "/var/log/syslog" to see result of "user-data" scripts that ran (succes and error codes, etc)

access the user-data and meta-data (with python):

import urllib2
urllib2.urlopen("http://169.254.169.254/latest/user-data").read()
urllib2.urlopen("http://169.254.169.254/latest/meta-data/public-hostname").read()

OOI packages

Versions of packages we make should go here: dev@amoeba:~/ddn/apps
These packages should be gzipped tar archives with this name format:
package_name-latest.tar.gz

the apps, support, and scripts directories in ~/ddn are linked to from /var/lib/nginx/html/fileshare

Export a git repository to a tar archive

git archive --format=tar --prefix=/ HEAD | gzip > [project-version].tar.gz

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators