How To

Install Apache Cassandra on Ubuntu 18.04: NoSQL Setup Guide

Apache Cassandra is a free, open-source NoSQL database designed for high availability and linear scalability with no single point of failure. It achieves this by distributing data across multiple nodes with no master node, so any node can handle any request. If one node goes down, other nodes continue serving traffic without interruption.

Cassandra is trusted at scale by organizations like Apple, Netflix, and eBay. It is a solid choice when you need a database that can grow horizontally and stay available under heavy load.

This guide shows you how to install Cassandra on Ubuntu 18.04, verify the installation, connect with the CQL shell, and rename the cluster. The same steps work on Ubuntu 16.04, Kubuntu, and Linux Mint.

<strong>Prerequisite:</strong>&nbsp;You need sudo access.

Install Cassandra on Ubuntu: Java, Repository, and Package Setup

Cassandra 3.11 requires OpenJDK 8. Install it first:

bashsudo apt updatesudo apt install openjdk-8-jdk

Verify with java -version. The output should show openjdk version "1.8.0_191" or similar.

Add the Cassandra repository. Install the HTTPS transport package so apt can reach the repository over HTTPS:

bashsudo apt install apt-transport-https

Import the Apache Cassandra GPG key:

bashwget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

The command prints OK to confirm the key was imported successfully. Add the Cassandra 3.11 repository to your apt sources:

bashsudo sh -c 'echo "deb https://archive.apache.org/dist/cassandra/debian/ 311x main" &gt; /etc/apt/sources.list.d/cassandra.list'

Update the package list and install Cassandra:

bashsudo apt updatesudo apt install cassandra

The Cassandra service starts automatically after installation.

Verify the Installation and Connect with cqlsh

Check that Cassandra is running with the nodetool utility:

bashnodetool status

The output lists the cluster nodes and their status. A healthy node shows UN in the first column. The U means the node is Up and the N means its state is Normal. If you see 100.0% in the Owns column, the single node owns the full data range.

Key file locations. Cassandra stores its data in /var/lib/cassandra. Configuration files are in /etc/cassandra, and Java startup options live in /etc/default/cassandra. By default, Cassandra listens on localhost only, which is fine if your application runs on the same server.

Connect with cqlsh. Cassandra ships with cqlsh, a command-line interface for the Cassandra Query Language:

bashcqlsh

A successful connection shows the Cassandra version and the cluster name (Test Cluster by default), followed by the cqlsh> prompt. Type exit to leave the shell.

Configure Cassandra and Rename the Cluster

The default cluster name “Test Cluster” is fine for development but should be changed before using Cassandra in production. Renaming requires three steps.

Step 1. Open cqlsh and update the cluster name in the system table:

sqlUPDATE system.local SET cluster_name = 'YourClusterName' WHERE KEY = 'local';

Type exit to close the shell.

Step 2. Update the cluster name in the Cassandra configuration file /etc/cassandra/cassandra.yaml:

yamlcluster_name: 'YourClusterName'

Replace YourClusterName with the same name you used in Step 1. The names must match exactly.

Step 3. Clear the system cache so Cassandra reads the new name cleanly on restart:

bashnodetool flush system

Then restart the service:

bashsudo systemctl restart cassandra

Run nodetool status again to confirm the cluster is still showing UN after the restart.

Apache Cassandra is now installed and configured on your Ubuntu 18.04 server. Visit the Apache Cassandra documentation to learn how to create keyspaces, define tables, and query data with CQL. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

groupdel Command in Linux: Remove a Group and Audit Files

The groupdel command in Linux removes a group from the system. It deletes the group's entry from /etc/group and /etc/gshadow,…

1 day ago

wc Command in Linux: Count Lines, Words, Characters, and Bytes

The wc command in Linux counts lines, words, characters, and bytes in files or standard input. It…

1 day ago

top Command in Linux: Monitor Processes and Resource Usage

The top command in Linux provides a real-time view of running processes and system resource usage. From…

1 day ago

usermod Command in Linux: Modify User Accounts and Groups

The usermod command in Linux modifies existing user account attributes. You can use it to manage group…

1 day ago

sort Command in Linux: Sort Text, Numbers, Columns, and More

The sort command in Linux reads lines from files or standard input and writes them to standard…

2 days ago

wall Command in Linux: Broadcast Messages to Logged-In Users

The wall command in Linux sends a message to the terminals of all currently logged-in users. The…

2 days ago