How to Install Apache Cassandra on Ubuntu 24.04


Apache Cassandra stands out as a distributed database engineered for stellar scalability and impressive performance, capable of managing vast datasets across numerous standard servers. It ensures continuous availability and is architected to prevent any single point of failure, thus safeguarding against data loss and service interruptions.

Installing Apache Cassandra on an Ubuntu server is a strategic move for managing large datasets in a distributed environment. Its masterless architecture allows for robust data replication and high availability.

This article will explain the steps to install Apache Cassandra on Ubuntu 24.04.

How to Install Apache Cassandra on Ubuntu 24.04?

As an open-source NoSQL database, Cassandra offers high scalability and reliability, making it an excellent choice for applications that require fault tolerance and seamless scalability across multiple servers.

The installation process can be approached in several ways, but the most common methods include as below:

Method 1: Install Apache Cassandra on Ubuntu 24.04 Using the Cassandra Repository

Apache Cassandra is a perfect choice for mission-critical data management with its robust support. To install Apache Cassandra on Ubuntu 24.04, follow the below steps:

Step 1: Installing Java

First, ensure that Java 8 or Java 11 is installed on your system. Cassandra needs Java to be pre-installed on the server. Let’s install Java 11 via the apt command:

sudo apt update
sudo apt install openjdk-11-jdk

Verify the complete installation process by running the “version” option in the terminal:

java -version

Step 2: Add the Apache Cassandra Repository

Next, add the official Apache Cassandra repository to the system’s sources list. It adds the repository for the 4.1.x versions of Cassandra:

echo "deb https://debian.cassandra.apache.org 41x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list

Step 3: Import Cassandra GPG Key

In this step, users need to add the public key to avoid any conflict during the installation:

curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -

Step 4: Install Cassandra

Now, update the package database and install Cassandra. It installs the latest version of Cassandra available in the repository:

sudo apt update
sudo apt install cassandra

Step 5: Check Cassandra Services

Once installed, Cassandra starts automatically. Users can authenticate the status of the Cassandra service with the “status” utility:

sudo systemctl status cassandra

If the user finds any issue, enable or start the services via the below commands:

sudo systemctl enable cassandra # Enable Services
sudo systemctl start cassandra # Start Services

Step 6: Connect to Cluster

To ensure that Cassandra is functioning correctly, execute the “nodetool” command with the “status” option. It provides a snapshot of your cluster’s topology and state:

nodetool status

Step 7: Access Apache Cassandra Shell

Users can also access the Apache Cassandra shell using the “cqlsh” command:

cqlsh

If the user finds any issue, install the “sudo snap install cqlsh” command.

Remove Apache Cassandra on Ubuntu 24.04

To remove/uninstall Apache Cassandra on Ubuntu 24.04, use the “autoremove” option with the “apt” command. Also, users can remove the GPG key and repository from the system:

sudo apt autoremove --purge cassandra
sudo rm /etc/apt/sources.list.d/cassandra.list
sudo rm /etc/apt/trusted.gpg.d/cassandra-key.gpg

That is all from the installation of the official repository.

Method 2: Install Apache Cassandra Using a Binary Tarball

To install Apache Cassandra on Ubuntu 24.04 using the binary tarball, follow the below steps:

Prerequisites: Install Java 8 or Java 11

Users must start by ensuring that the system meets the necessary prerequisites, which include having Java 8 or Java 11 installed.

Step 1: Download the Cassandra Binary Tarball

Once Java is set up, download the Cassandra binary tarball from the official Apache Cassandra website:

wget https://archive.apache.org/dist/cassandra/4.1.4/apache-cassandra-4.1.4-bin.tar.gz

Step 2: Extract the Tarball

After downloading, extract the tarball using the command “tar” command with the “xzvf” option:

tar xzvf apache-cassandra-4.1.4-bin.tar.gz

Note: Users can replace the “apache-cassandra-*.*.*-bin.tar.gz”, asterisks with the appropriate version numbers of the downloaded tarball.

Step 3: Open Cassandra Configuration File

Navigate to the extracted directory and look for the “conf” directory where you’ll find the “cassandra.yaml” configuration file:

cd apache-cassandra-4.1.4/conf

sudo nano cassandra.yaml

You may need to edit this file to suit your setup, particularly the “cluster_name” and “seeds” properties under the “seed_provider” section:

Step 4: Start Cassandra

To start Cassandra, run the “bin/cassandra” script under the “apache-cassandra-4.1.4” directory:

bin/cassandra

Step 5: Check Cassandra Services

Users can also check the Cassandra services using the “status” option:

bin/nodetool status

That is all from the binary tarball method.

Method 3: Install Apache Cassandra Using Docker Image

To install Cassandra on Ubuntu 24.04 using a Docker image, you’ll need to ensure that Docker is installed on your system. Users can configure Docker on Ubuntu by considering the Docker installation guide for Linux. To install Apache Cassandra using Docker image, follow the stated steps:

Step 1: Pull the Cassandra Docker Image

Once Docker is set up, users can pull the official Cassandra Docker image from the Docker Hub using the below command:

docker pull cassandra:latest

Step 2: Run a Cassandra Container

After pulling the image, you can run a Cassandra container using the command “docker run”. It starts a new Cassandra instance in a detached container:

docker run --name cassandra -d cassandra:latest

Step 3: Connect to Cassandra

You can then access the Cassandra instance using the “cqlsh” command, which connects to the Cassandra query language shell:

cqlsh

It’s important to note that running Cassandra in Docker is suitable for development and testing environments.

How to Configure Apache Cassandra on Ubuntu 24.04?

After installation, configure the “cassandra.yaml” file to suit your cluster’s requirements and start the Cassandra service. Let’s configure Apache Cassandra on Ubuntu 24.04 as below:

Step 1: Configuring Cassandra

Cassandra’s main configuration file is located at “/etc/cassandra/cassandra.yaml”. You may need to edit this file to suit your setup, particularly the “cluster_name” and “seeds” properties under the “seed_provider” section for setting up a multi-node cluster. By default, the cluster name is “Test Cluster” as below:

sudo nano /etc/cassandra/cassandra.yaml

Step 2: Using Cassandra

Finally, start Cassandra using the “cqlsh” utility to interact with your database. This command launches the Cassandra Query Language Shell, where you can execute queries and manage your database:

cqlsh

You have successfully installed and configured Apache Cassandra on Ubuntu 24.04.

Explore Different Commands

For a more detailed guide, including setting up a single-node cluster and troubleshooting, refer to the official documentation provided by Apache. Users can also explore more shell commands via the “HELP” statement:

Note: Configure it to run as a single-node or multi-node cluster, depending on your requirements. Remember to configure the firewall to allow traffic for Cassandra, especially if you’re setting up a multi-node cluster where nodes must communicate.

Conclusion

To install Apache Cassandra on Ubuntu 24.04, make sure that Java 8 or Java 11 is installed. Then, add the Apache Cassandra repository and import the Cassandra GPG key. Finally, update the system repository and install Cassandra via the “sudo apt install cassandra” command. Alternatively, users can install Apache Cassandra using the binary tarball and docker.

The recommended method is to add the official Apache Software Foundation repositories to the system’s sources list by following Method 1.

Categories