Running Cassandra Multinode Cluster
[2 Nodes & 1 Datacenter]
Reference links
1. Install Cassandra on all Nodes as follows:
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
sudo apt-get update
sudo apt-get install cassandra -y
- You can start Cassandra with
sudo service cassandra start Stop it with
sudo service cassandra stopNormally the service will start automatically. For this reason be sure to stop it if you need to make any configuration changes.
Verify that Cassandra is running by invoking
nodetool statusfrom the command line.nodetool status Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns Host ID Rack UN 127.0.0.1 172.18 KiB 256 ? 60bc1910-eb04-4c7f-bc44-4de3643ce4f4 rack1 Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaninglessThe default location of configuration files is
/etc/cassandra.- The default location of log and data directories is
/var/log/cassandra/and/var/lib/cassandra. - Start-up options (heap size, etc) can be configured in
/etc/default/cassandra.
1. Stop Cassandra-daemon-
sudo service cassandra stop
2. Delete the default dataset:
sudo rm -rf /var/lib/cassandra/data/system/*
3. Edit the cassandra.yaml file as follows-
sudo vim /etc/cassandra/cassandra.yaml
4. The contents should look like the below:
cluster_name: 'CassandraDOCluster'
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "your_server_ip,your_server_ip_2,...your_server_ip_n"
listen_address: your_server_ip
rpc_address: your_server_ip
endpoint_snitch: GossipingPropertyFileSnitch
- at the end of the cassandra.yaml file add the following :
auto_bootstrap: false
- edit the file below
sudo vim /etc/cassandra/cassandra-env.sh- search for hostname and place your IP address in it
5. Restart the cassandra-daemon
sudo service cassandra start
sudo service cassandra restart
6. Check status of the cluster
sudo nodetool status
sudo nodetool status <keyspace-name> (if the keyspaces don't have the same replication factor)
Output
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.31.86.204 456.99 MiB 256 23.6% c03141fc-ae28-4d4c-b658-cb949e5ccc57 rack1
UN 172.31.90.24 107.44 KiB 256 27.5% 8c143d7a-69d2-48c1-8a23-dcda6ce9dfa5 rack1
8. Modify the firewall rules
sudo vim /etc/iptables/rules.v4
9. New firewall rule should be as follows
-A INPUT -p tcp -s your_other_server_ip -m multiport --dports 7000,9042 -m state --state NEW,ESTABLISHED -j ACCEPT
10. Restart ip-tables
sudo service iptables-persistent restart
11. Check cluster status
sudo nodetool status
12. use cqlsh as follows
cqlsh your_server_ip 9042