Setting up Cassandra Cluster
To avoid a single point of failure, Cassandra server can be run on each server machine (AMS and AGS), thereby Cassandra servers acting as a cluster.
To set up the Cassandra cluster, perform the following actions:
- Open Cassandra.yaml file and specify the below:
cluster_name: Give a name for the cluster.
All nodes must use the same cluster name.
seeds: Mention the IP address of each node in the cluster, separated by commas.
Example
192.168.3.32,192.168.4.25,192.168.4.55
listen_address: This is the IP address that other nodes in the cluster will use to connect. By default, the value will be "localhost" which canneeds to be changed to the IP address of the node.
Example
listen_address: 192.168.1.74
rpc_address: This is the IP address for remote procedure calls. The default value is "localhost". If the server's hostname is properly configured, leave this as is. It can be replaced with the server's IP address or the loopback address (127.0.0.1).
Example
rpc_address: 192.168.1.74
endpoint_snitch: Set the value to "GossipingPropertyFileSnitch".
endpoint_snitch: GossipingPropertyFileSnitch
Open the cassandra-rackdc.properties file and specify the Data Center and Rack names:
Example
dc=dc1
rack=rack1Open the cassandra-topology.properties file.
Under the Cassandra Node IP address, specify the IP address of the node to the respective Rack and Data center.Example
192.168.1.73=DC1:RAC1
192.168.1.74=DC1:RAC1Start the Cassandra server on every node in the cluster using the command below:
CODEsudo service cassandra start
Set Replication Factor using the command below:
If Cassandra servers are running on the same Data Center
CODEcqlsh> ALTER KEYSPACE api WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 2 };
If Cassandra servers are running on a different Data Center
CODEcqlsh> ALTER KEYSPACE api WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};
The replication factor should be set on each node and must be equal to the number of Cassandra servers running.
After Replication factor is set, run the nodetool repair command below in every node in the cluster:
CODEcqlsh> nodetool repair
By this, the cluster setup must be ready. To check the status of a particular node, run the nodetool status command below:
CODEcqlsh> nodetool status api
If Cassandra server is running, stop the server and clear the data:
Stop Cassandra:
CODEsudo service cassandra stop
Clear the data:
CODEsudo rm -rf CASSANDRA_LOCATION/data/system/*