Here I'm going to set up a Cassandra cluster over several virtual machines tunning Ubuntu operating system, furthermore they will be running under Docker containers.
Not going to discuss about the advantages or when is suitable to use Cassandra as there are many resources over the Web where this can be found. Just to point one of the most interesting ones from my point of view, which is the possibility to add new nodes easily to the cluster in case you are running out of space.
First step is to have at least 2 virtual machines running Ubuntu and docker as explained in my entry another entry
Docker install
Lets say you have these IP addresses 192.168.1.74 (Node A) and 192.186.1.75 (Node B)
On Node A type
docker pull cassandra
This will get the latest image version of Cassandra to your Docker.
Then to run it just
docker run -d --name=cassandra1 -e CASSANDRA_BROADCAST_ADDRESS=192.168.1.74 -p 9042:9042 -p 7000-7001:7000-7001 -p 7199:7199 -p 9160:9160 cassandra
Main things there are the broadcast address (so other nodes can see this one) and expose the ports to be able to communicate. Rest ot options are the usual ones to run an image in Docker.
Now we have our first node running.
Lets move to second virtual machine
Once we pull Cassandra we run there
docker run -d --name=cassandra2 -p 9042:9042 -p 7000-7001:7000-7001 -p 7199:7199 -p 9160:9160 -e CASSANDRA_BROADCAST_ADDRESS="192.168.1.75" -e CASSANDRA_SEEDS="192.168.1.74" cassandra
We will have our second instace of Cassandra running
To check that our cluster in correct we can run in any of the nodes this
docker exec cassandra1 nodetool status
And here we have our cluster ready!
In case you want to add a new node to the cluster is a simple as we have dont with the second one.
Obstacles:
One important thing if you are running instances in separated virtual machines is that to make sure you state the bradcast and the seeds IP addresses, in some documentation you can see people just use
the option
--net=host so instance just take the host network configuration
Also make sure you expose the ports
References:
https://hub.docker.com/_/cassandra/
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-cassandra
https://yurisubach.com/2016/03/24/cassandra-docker-test-cluster/
http://blog.ditullio.fr/2016/06/10/docker-docker-basics-cassandra/