Created
April 13, 2011 21:13
-
-
Save asimihsan/918435 to your computer and use it in GitHub Desktop.
Erlang on AWS: Part 2 (http://www.asimihsan.com/articles/zero_to_hero_erlang_on_aws_part_02.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: /home/ubuntu/.aws_keys | |
export AWS_ACCESS_KEY_ID=XXXXXXXXX | |
export AWS_ACCOUNT_ID=1111111111 | |
export AWS_SECRET_ACCESS_KEY=fFjerT235Fj | |
# subsequently modify /home/ubuntu/.bash_profile and "dot this in" by using: | |
# . /home/ubuntu/.aws_keys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 | |
Type "copyright", "credits" or "license()" for more information. | |
DreamPie 1.0 | |
>>> from boto.ec2.connection import EC2Connection | |
... conn = EC2Connection() | |
... region_eu = [region for region in conn.get_all_regions() if "eu-west" in region.name][0] | |
... conn_eu = region_eu.connect() | |
... conn_eu | |
0: EC2Connection:ec2.eu-west-1.amazonaws.com | |
>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# create loadbalancer group, or use conn_eu.get_all_security_groups() | |
# if it already exists. replace "your.private.ip" with your private | |
# IP address, as we're restricting SSH access to your IP address. | |
# ---------------------------------------------------------------------- | |
loadbalancer = conn_eu.create_security_group("loadbalancer", "Load Balancer Group") | |
loadbalancer.authorize("tcp", 80, 80, "0.0.0.0/0") | |
loadbalancer.authorize("tcp", 443, 443, "0.0.0.0/0") | |
loadbalancer.authorize("ssh", 22, 22, "your.private.ip/32") | |
# ---------------------------------------------------------------------- | |
# we're going to use the AMI we cooked ahead of time. | |
# ---------------------------------------------------------------------- | |
image = conn_eu.get_image("ami-4fe7d03b") | |
key_name = "ai_keypair" | |
security_groups = [loadbalancer] | |
reservation = image.run(key_name=key_name, security_groups=security_groups, instance_type="t1.micro") | |
instance = reservation.instances[0] | |
# ---------------------------------------------------------------------- | |
# update, get state, repeat | |
# ---------------------------------------------------------------------- | |
instance.update(); instance.state | |
# ---------------------------------------------------------------------- | |
# eventually instance.state becomes running. instance.public_dns_name | |
# contains that hostname you need to connect to as you've done before. | |
# ---------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# Open /etc/rsyslog.d/haproxy.conf, add the following: | |
# ---------------------------------------------------------------------- | |
# .. otherwise consider putting these two in /etc/rsyslog.conf instead: | |
$ModLoad imudp | |
$UDPServerRun 514 | |
# ..and in any case, put these two in /etc/rsyslog.d/haproxy.conf: | |
local0.* -/var/log/haproxy_0.log | |
local1.* -/var/log/haproxy_1.log | |
# ---------------------------------------------------------------------- | |
# Save, close the file | |
# ---------------------------------------------------------------------- | |
# ---------------------------------------------------------------------- | |
# Execute: | |
# ---------------------------------------------------------------------- | |
restart rsyslog | |
# to see HAProxy logs, execute the command below. Of course, there will | |
# not be anything there for now. | |
tail -f /var/log/haproxy*.log | |
# ---------------------------------------------------------------------- | |
# Set up log rotation in /etc/logrotate.d/haproxy: | |
# ---------------------------------------------------------------------- | |
/var/log/haproxy.log | |
{ | |
rotate 4 | |
weekly | |
missingok | |
notifempty | |
compress | |
delaycompress | |
sharedscripts | |
postrotate | |
reload rsyslog >/dev/null 2>&1 || true | |
endscript | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ---------------------------------------------------------------------- | |
# Bare essentials. | |
# ---------------------------------------------------------------------- | |
sudo cp /etc/apt/sources.{list,list.backup} | |
sudo vim /etc/apt/sources.list | |
# enable multiverse inside this file, save it, close it. | |
# ---------------------------------------------------------------------- | |
# Install Java. | |
# ---------------------------------------------------------------------- | |
sudo add-apt-repository ppa:sun-java-community-team/sun-java6 | |
sudo apt-get update | |
yes yes | sudo apt-get upgrade | |
yes yes | sudo apt-get install git mercurial build-essential unzip sun-java6-jre sun-java6-bin sun-java6-jdk python-software-properties ruby | |
# ---------------------------------------------------------------------- | |
# Update your bash_profile. | |
# ---------------------------------------------------------------------- | |
vim ~/.bash_profile | |
# add the following lines to your bash_profile: | |
JAVA_HOME="/usr/lib/jvm/java-6-sun" | |
export JAVA_HOME | |
PATH="${PATH}:${JAVA_HOME}/bin" | |
export PATH | |
# save it, close it. | |
# ---------------------------------------------------------------------- | |
# Install Python and other bits. | |
# | |
# References: | |
# - http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python | |
# ---------------------------------------------------------------------- | |
yes yes | sudo apt-get install zlib1g-dev libreadline5-dev uuid-dev openssl libssl-dev bzip2 libbz2-dev | |
mkdir ~/downloads && cd ~downloads | |
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz | |
tar xvf Python-2.7.1.tgz | |
cd Python-2.7.1 | |
./configure --prefix=/usr/local/ | |
make | |
sudo make install | |
# now some finicky stuff to get pip set up. | |
cd ~ | |
mkdir -p ~/.local | |
# add ~/.local/bin to PATH, ~/.local to PYTHONPATH, in ~/.bash_profile | |
vim ~/.pydistutils.cfg | |
# add the following to .pydistutils.cfg: | |
[install] | |
prefix=~/.local | |
# save it, close it, relaunch bash by e.g. logging in/out. | |
mkdir -p /home/ubuntu/.local/lib/python2.7/site-packages/ | |
mkdir -p ~/downloads && cd ~/downloads | |
curl -O http://python-distribute.org/distribute_setup.py | |
python distribute_setup.py | |
easy_install pip | |
pip install virtualenv | |
pip install virtualenvwrapper | |
mkdir -p ~/.virtualenvs | |
vim ~/.bash_profile | |
# append the following to .bash_profile: | |
export WORKON_HOME | |
source ~/.local/bin/virtualenvwrapper.sh | |
# save it, close it, relaunch the shell by e.g. logging in/out | |
# test your shell by running: | |
pip install boto | |
python | |
import boto | |
boto.__version__ | |
exit() | |
# you should be able to install boto, run python, and import it. | |
# ---------------------------------------------------------------------- | |
# Install Erlang. | |
# http://wiki.basho.com/Installing-Erlang.html | |
# ---------------------------------------------------------------------- | |
yes yes | sudo apt-get install curl m4 flex xsltproc fop libncurses5-dev unixodbc-dev | |
mkdir -p ~/downloads && cd ~/downloads | |
wget http://www.erlang.org/download/otp_src_R14B02.tar.gz | |
tar xvf otp_src_R14B02.tar.gz | |
cd otp_src_R14B02 | |
./configure | |
make | |
sudo make install | |
# ---------------------------------------------------------------------- | |
# Cleanup | |
# ---------------------------------------------------------------------- | |
cd ~ | |
rm -rf ~/downloads | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment