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

Install Rocket.Chat on Ubuntu 18.04 with Nginx and Let’s Encrypt

Rocket.Chat is a free, open-source team communication platform built with the Meteor framework. It is a…

14 minutes ago

Install MySQL on Ubuntu 18.04: Setup, Security, and Root Access

MySQL is the most popular open-source relational database management system. It is fast, reliable, and scales…

17 minutes ago

Install Apache on Ubuntu 18.04: Web Server Setup and Config

Apache is the most widely used web server in the world. It is free, open-source, and…

22 minutes ago

Install NetBeans IDE on Ubuntu 18.04 with Snap and OpenJDK 8

NetBeans is a free, open-source, cross-platform IDE developed by the Apache Software Foundation. It was one…

27 minutes ago

Install Pip on Ubuntu 18.04: Python 3 and Python 2 Setup Guide

Pip is the official package manager for Python and the standard way to install libraries from…

5 days ago

Install R on Ubuntu 18.04 from CRAN: Statistical Computing Setup

R is an open-source programming language and environment built for statistical computing and data visualization. It…

5 days ago