Monday, November 5, 2018

Cassandra Cluster With 3 Nodes on ubuntu 16.04


It is assumed that the following is already in place:
  • Cassandra 3.2 is installed on 3 nodes.
for downloading cassandra ,goto  http://cassandra.apache.org/download/
  • Each node has open communication between the other nodes. Take a look here if you use a firewall between nodes.
  • The IP addresses of each node are known.
  • No data is stored on the 3 Cassandra instances.
Example for node 1:

Goto Cassandra home directory .
Goto conf ->cassandra.yaml and edit the yaml file as mentioned below .

cluster_name: 'Test Cluster'
num_tokens: 256
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
        - seeds: 1.2.3.4, 5.6.7.8, 9.10.11.12
listen_address: 1.2.3.4
rpc_address: 1.2.3.4
endpoint_snitch: GossipingPropertyFileSnitch


For node 2:

cluster_name: 'Test Cluster'
num_tokens: 256
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
        - seeds: 1.2.3.4, 5.6.7.8, 9.10.11.12
listen_address: 5.6.7.8
rpc_address: 5.6.7.8
endpoint_snitch: GossipingPropertyFileSnitch



for node 3:

cluster_name: 'Test Cluster'
num_tokens: 256
seed_provider:
    - class_name: org.apache.cassandra.locator.SimpleSeedProvider
        - seeds: 1.2.3.4, 5.6.7.8, 9.10.11.12
listen_address: 9.10.11.12
rpc_address: 9.10.11.12
endpoint_snitch: GossipingPropertyFileSnitch

imp-:make sure that ,all the 3 nodes having same clustername and endpoint snitch .
Edit the cassandra-rackdc.properties file on each node and set the dc and rackattributes. For this example we’ll assume everything is in the same dc, dc1 however two nodes will be on rack1 and one node will be on rack2. Names are irrelevant, just come up with a naming standard that helps you understand where the Cassandra instance actually is. Everything here is case sensitive so be sure you’re consistent.
Goto  cassandra-rackdc.properties
 For node 1 and node 2:
dc=uk_dc
rack=rack1

Example for node 3:
dc=uk_dc
rack=rack2
Finally, remove the config file cassandra-topology.properties from the  Cassandra HOME dir as that’s not used with our configuration.

 rm cassandra-topology.properties 

Starting your Cassandra cluster

Goto bin > ./cassandra in each machine .

You can do curd operation through  cql .

bin >./cqlsh 1.2.3.4 9042

and for check status of your cluster you can type

 bin >./nodetool status

You can see all the nodes are up and running .Status is showing UN(up and Normal)
These are the ports which occupied by cassandra ,

·         7199 - JMX (was 8080 pre Cassandra 0.8.xx)
·         7000 - Internode communication (not used if TLS enabled)
·         7001 - TLS Internode communication (used if TLS enabled)
·         9160 - Thrift client API
·         9042 - CQL native transport port

Production issue fixed:-
These are some important commands :-
If 9042 port is not running then  , ./bin/nodetool enablebinary

To remove Cassandra dead node , ./bin/nodetool assassinate <dead node ip>
 to fix Cassandra node up
   ./bin/nodetool scrub 

./bin/nodetool drain (stop accepting request)
./bin/nodetool stopdaemon (graceful shutdown)
Then start Cassandra ,./bin/Cassandra

If java.lang.RuntimeException: A node with address /1.2.3.4 already exists, cancelling join. Use cassandra.replace_address if you want to replace this node.
Then goto another node and delete the dead node .

nodetool removenode <node_id>
nodetool snapshot <mykeyspace> -t <SnapshotDirectoryName> (back up)