Skip to content

Cassandra Tutorial 1: Setting up a Cassandra cluster with cassandra image and cassandra cloud project with Vagrant

jeanpaulazara edited this page Mar 7, 2017 · 1 revision

The cassandra-image project creates CentOS/Cassandra images for docker, virtualbox/vagrant and AWS/EC2. It is nice to use vagrant and/or docker for local development. At this time it is hard to develop systemd services using Docker so we use Vagrant.

The cassandra-image project packages systemd utilities

The cassandra-image project uses the Cassandra cloud project to configure Cassandra running in instances to aid in setting up the cluster.

With this in mind, let's setup Vagrant to launch a Cassandra cluster locally.

We are going to setup three nodes as follows that use our provision scripts to install Cassandra and utilities:

  • 192.168.50.4 node0
  • 192.168.50.5 node1
  • 192.168.50.5 node2

Setup network of boxes.

Vagrant.configure("2") do |config|


  # Use CentOS 7
  config.vm.box = "centos/7"

  # Setup 4 cpus and 3096 MB of memory for each instance
  config.vm.provider "virtualbox" do |vb|
       vb.memory = "3096"
       vb.cpus = 4
  end

  # Run the provision install scripts
  config.vm.provision "shell", inline: <<-SHELL
        sudo /vagrant/scripts/000-vagrant-provision.sh
  SHELL


  config.vm.define "node0" do |node0|
    ...
    # Node 0 is 192.168.50.4
    node0.vm.network "private_network", ip: "192.168.50.4"
   ...
  end

  config.vm.define "node1" do |node1|
    ...
    # Node 1 is 192.168.50.5
    node1.vm.network "private_network", ip: "192.168.50.5"
    ...
  end

  config.vm.define "node2" do |node2|
    ...
    # Node 2 is 192.168.50.6
    node2.vm.network "private_network", ip: "192.168.50.6"
  end

In this example we will use these three servers as seed nodes. Seed nodes are nodes that are first contacted by nodes that join the cluster. It is a good idea to have two or three of them as one would be a SPOF (single point of failure). In this example we will use the utility cassandra-cloud to configure the seed nodes. We will also use cassandra-cloud to tell Cassandra which address to listen on for clustering (storage network), and which address to listen on for client connections.

Using Cassandra cloud from Vagrant

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|


...

  config.vm.define "node0" do |node0|
...
    node0.vm.network "private_network", ip: "192.168.50.4"

    ### Use Cassandra cloud to configure Cassandra before launching it.
    ### Set the cluster name to test, set the client-address and the cluster-address.
    ### Also setup the Cassandra seed nodes. 
    node0.vm.provision "shell", inline: <<-SHELL
                sudo /opt/cassandra/bin/cassandra-cloud -cluster-name test \
                -client-address 192.168.50.4 \
                -cluster-address  192.168.50.4 \
                -cluster-seeds 192.168.50.4,192.168.50.5,192.168.50.6


                /opt/cassandra/bin/cassandra -R
    SHELL
  end

  config.vm.define "node1" do |node1|
...
    node1.vm.provision "shell", inline: <<-SHELL
                sudo /opt/cassandra/bin/cassandra-cloud -cluster-name test \
                -client-address 192.168.50.5 \
                -cluster-address  192.168.50.5 \
                -cluster-seeds 192.168.50.4,192.168.50.5,192.168.50.6

                /opt/cassandra/bin/cassandra -R
    SHELL
  end

  config.vm.define "node2" do |node2|
...
    node2.vm.provision "shell", inline: <<-SHELL
                sudo /opt/cassandra/bin/cassandra-cloud -cluster-name test  \
                -client-address 192.168.50.6 \
                -cluster-address  192.168.50.6 \
                -cluster-seeds 192.168.50.4,192.168.50.5,192.168.50.6


                /opt/cassandra/bin/cassandra -R
    SHELL
  end

...

end

The utility cassandra-cloud can read setting from Environment Variables so that it can work well in Mesos, Docker, Heroku, etc. It can also read properties from a config file. It can also read properties from the command line. The cassandra-image creates a cassandra-cloud config file that can be modified. The cassandra-cloud utility can setup memory, threads, number of workers, etc. for Cassandra. You can set values explicitly or they can be set by looking that the ergonomics of the server.

Ok. Let's test our cluster out.

Testing our cluster setup

$ vagrant up
$ vagrant ssh node0
[vagrant@localhost ~]$ ps -ef | grep cassandra
root     12414     1  2 19:16 ?        00:00:26 java -Xloggc:/opt/cassandra/bin/../logs/gc.log 
...

$ /opt/cassandra/bin/nodetool describecluster
Cluster Information:
        Name: test
        Snitch: org.apache.cassandra.locator.DynamicEndpointSnitch
        Partitioner: org.apache.cassandra.dht.Murmur3Partitioner
        Schema versions:
                86afa796-d883-3932-aa73-6b017cef0d19: [192.168.50.4, 192.168.50.5, 192.168.50.6]

We can see that we have a cluster of three servers.

More to come.

Check back with us at the Cloudurable blog to find out more about cassandra-image and cassandra-cloud.

About us

Cloudurable provides AMIs, cloudformation templates and monitoring tools to support Cassandra in production running in EC2. We also teach advanced Cassandra courses which teaches how one could develop, support and deploy Cassandra to production in AWS EC2.

About us

Cloudurable™: streamline DevOps for Cassandra running on AWS provides AMIs, CloudWatch Monitoring, CloudFormation templates and monitoring tools to support Cassandra in production running in EC2. We also teach advanced Cassandra courses which teaches how one could develop, support and deploy Cassandra to production in AWS EC2 for Developers and DevOps.

More info

Please take some time to read the Advantage of using Cloudurable™.

Cloudurable provides:

AWS Cassandra Deployment Guides

Cassandra Cluster/DevOps/DBA tutorial

Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting

Clone this wiki locally