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/*

Bash
sudo service cassandra stop
sudo rm -rf /var/lib/cassandra/data/*
  • edit /etc/cassandra/cassandra.yaml
Bash
sudo nano /etc/cassandra/cassandra.yaml
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

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

Start cassandra server(s)

Bash
sudo service cassandra start
  • Test with command
Bash
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):

Bash
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:

Bash
nodetool assassinate 192.168.122.201

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