Skip to content

Starcluster ami cookbook scientific linux 6.4

Gavin Burris edited this page Sep 30, 2013 · 8 revisions

Here is the build log for a Scientific Linux AMI: ami-8f3e69e6

This image is based off of Jamie Kinney's Scientific Linux 6.4 x86_64 HVM AMI.

$ starcluster start -o -s 1 -i m3.xlarge -n ami-07c9be6e imagehost
$ starcluster listclusters --show-ssh-status imagehost
$ starcluster sshmaster imagehost
# cd /opt
# wget http://dl.dropbox.com/u/47200624/respin/ge2011.11.tar.gz
# tar xzvf ge2011.11.tar.gz
# mv ge2011.11 sge6-fresh
# rm ge2011.11.tar.gz
# yum -y install yum-fastestmirror yum-conf-epel
# yum -y update
# yum -y install openmpi-devel nfs-utils-lib-devel java-1.6.0-openjdk-devel tmux zsh ksh tcsh \
  unzip mysql-server mysql httpd emacs ntsysv freetype-devel libpng-devel blas-devel lapack-devel \
  atlas-devel lbzip2 bzip2-devel ncurses-devel sqlite-devel zlib-devel libjpeg-devel mercurial ipython \
  python-imaging python-boto python-virtualenv Cython python-nose python-gnutls python-pip ruby
# yum -y install gsl armadillo libstdc++ glibc libgcc lapack blas atlas libgfortran
# vim /etc/inittab
    id:3:initdefault:
# vim /etc/selinux/config
    SELINUX=permissive
# setenforce 0
# chkconfig iptables off
# service iptables stop
# init 3
# echo "exit 0" >> /etc/init.d/portmap
# chmod +x /etc/init.d/portmap
# yum -y groupinstall "Development Tools"
# yum -y install infinipath-psm-devel
# yumdownloader --source openmpi
# rpm --import https://www.redhat.com/security/fd431d51.txt
# yum-builddep openmpi-1.5.4-1.el6.src.rpm
# rpm -ivh openmpi-1.5.4-1.el6.src.rpm
# rpmbuild -bb --define 'configure_options --with-sge' /root/rpmbuild/SPECS/openmpi.spec
# yum remove openmpi openmpi-devel
# rpm -Uhv /root/rpmbuild/RPMS/x86_64/openmpi-1.5.4-1.el6.x86_64.rpm /root/rpmbuild/RPMS/x86_64/openmpi-devel-1.5.4-1.el6.x86_64.rpm
# echo "exclude=openmpi*" >> /etc/yum.conf
# . /etc/profile.d/modules.sh
# module load openmpi-x86_64
# ompi_info | grep -i grid
    MCA ras: gridengine (MCA v2.0, API v2.0, Component v1.5.4)
# echo "module load openmpi-x86_64" >> /etc/profile.d/zzlocal.sh
# echo "module load openmpi-x86_64" >> /etc/profile.d/zzlocal.csh
# echo 'export PYTHONPATH=/usr/local/lib64/python2.6/site-packages:$PYTHONPATH' >> /etc/profile.d/zzlocal.sh
# echo 'setenv PYTHONPATH /usr/local/lib64/python2.6/site-packages:$PYTHONPATH' >> /etc/profile.d/zzlocal.csh
# chmod +x /etc/profile.d/zzlocal.*
# . /etc/profile.d/zzlocal.sh
# pip-python install --install-option="--prefix=/usr/local" mpi4py
# pip-python install --install-option="--prefix=/usr/local" numpy
# pip-python install --install-option="--prefix=/usr/local" scipy
# chmod u=rwx,go= /root
# vim /etc/rc.local # see below
# /etc/rc.local
# exit
$ starcluster listclusters
    master running i-xxxxxxxx ec2-XX-XX-XXX-XXX.compute-1.amazonaws.com
$ starcluster ebsimage i-xxxxxxxx starcluster-base-scientific-linux-6.4-x86_64-ebs-hvm-XX
    >>> Your new AMI id is: ami-xxxxxxxx
$ starcluster terminate imagehost

/etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

if [ ! -d /root/.ssh ] ; then
    mkdir -p /root/.ssh
    chmod 0700 /root/.ssh
    restorecon /root/.ssh
fi

# bz 707364
if [ ! -f /etc/blkid/blkid.tab ] ; then
        blkid /dev/xvda &>/dev/null
fi

ATTEMPTS=5
FAILED=0
# Fetch public key using HTTP
while [ ! -f /root/.ssh/authorized_keys.aws ]; do
    curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/aws-key 2>/dev/null
    if [ $? -eq 0 ]; then 
        cat /tmp/aws-key >> /root/.ssh/authorized_keys.aws
        cat /root/.ssh/authorized_keys.aws >> /root/.ssh/authorized_keys
        chmod 0600 /root/.ssh/authorized_keys
        restorecon /root/.ssh/authorized_keys
        rm -f /tmp/aws-key
        echo "Successfully retrieved AWS public key from instance metadata"
    else
        FAILED=$(($FAILED + 1))
        if [ $FAILED -ge $ATTEMPTS ]; then 
            echo "Failed to retrieve AWS public key after $FAILED attempts, quitting"
            break
        fi
        echo "Could not retrieve AWS public key (attempt #$FAILED/$ATTEMPTS), retrying in 5 seconds..."
        sleep 5
    fi
done
rm -f /root/.ssh/authorized_keys.aws

# update ec2-ami-tools
#wget http://s3.amazonaws.com/ec2-downloads/ec2-ami-tools.noarch.rpm && \
#rpm -Uvh ec2-ami-tools.noarch.rpm

# reset root password
dd if=/dev/urandom count=50|md5sum|passwd --stdin root