Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (112 sloc) 7.04 KB

DESCRIPTION:

This script launches a Apache Cassandra cluster of a predetermined size.

This has been tested in Ubuntu 10.10 and CentOS 5.5, but should support your version of Ubuntu, CentOS, and RedHat.

This script will be developed and housed at: github.com/riptano/chef.

REQUIREMENTS:

Follow the instructions as listed here: wiki.opscode.com/display/chef/Quick+Start.

Configure cloud access

Proceed to configure your cloud access by adding these following lines to your ~/.chef/knife.rb file.

# Information can be found at: https://manage.rackspacecloud.com/APIAccess.do
knife[:rackspace_api_username] = "USER"
knife[:rackspace_api_key]      = "KEY"

# Information can be found at: https://aws-portal.amazon.com/gp/aws/developer/account?ie=UTF8&action=access-key
knife[:aws_access_key_id]     = "ID"
knife[:aws_secret_access_key] = "KEY"

Place this directory into your cookbooks folder.

Download and place the apt cookbook in your cookbooks folder. The apt cookbook can be found here: community.opscode.com/cookbooks/apt.

Then run:

knife cookbook upload -a -o cookbooks/

You should see something similar to:

Uploading apt                     [1.1.2]
Uploading cassandra               [0.1.4]
Uploading chef-client             [0.99.5]
upload complete

ATTRIBUTES:

The main attributes to look can be found at $CHEF_HOME/cookbooks/cassandra/attributes/default.rb and are:

# Needed for the Chef script to function properly
default[:setup][:deployment] = "08x"    # Choices are "07x", or "08x"
default[:setup][:cluster_size] = 4
default[:setup][:current_role] = "cassandra"

# A unique name is preferred to stop the risk of different clusters joining each other
default[:cassandra][:cluster_name] = "Cassandra Cluster"

# It is best to have the commit log and the data
# directory on two seperate drives
default[:cassandra][:commitlog_dir] = "/var/lib"
default[:cassandra][:data_dir] = "/var/lib"

For more information, look over $CHEF_HOME/cookbooks/cassandra/metadata.rb.

To obtain a free OpsCenter license, please visit: www.datastax.com/opscenter.

After properly configuring the attributes, upload the cookbook files again by running:

knife cookbook upload -a -o cookbooks/

USAGE:

Configure roles

Run this line from your default chef folder:

knife role create cassandra

where “cassandra” is the value declared as default[:current_role]. Edit the file to look very similar to this:

{
  "name": "cassandra",
  "default_attributes": {
  },
  "json_class": "Chef::Role",
  "env_run_lists": {
  },
  "run_list": [
    "recipe[cassandra]"  # This is the line of importance
  ],
  "description": "",
  "chef_type": "role",
  "override_attributes": {
  }
}

This means that the role, that you can assign to many machines, will run this recipe upon assignment and will be bound within a group for easy clustering.

Ports Needed

The list of the ports required to be open are as follows:

Public Facing:
    Cassandra:
        9160: Cassandra client port
        7199: Cassandra JMX port, (8080 in 07x)
Internal:
    Cassandra:
        7000: Cassandra intra-node port

Starting up a cluster

An Ubuntu 10.10 cloud in Rackspace (login as root):

knife rackspace server create -r "role[cassandra]" -I 69 -f 6 -S Server01 -N Server01
knife rackspace server create -r "role[cassandra]" -I 69 -f 6 -S Server02 -N Server02
knife rackspace server create -r "role[cassandra]" -I 69 -f 6 -S Server03 -N Server03
knife rackspace server create -r "role[cassandra]" -I 69 -f 6 -S Server04 -N Server04

An Ubuntu 10.10 cloud in EC2 (login as ubuntu):

pemname=<pemFileName>  # do not include ".pem"
group=<securityGroupName>
knife ec2 server create -r "role[cassandra]" -I ami-08f40561 --flavor m1.large -S $pemname -G $group -x ubuntu -N Server01
knife ec2 server create -r "role[cassandra]" -I ami-08f40561 --flavor m1.large -S $pemname -G $group -x ubuntu -N Server02
knife ec2 server create -r "role[cassandra]" -I ami-08f40561 --flavor m1.large -S $pemname -G $group -x ubuntu -N Server03
knife ec2 server create -r "role[cassandra]" -I ami-08f40561 --flavor m1.large -S $pemname -G $group -x ubuntu -N Server04

NOTE: These AMIs only work in the US-East region. For all other regions, see cloud.ubuntu.com/ami/.

A Debian 6.0 (Squeeze) cloud in Rackspace (login as root):

knife rackspace server create -r "role[cassandra]" -I 75 -f 6 -S Server01 -N Server01
knife rackspace server create -r "role[cassandra]" -I 75 -f 6 -S Server02 -N Server02
knife rackspace server create -r "role[cassandra]" -I 75 -f 6 -S Server03 -N Server03
knife rackspace server create -r "role[cassandra]" -I 75 -f 6 -S Server04 -N Server04

A CentOS 5.5 cloud in Rackspace (login as root):

knife rackspace server create -r "role[cassandra]" -I 51 -f 6 -d centos5-gems -S Server01 -N Server01
knife rackspace server create -r "role[cassandra]" -I 51 -f 6 -d centos5-gems -S Server02 -N Server02
knife rackspace server create -r "role[cassandra]" -I 51 -f 6 -d centos5-gems -S Server03 -N Server03
knife rackspace server create -r "role[cassandra]" -I 51 -f 6 -d centos5-gems -S Server04 -N Server04

NOTE: You can run these lines more times as long as the attributes are set properly. Also, these lines should be run consecutively and never in parallel.

Keep in mind that these commands start up ONE cluster. By running these same four commands repeatedly, you will keep manipulating the same logical cluster of nodes which may serve unintended results. To create different clusters, either create new roles or remove the previous nodes from OpsCodes's Managment Console (manage.opscode.com/nodes). This is due to the fact that these scripts need to know the end size that Cassandra will grow to become to evenly parse the ring.

If you wish to add more nodes to the same cluster, however, then simply change ([:cassandra] or [:cassandra]) and [:setup].

Bootstrapping Commands

In order to run bootstrapping commands, you must be able to complete a passwordless SSH login. Typically, by copying your ~/.ssh/id_rsa.pub key into the target machine's ~/.ssh/authorized_keys file, passwordless SSH should work. Search google for more information.

For an Ubuntu/Debian Machine:

knife bootstrap -r recipe['cassandra'] --sudo -x root <publicDNS>

For an Ubuntu Machine on EC2:

knife bootstrap -r recipe['cassandra'] --sudo -x ubuntu <publicDNS>

For a CentOS 5 Machine:

knife bootstrap -r "recipe['cassandra']" --sudo -x root -d centos5-gems <publicDNS>

For a RedHat 5 Machine (Untested):

wget http://goo.gl/0k8mV -O- > ~/.chef/bootstrap/rhel5-rbel.erb
knife bootstrap --sudo -x root -d rhel5-rbel <publicDNS>
knife bootstrap -r recipe['cassandra'] --sudo -x root -d rhel5-rbel <publicDNS>

Other Useful Debugging Commands

knife node show Server01 --format json
knife cookbook metadata cassandra -o cookbooks