Skip to content

Setup HA Cassandra Cluster

Stolen from here

Install Cassandra

Configure cassandra node

Default config file is placed in /etc/cassandra/cassandra.yaml

Once cassandra is installed stop it and delete /var/lib/cassandra/data/*

sudo service cassandra stop
sudo rm -rf /var/lib/cassandra/data/*
  • edit /etc/cassandra/cassandra.yaml
sudo nano /etc/cassandra/cassandra.yaml
cluster_name: 'Test Cluster'

seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "your-server-ip,your-server-ip-2"

listen_address: your-server-ip

rpc_address: your-server-ip

auto_bootstrap: false

Added the line in the end:

auto_bootstrap: false

sudo sed -i 's/endpoint_snitch: SimpleSnitch/endpoint_snitch: GossipingPropertyFileSnitch/g' /etc/cassandra/cassandra.yaml
sudo sed -i 's/dc=dc1/dc=datacenter1/g' /etc/cassandra/cassandra-rackdc.properties

Start cassandra server(s)

sudo service cassandra start
  • Test with command
nodetools status

Creating keyspaces

In this case we have two cassandra nodes so create keyspaces with 2 replicas (how many nodes that many replicas so the ownership would be 100% on all nodes):

CREATE KEYSPACE IF NOT EXISTS somename WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 2}  AND durable_writes = true;

If one of the nodes "dies"

remove the faulty one from working one:

nodetool assassinate 192.168.122.201

Bring back new node with the same IP (of the dead one) and everything will work.