Install and Configure Apache Cassandra on Debian 11

In this article, we want to teach you How To Install and Configure Apache Cassandra on Debian 11.

Cassandra or Apache Cassandra is an open-source NoSQL database.

It stores data in the form of key-value pairs and uses its own query retrieving language known as CQL (Cassandra Query Language).

The outermost shell of Cassandra is known as Cluster and it consists of several nodes, nodes are just the instance of Cassandra running on a machine.

How To Install and Configure Apache Cassandra on Debian 11

To install Apache Cassandra on Debian 11, you need to log in to your server as a non-root user with sudo privileges. To do this you can follow our article about the Initial Server Setup with Debian 11.

Now follow the steps below to install Apache Cassandra.

Install Java on Debian 11

First, you need to install java on your Debian 11. Use the following command to install the latest Java:

 sudo apt install default-jdk

After your installation is completed, verify it by checking the Java version:

java --version

Your output should similar to this:

Output
openjdk version "11.0.13" 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+8-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.13+8-post-Debian-1deb11u1, mixed mode, sharing)

Now you can start to install Apache Cassandra.

Install Apache Casandra on Debian 11

The Apache Cassandra package is not available in the default Debian repository. You should add the Cassandra repository on Debian 11.

First, you need to install the dependencies with the following command:

sudo apt install curl gnupg2 -y

Then, you should add the GPG key on Debian 11 with the following command:

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

Now you can add the Apache Cassandra repository on Debian 11 with the following command:

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

Next, update your local package index:

sudo apt update

Here you can install Cassandra with the following command:

sudo apt install cassandra -y

Apache Cassandra will automatically start on your Debian 11 when your installation is completed. To verify that your service is active and running use the following command:

sudo systemctl status cassandra

In your output you will see:

Output
cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; generated)
Active: active (running) since Tue 2021-11-23 04:12:56 EST; 1min 42s ago
Docs: man:systemd-sysv-generator(8)
Process: 6488 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/>
Tasks: 41 (limit: 2340)
Memory: 1.3G
CPU: 22.149s
CGroup: /system.slice/cassandra.service
└─6581 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPrioriti

Also, you can check the status of Cassandra clusters with the following command:

sudo nodetool status

In your output you will see:

Output
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 69.08 KiB 16 100.0% 2511a1bd-f614-42e7-8195-28ea3dbd8a93 rack1

The “UN” mark in the output shows that the cluster is “UP” and running “Normal”.

At this point, you can connect to the Apache Cassandra cluster on Debian 11 with the command below:

cqlash

You will get the following output:

Output
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlash>

Now that you have Apache Cassandra installed on your Debian 11, let’s see how to configure it.

Configure Apache Cassandra on Debian 11

At this point, you can make some changes in the Cassandra cluster. If you want to change the Cassandra cluster name, you can use the following command from the cluster:

cqlsh> UPDATE system.local SET cluster_name = 'orca cluster' WHERE KEY = 'local';

We use the orca cluster name, you can choose your own name and replace it.

Exit from your cqlsh shell with the following command:

cqlsh> exit

Now you need to edit the Apache Cassandra configuration file. Open the file with your favorite text editor, here we use vi:

sudo vi /etc/cassandra/cassandra.yaml

In the file search for the cluster_name option and change it to your name:

cluster_name: 'orca cluster'

When you are done, save and close the file.

To apply this change, restart Cassandra on Debian 11 with the following command:

sudo systemctl restart cassandra

Now connect to your Cassandra cluster again:

cqlsh

In your output you will see that your cluster name is changed:

Connected to orca cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh>

Conclusion

At this point, you learn to install Apache Cassandra on Debian 11. You can start using it.

Hope you enjoy it.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!