How to Install Apache Cassandra on Debian 10 Linux

Choose a different version or distribution

Introduction

Before we begin talking about how to install Apache Cassandra on Debian 10 Linux, let's briefly understand – What is Apache Cassandra?

Apache Cassandra is a NoSQL database that is free and open source, with no single point of failure. It offers high availability and linear scalability without sacrificing performance. Many businesses with sizable, active data sets, such as Reddit, Netflix, Instagram, and GitHub, use Apache Cassandra.

In this tutorial, you will install Apache Cassandra on Debian 10 Linux.

Prerequisites

1) Root or a user with sudo privileges.

Installing Java

The latest stable version of Apache Cassandra is 3.11, and it requires OpenJDK 8, which is not present in the official Debian Buster repositories at the time this tutorial was written.

We will enable the AdoptOpenJDK repository and install the prebuilt OpenJDK 8 package.

To add a new repository over HTTPS, update the packages list and install the required dependencies:

sudo apt update
sudo apt install apt-transport-https ca-certificates wget dirmngr gnupg software-properties-common

Add the AdoptOpenJDK APT repository to your system and import the repository's GPG key:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

Execute the following commands to install Java 8:

sudo apt update
sudo apt install adoptopenjdk-8-hotspot

Verify it once done by printing the Java version:

java -version

The output should look like this:

Output

openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

Install Apache Cassandra on Debian 10

We will use the deb package from the vendor repository to install Apache Cassandra. We must first enable the Apache Cassandra repository to do this.

Use the wget command below to import the repository's public key:

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

The output from the aforementioned command should be OK. As a result, the packages from this repository will be regarded as trustworthy because the key was successfully imported.

Use the command below to add the Cassandra repository to your list of system sources:

sudo sh -c 'echo "deb https://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

Install the Apache Cassandra package after updating the package index:

sudo apt update
sudo apt install cassandra

The Cassandra service will launch automatically after the installation has been completed. To ensure Cassandra is up and running, enter:

nodetool status

You should see something like this:

Output

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load        Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  103.71 KiB  256          100.0%            dd8f6709-08ef-45b8-881e-5c1b5bbfc7f7  rack1

All done. Apache Cassandra has been installed successfully.

Configure Apache Cassandra

The /var/lib/cassandra directory stores Apache Cassandra data. Java start-up options can be configured in the /etc/default/cassandra file, which is where configuration files for Cassandra are placed.

Cassandra only listens on localhost by default. You do not need to change the binding interface if the client connecting to the database is also operating on the same system.

Use the cqlsh tool, which comes with the Cassandra package, to communicate with Cassandra using the command line.

cqlsh
Output

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.5 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> 

Rename Apache Cassandra Cluster

The Cassandra cluster's default name is “Test Cluster.” The following steps should be followed if you want to change it:

1) Using cqlsh, access the Cassandra CQL terminal:

cqlsh

2) To rename the cluster to “VegaStack Cluster,” enter the following command:

UPDATE system.local SET cluster_name = 'VegaStack Cluster' WHERE KEY = 'local';

Replace “VegaStack Cluster” with the name of your choice. Type exit to close the terminal after you are done.

3) Edit the cassandra.yaml configuration file and enter your new cluster name:

cd /etc/cassandra/cassandra.yaml

cluster_name: 'VegaStack Cluster'

4) Get rid of the system cache:

nodetool flush system

5) Run the following command to restart Cassandra:

sudo systemctl restart cassandra

Conclusion

We have demonstrated how to set up Apache Cassandra on Debian 10 and how to rename the default cluster if desired. Visit the official Documentation page for more details on how to start using Cassandra.

If you have any queries, feel free to post a comment below, and we'll be happy to answer them.