My last post started a discussion about various possible ways to improve the Nova Scheduler, so I thought that I’d start putting together a proof-of-concept for the solution I proposed, namely, using Cassandra as the data store and replication mechanism. But there’s a problem: not everyone has the experience to set up Cassandra, so I thought I’d show you what I did. I’m using 3 small cloud instances on Digital Ocean, but you could set this up with some local VMs, too.
We’ll create 3 512MB droplets (that’s their term for VMs). The 512MB size is the smallest they offer (hey, this is POC, not production!). I named mine ‘cass0’, ‘cass1’, and ‘cass2’. Choose a region near you, and in the “Select Image” section, click on the “Applications” tab. In the lower right side of the various options, you should see one for Docker (as of this writing, it’s “Docker 1.8.3 on 14.04”). Select that, and then below that select the “Private Networking” option; this will allow your Cassandra nodes to communicate more efficiently with each other. Add your SSH key, and go! In about a minute the instances should be ready, so click on their name to get to the instance information page. Click the word ‘Settings’ along the left side of the page, and you will see both the public and private IP addresses for that instance. Record those, as we’ll need them in a bit. I’ll refer to them as $IP_PRIVn
for the instance cass(n); e.g., $IP_PRIV2
is the private IP address for cass2.
If you are using something other than Digital Ocean, such as Virtual Box or Rackspace or anything else, and you don’t have access to an image with Docker pre-installed, you’ll have to install it using either sudo apt-get install docker-engine
or sudo yum install docker-engine
.
Once the droplets are running, ssh into them (I use cssh to make this easier), and run the usual apt-get updates to pull all the security fixes. Reboot. Reconnect to each droplet, and then grab the latest Cassandra image for Docker by running: docker pull cassandra:latest
. [EDIT – I realized that without using volumes, restarting the node would lose all the data. So here are the corrected steps.] Then you’ll create directories to use for Cassandra’s data and logs:
mkdir data mkdir log
To set up your Cassandra cluster, first ssh into the cass0 instance. Then run the following to create your container:
docker run --name node0 -v data:/var/lib/cassandra -v log:/var/log/cassandra -e CASSANDRA_BROADCAST_ADDRESS=$IP_PRIV0 -p 9042:9042 -p 7000:7000 -d cassandra:latest
If you’re not familiar with Docker, what this does is create a container with the name ‘node0’ from the image cassandra:latest. It creates two volumes (the sections beginning with the -v parameter: the first maps the local ‘data’ directory to the container’s ‘/var/lib/cassandra’ directory (where Cassandra stores its data), and the second maps the local ‘log’ directory to where Cassandra would normally write its logs. It passes in the private IP address in environment variable CASSANDRA_BROADCAST_ADDRESS
; in Cassandra, the broadcast address is what that node should use to communicate. It also opens 2 ports: 9042 (the CQL query port) and 7000 (for intra-cluster communication). Now run docker ps -a to verify that the container is up and running.
For the other two nodes, you do something similar, but you also specify the CASSANDRA_SEEDS
parameter to tell them how to join the cluster; this is the private IP address of the first node you just created. On cass1, run:
docker run --name node1 -v data:/var/lib/cassandra -v log:/var/log/cassandra -e CASSANDRA_BROADCAST_ADDRESS=$IP_PRIV1 -e CASSANDRA_SEEDS=$IP_PRIV0 -p 9042:9042 -p 7000:7000 -d cassandra:latest
Then on cass2 run:
docker run --name node2 -v data:/var/lib/cassandra
-v log:/var/log/cassandra -e CASSANDRA_BROADCAST_ADDRESS=$IP_PRIV2 -e CASSANDRA_SEEDS=$IP_PRIV0 -p 9042:9042 -p 7000:7000 -d cassandra:latest
That’s it! You have a working 3-node Cassandra cluster. Now you can start playing around with it for your tests. I’m using the Python library for Cassandra to connect to my cluster, which you can install with pip install cassandra-driver
. But working with that is the subject for another post in the future!
Great article.