
A multi-node Apache Cassandra database cluster contains two or more database nodes (servers) in different cloud locations. This setup prevents Single-Point of Failure (SPOF) in case some nodes in the cluster fail. For instance, consider a scenario where you're running a cluster with three nodes. If one node fails due to network, power, or software problems, the rest of the nodes in the cluster can continue accepting read and write requests to the connected clients.
In a Cassandra multi-node setup, there is no leader election, and all participating nodes equally perform similar functions. Depending on your target level of data consistency, you must declare a replication strategy when creating a keyspace in the cluster. The strategy determines how Cassandra stores replicas across participating nodes and the total number of replicas per keyspace.
In this guide, deploy a multi-node Apache Cassandra database cluster on a Ubuntu 22.04 server, and test communication between the cluster nodes by adding sample data to a shared keyspace.
Before you begin, in a single Vultr location:
Deploy three Ubuntu 22.04 servers with at least 16 GB RAM for production.
Add the servers to the same Vultr Virtual Private Cloud (VPC).
A VPC is a logical VLAN connection between Vultr servers that allows Apache Cassandra nodes to communicate in real time. Enable VPC peering to configure servers deployed in a different location to sync with the Cassandra cluster.
In this article, the following example IP Addresses represent the respective Server VPC Addresses.
192.0.2.3192.0.2.4192.0.2.5To view your server VPC address, run the following command in your SSH session.
On each server:
Use SSH to access the server in a separate terminal session.
Switch to the sudo user account.
In this section, configure the hostname of every server for fast identification in the Apache Cassandra cluster. For this article, Set each of the servers with the hostnames below:
node-1node-1node-1On each of the servers, set a new hostname identity as described in the steps below:
Using a text editor such as Nano, edit the /etc/hostname file.
Replace the default hostname (localhost) with the respective cluster-ID.
Save and close the file.
Open the /etc/hosts file.
Add the following line at the end of the file.
Save and close the file.
Reboot the server to apply changes.
To communicate and send keep-alive packets to all nodes in the cluster, set up firewall rules to accept Cassandra requests from the respective VPC server addresses. By default, Uncomplicated Firewall (UFW) is active on Vultr Ubuntu servers, set up UFW rules on each server as described below.
Server 1:
Allow connections to port 7000 and 9042 from Server 2 to Server 1.
Allow connections from Server 3 to Server 1.
Reload firewall rules to save changes.
Server 2:
Allow connections to port 7000 and 9042 from Server 1 to Server 2.
Allow connections from Server 3 to Server 2.
Reload firewall rules.
Server 3:
Allow connections to port 7000 and 9042 from Server 1 to Server 3.
Allow connections from Server 2 to Server 3.
Reload firewall rules to apply changes.
In this section, set up the Apache Cassandra cluster information on each server to allow all nodes to communicate together. To set up the cluster information, make changes to the main configuration file /etc/cassandra/cassandra.yaml on each server as described below.
Stop the Apache Cassandra service.
Clear existing Cassandra data directories to refresh the node state.
Open the /etc/cassandra/cassandra.yaml file.
The Cassandra configuration file contains many directives, when using the Nano text editor, press Ctrl + W to search a directive by string.
Find cluster_name:, and change the value from Test Cluster to AppDbCluster.
The above directive sets the cluster name to AppDbCluster. Verify that all servers in the cluster share the same name for a successful connection.
Find the seed_provider: directive, and enter the IP Addresses of other nodes in the format <ip>,<ip> as below.
The above directives set the addresses Apache Cassandra sends seed nodes to find cluster information. Seed nodes are keep-alive packets known as gossips in Cassandra. To enable high availability in the cluster, you must set at least two seed addresses.
Find the listen_address: directive, and set the value to your node's VPC Address.
The above directive sets the IP address used to communicate with other nodes in the cluster. Cassandra nodes use the inter-nodal gossip protocol that implements a peer-to-peer architecture to exchange state information in the cluster.
Find rpc_address:, and set it to your node's VPC address.
The above directive sets the client connection address. No connections are from other interfaces or addresses.
At the end of the file, add the auto_bootstrap: directive, and set it to false.
The above directive allows a node to join the Cassandra cluster without streaming data. When enabling it on existing clusters, set the value to true.
Save and close the Cassandra configuration file.
Start the Cassandra database server.
The Cassandra cluster may take up to 30 seconds to start.
Clear the Apache Cassandra data directories.
Verify that the Cassandra server is running.
Output:
nodetool is a utility used by the Apache Cassandra database server to manage view cluster information. On each of the server, use the tool to verify the cluster status.
Verify the database cluster status.
The above command displays the IP addresses, state, load, and node IDs in the cluster as below.
On node-3, run the following command to view the IP list of remote seed nodes.
Run the following command on node-3 to get the IP list of the remote seed nodes.
Output:
As displayed in the above output, the active node's IP address isn't listed if the node is part of the seeds.
On node-1, Log in to the Cassandra cluster.
Output:
To redistribute the default system_auth keyspace in the cluster, change the replication_factor to 3.
The above command keeps three copies of the system_auth keyspace on each node. When set to 1, the cluster shuts down when a single replica of the keyspace isn't available.
You should get a warning that requires a full cluster repair to redistribute data across all cluster nodes.
Exit the cluster.
Run the following cluster repair command to load the new replication strategy.
Output:
On node-1, connect to the Cassandra cluster:
Create a sample keyspace with a replication_factor of 3.
Switch to the new keyspace.
Create a sample customers table with three columns.
Insert data to the customers table.
On node-3, connect to the Cassandra cluster.
Switch to the new my_keyspace keyspace.
View the customers table data.
Output:
As displayed in the above output, the data entered on node-1 replicates to node-2 and node-3 in real-time.
Add a new row to the customers table.
Exit the cluster.
On node-1 run a SELECT statement and verify if the cluster replicates the last record you on node-3.
Output:
Exit the cluster.
In this section, use the QUORUM consistency level to set a level participating nodes must achieve before the Cassandra cluster accepts read or write operations. By using enforcing a consistency level policy, you can restrict data availability and accuracy when nodes fail. The cluster uses the following formula to calculate the available quorum level.
When expanded, the above formula evaluates to 2:
As listed in the above evaluation, any query you perform on the sample my_keyspace keyspace requires 2 healthy nodes to respond. This is because the cluster consists of 3 nodes, and tolerates only 1 replica down. If you have 10 nodes, a sample key space with a replication_factor of 10 tolerates 4 nodes down because (10 / 2) + 1 rounded down to the nearest integer is 6.
To test the above consistency level logic, follow the steps below:
On node-1, stop the Apache Cassandra cluster.
The above command sets the total available nodes to two with node-2 and node-3 actively running.
On node-2, run the Cassandra nodetool to verify that one node is down and two nodes are running.
Output:
The above output confirms that node-1 (192.0.2.3) is down with the DN status, and the rest of the nodes are running.
On node-2, log in to the Cassandra Cluster.
Set the consistency level to QUORUM.
Output:
Switch to the my_keyspace keyspace.
View the customers table data.
Output:
The above output displays table data because the majority of nodes 2 out of 3 respond and there is a quorum.
Exit the cluster.
On node-3, stop the Apache Cassandra cluster.
On node-2, access the cluster, and try viewing the customers table data.
Output:
As displayed in the output, there is no quorum because the majority of nodes are down. This is because the cluster requires a majority of healthy nodes (2) as compared to (1).
If you encounter any error while setting up a multi-node Apache cluster, follow the troubleshooting steps below to fix any cluster issues. To view detailed errors, view the /var/log/cassandra/system.log file.
In case of server restarts, a node may fail to respond. To enable a dead node fix, edit the cassandra-env.sh as below.
Add the following line at the end of the file. Replace 192.0.2.3 with your actual node address.
Clear the cluster data directories.
Verify the cluster status to verify that your node is up and running.
nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused (Connection refused)'.Verify that the Apache Cassandra database server is running.
Open the /etc/cassandra/cassandra.yaml, and verify that the rpc_address: directive points to your node address to accept client connections.
Connection error: ('Unable to connect to any servers', {'192.0.2.3:9042': ConnectionRefusedError(111, "Tried connecting to [('192.0.2.3', 9042)]. Last error: Connection refused")})Verify the cluster status.
Verify that Cassandra is running.
Verify that the listen_address: directive points to your node address in your configuration file.
In this guide, you have deployed a multi-node Apache Cassandra cluster on a Ubuntu 22.04 server. Creating a multi-node Apache Cassandra cluster ensures high availability and improves the reliability of applications that use the cluster. For more information, visit the Apache Cassandra documentation.
0 Comments
Be the first to comment and share your perspective with the community.