Monday, September 10, 2012

7 Databases - Riak - Setting Up Cluster on EC2

Based on: http://blog.wakatta.jp/blog/2011/12/17/seven-databases-in-seven-weeks-riak-on-ec2/

Log into EC2 -> Instances -> Launch Instance -> Classic Wizard
64bin Amazon Linux
Instance Type: Micro
Defaults for Instance Details screens.
Create new Key Pair: "riak_7databases" (or similar)
Create new Sec Group: "riak-cluster":
    Open up ports: 4369, 8099, 8098, 8087, 6000-6999
Start the instance.
Create two more instances (exactly the same process) and add to the "riak-cluster" security group
Name the instances riak_ec2_1, riak_ec2_2, riak_ec2_3

ssh into each instance (Right-click the instance and Connect for hints) and do the following.

$ wget http://s3.amazonaws.com/downloads.basho.com/riak/CURRENT/rhel/6/riak-1.2.0-1.el6.x86_64.rpm

$ sudo rpm -Uvh riak-1.2.0-1.el6.x86_64.rpm

Safe to ignore following error:
chcon: can't apply partial context to unlabeled file `/usr/lib64/riak/lib/bitcask-1.5.1/priv/bitcask.so'
chcon...


# Get your <IP_ADDRESS>
$ ifconfig  
$ sudo -e /etc/riak/vm.args
# Change name to riak_ec2_1@<IP_ADDRESS>   # or riak_ec2_2/3, etc


$ sudo -e /etc/riak/app.config

# Insert following near the top:

{ kernel, [
            {inet_dist_listen_min, 6000},
            {inet_dist_listen_max, 6999}
            ]},
 
# Change "http" entry to:
 
{http, [ {"127.0.0.1", 8098 }, {"<IP_ADDRESS>", 8098} ]},

$ sudo riak start
 
 
# To test riak installation: 
 
$ curl http://localhost:8098/stats | python -mjson.tool

$ sudo riak-admin test
Attempting to restart script through sudo -H -u riak
Successfully completed 1 read/write cycle to 'riak_ec2_1@10.170.93.188'


# On 2nd and 3rd instances, join the cluster: 
 
$ sudo riak-admin cluster join riak_ec2_1@<IP_ADDRESS>
Attempting to restart script through sudo -H -u riak
Success: staged join request for 'riak_ec2_1@10.170.93.188' to 'riak_ec2_1@10.170.86.93' 


# On any instance: 


$ wget http://wiki.basho.com/attachments/goog.csv
$ wget http://wiki.basho.com/attachments/load_data
 
 
# Need Erlang so 'escript' works:
$ sudo yum install erlang

$ . ./load_data goog.csv

$ curl localhost:8098/riak/goog |python -mjson.tool
 - or browse to public address E.g.:
http://ec2-184-169-247-208.us-west-1.compute.amazonaws.com:8098/riak/goog