Friday, September 29, 2023

Cassandra: Adding Cassandra node

A quick guide on how to add a Cassandra node on Ubuntu OS.


Specification
VMware Fusion Professional 13.0.2

/var/log/cassandra$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy

cqlsh cassandra01
Connected to Test Cluster at cassandra01:9042
[cqlsh 6.1.0 | Cassandra 4.1.3 | CQL spec 3.4.6 | Native protocol v5]



Adding Cassandra node
Requirement
1 - a cluster name:  Test Cluster (default and making sure all nodes have the same name)
2 - a static IP for both nodes: 192.168.1.32, 192.168.1.35
3 - delete the cloned nodes' data

Steps

Step 1: Clone the primary node to other nodes

Step 2: Set both nodes IP address to static IP. In my lab, I simply set them to 2 fictitious IPs - 192.168.1.32, 192.168.1.35

Test them both can be ping and ssh.


Step 3: change hostname
sudo vim /etc/hostname
cassandra1


Step 4: Add IP and hostname to /etc/hosts

192.168.1.32 cassandra01
192.168.1.35 cassandra02


Step 5: Reboot the VM

Perform the same for all other nodes and reboot

Step 6: Change the listen_address and rpc_address properties in the cassandra.yaml for each node.
set the IP address as the corresponding node had. If node1 have 192.168.1.1, the listener_address and rpc_address should also have 192.168.1.1 and if node2 has 192.168.1.2 then the listener and rpc should also have 192.1.168.2



Step7: Need at least one seed node for others to join the cluster

Step 8: Restart Cassandra

sudo service cassandra restart


Step 9:  Edit the Cassandra seed section within the cassandra.yaml file and replace a primary IP address on it or all nodes. Perform the same for node2 with the primary IP address.


Step 10: Delete node2 data directory and restart

cassandra@cassandra02:/var/log/cassandra$ ls -las /var/lib/cassandra/
total 24
4 drwxr-xr-x 6 cassandra cassandra 4096 Aug 15 16:39 .
4 drwxr-xr-x 42 root root 4096 Aug 15 16:39 ..
4 drwxr-xr-x 2 cassandra cassandra 4096 Sep 29 16:36 commitlog
4 drwxr-xr-x 8 cassandra cassandra 4096 Aug 17 21:18 data
4 drwxr-xr-x 2 cassandra cassandra 4096 Aug 15 16:39 hints
4 drwxr-xr-x 2 cassandra cassandra 4096 Sep 28 16:31 saved_caches


cassandra@cassandra02:/var/log/cassandra$ sudo service cassandra stop 


cassandra@cassandra02:/var/log/cassandra$ sudo rm -rf /var/lib/cassandra/*


cassandra@cassandra02:/var/log/cassandra$ ps auwx | grep cassandra
root 2048 0.0 0.1 18368 9636 ? Ss 16:02 0:00 sshd: cassandra [priv]
cassand+ 2114 0.0 0.0 18500 6460 ? S 16:02 0:00 sshd: cassandra@pts/0
cassand+ 4616 0.0 0.0 6024 2008 pts/0 R+ 16:47 0:00 grep --color=auto cassandra


cassandra@cassandra02:/var/log/cassandra$ sudo service cassandra start


cassandra@cassandra02:/var/log/cassandra$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack 
UN 192.168.1.32 265 KiB 16 100.0% 37562f38-b9da-4e77-b44d-6572248ec7d1 rack1

cassandra@cassandra02:/var/log/cassandra$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack 
UN 192.168.1.35 79.81 KiB 16 51.2% d9d37072-817a-4095-87da-c4fc7a4686f8 rack1
UN 192.168.1.32 265 KiB 16 48.8% 37562f38-b9da-4e77-b44d-6572248ec7d1 rack1




In summary, it adds the listen_address, rpc_address, seeds, deletes the added node's directory, and starts node2 Cassandra.


With the help of the following guide.

No comments:

Post a Comment