Saturday, 17 May 2014

Cassandra - multi node configuration and clustering details

Process to configure Cassandra cluster:

·         Step 1. Locate Cassantdra.yaml and search for ‘seed’. Change the IP address to the IP Address of any one node whom you want to designate as ‘seed’ (more on seed later).
·         Step 2. Change listen_address to local IP (should not be 127.0.0.1)
·         Step 3. Change rpc_address to local IP (should not be 127.0.0.1) Repeat the configuration changes for all the nodes .

List of fields needs changes in ~/cassandra/conf/cassandra.yaml


o    cluster_name: 'Name'
o    initial_token: Token
o    seed_provider:
o    seeds:  "Seed IP"
o    listen_address: Droplet's IP
o    rpc_address: 0.0.0.0
o    endpoint_snitch: RackInferringSnitch

Configuration Cassandra Box 1

By default, Cassandra is configured as a single-node installation. First, stop Cassandra:
sudo /etc/init.d/cassandra stop
Follow the next steps to create a multinode configuration for Box 1:
sudo nano /etc/cassandra/cassandra.yaml

o    change the name of cluster. The current name is ‘Test Cluster’. Search for the string cluster_name and give a name to your cluster.
o    Next, search for the string  listen_address and change it from localhost to the ip address of this machine.
o    Search for the string rpc_address and change it from localhost to 0.0.0.0
Delete the cache and logfiles because we changed the name of the cluster.
sudo rm -rf /var/lib/cassandra/*
Finally, restart Cassandra on Box 1:
sudo /etc/init.d/cassandra start

Configuration Cassandra Box 2

Start with repeating the same steps for Box 1. Then you need to take two more steps when you are editing cassandra.yaml:
  1. Search for the string auto_bootstrap and change the value from false to true.
  2. Search for the string seeds and replace localhost with the ip address of Box 1.
Finally,  restart Cassandra on Box 2:
sudo /etc/init.d/cassandra start
Inspect the logfile of Cassandra on Box 1 and you should see that Box 2 has arrived. You can also issue this command:
nodetool -host 127.0.0.1 ring

List of Useful commands:
Starting Cassandra service:

o    cd /etc/cassandra/bin; run  cassandra & ( for Apache cassandra)
o    cd /etc/dse/cassandra/bin; run cassandra & ( for DATAstax cassandra)
o    sudo service dse start / stop ( for DATASTAX cassandra)
o    Cassandra_cli commnds
o    Cassandra_cli –h <ip>
o    Use keyspace
o    CQL commands.

Checking if Cassandra is up and running: telnet  <ip> 9160 (should not give connection refused or time out).

How to test Cluster:

./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down       
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Owns (effective) Host ID Token Rack
UN 172.22.67.101 42.78 KB 25.4% 6fb0a0cb-b804-4f57-8178-d2c9f36bfac4 -5882736283116946676 rack1
DN 172.22.67.102 60.04 KB 31.8% 9e675cf5-f428-4770-8e73-38dc4338bf80 7869867229365366303 rack1
UN 172.22.67.103 62.13 KB 42.8% 8e87c60c-ef07-4ed6-83d0-0dc79f5094e4

Sample  configuration file for configuration for 3 node cluster :
Initial token can be generated using the following link https://dl.dropboxusercontent.com/u/30184176/digitalocean/tokenCalc/index.html

Server 1:
Node 0
cluster_name: 'MyDigitalOceanCluster'
initial_token: 0
seed_provider:
    - seeds:  "198.211.xxx.0"
listen_address: 198.211.xxx.0
rpc_address: 0.0.0.0
endpoint_snitch: RackInferringSnitch
 
Server 2:
 
cluster_name: 'MyDigitalOceanCluster'
initial_token: 3074457345618258602
seed_provider:
    - seeds:  "198.211.xxx.0"
listen_address: 192.241.xxx.0
rpc_address: 0.0.0.0
endpoint_snitch: RackInferringSnitch
 
 
server 3:
 
cluster_name: 'MyDigitalOceanCluster'
initial_token: 6148914691236517205
seed_provider:
    - seeds:  "198.211.xxx.0"
listen_address: 37.139.xxx.0
rpc_address: 0.0.0.0

endpoint_snitch: RackInferringSnitch

No comments:

Post a Comment

Angular Tutorial (Update to Angular 7)

As Angular 7 has just been released a few days ago. This tutorial is updated to show you how to create an Angular 7 project and the new fe...