Multi node Cassandra setup: On two ubuntu 12.04 vm's
Password less communication b/w nodes
Vm 1: IP : 192.168.56.138
Vm 2: IP: 192.168.56.139
Step 1:
On both systems:
1.1 : sudo apt-get update
1.2 : sudo apt-get install openssh-server ( install ssh)
Edit the hosts & hostname in both nodes
Node 1 & Node2
[user@ubuntu] sudo gedit /etc/hosts
192.168.56.138 cc1
192.168.56.138 cc2
Node 1
[user@ubuntu] sudo gedit /etc/hostname
cc1
Node 2
[user@ubuntu] sudo gedit /etc/hostname
cc2
Password less communication b/w nodes
node 1:
==> [user@cc1~]$ ssh-keygen -t rsa
==> move to ssh
[user@cc1~]$ cd .ssh
[user@cc1 .ssh]$ ssh-copy-id user@cc1
[user@cc1 .ssh]$ ssh-copy-id user@cc2
node2 :
[user@cc2~]$ ssh-keygen -t rsa
==> move to ssh
[user@cc2~]$ cd .ssh
[user@cc2 .ssh]$ ssh-copy-id user@cc1
[user@cc2 .ssh]$ ssh-copy-id user@cc2
Test communication ( without password)
[user@cc1~]ssh cc2
[user@cc2~]ssh cc1
Step 2: Install Java
$ sudo apt-get install openjdk-7-jdk
Edit bash file
[user@cc1~] sudo gedit .bashrc
#Add at end of file
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/lib/jvm/java-7-openjdk-i386/
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
export CASSANDRA_HOME=/home/user/cassandra
export PATH=$PATH:$CASSANDRA_HOME/bin
DOWNLOAD CASSANDRA FROM APACHE
[user@cc1~]Wget http://download.nextag.com/apache/cassandra/2.0.7/apache-cassandra-2.0.7-bin.tar.gz
• Unzip the file.
• Rename as Cassandra
Make sure that the folders Cassandra accesses, such as the log folder, exists and that Cassandra has the right to write on it:
sudo mkdir /var/lib/cassandra
sudo mkdir /var/log/cassandra
sudo chown -R user:user /var/lib/cassandra
sudo chown -R user:user /var/log/Cassandra
Now you'll need to edit your configuration file for each node. To do so, open the nano text editor by running:
sudo gedit /cassandra/conf/cassandra.yaml
Node 1: 198.168.56.138
In this file we need to find this 5 key word
cluster_name: 'Test Cluster'
Note: It can be any name based on your requirement , but we need to keep same cluaser_name in all the nodes.
num_token: 256
note: 256 default
seed_provider:
- seeds: "198.168.56.138"
listen_address: 198.168.56.138
rpc_address: 0.0.0.0
Node 2: 198.168.56.139
cluster_name: 'Test Cluster'
num_token: 256
seed_provider:
- seeds: "198.168.56.139"
listen_address: 198.168.56.139
rpc_address: 0.0.0.0
Then run on each nodes:
user@cc1:~/cassandra/bin$ ./cassandra -f
user@cc2:~/cassandra/bin$ ./cassandra –f
To check status:
user@cc1:~/cassandra/bin$ ./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Owns (effective) Host ID Token Rack
UN 192.168.56.139 104.35 KB 100.0% 60d7b5dc-1fe9-4dbd-95ce-4dda909 541eb -8865002000542532430 rack1
UN 192.168.56.138 122.59 KB 100.0% d7da38ee-9966-4298-9287-cfc01c6 38b36 -9204566404324983001 rack1
user@cc2:~/cassandra/bin$ ./nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Owns (effective) Host ID Token Rack
UN 192.168.56.139 104.35 KB 100.0% 60d7b5dc-1fe9-4dbd-95ce-4dda909 541eb -8865002000542532430 rack1
UN 192.168.56.138 122.59 KB 100.0% d7da38ee-9966-4298-9287-cfc01c6
To test:
user@cc1:~/cassandra/bin$ ./cassandra-cli
[default@unknown]
Create Keyspace…………
[default@unknown] create keyspace webapp1;
Use the Keyspace………………….
[default@unknown] use webapp1;
[default@webapp1]
Create column family …………………..
create column family users with key_validation_class = 'UTF8Type' and comparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and column_metadata = [{ column_name: username,validation_class: UTF8Type, index_type: KEYS}];
set users[username][emailid] = '<<user email id>> ';
Here we run the status command, it will share the data in all nodes..
To stop the Cassandra process, find the Cassandra Java process ID (PID), and then kill the process using its PID number:
$ ps auwx | grep cassandra
$ sudo kill <pid>
Acknowledgements
Thank you Rakesh Budagam and David Letchumanan for this post.
No comments:
Post a Comment