Read in 3 minutes

last updated 

How to Install Apache Cassandra on Debian 9

Apache Cassandra is a free and open source NoSQL database with no single point of failure. It provides linear scalability and high availability without compromising performance. Apache Cassandra is used by a number of companies that have large, active data sets, including Reddit, NetFlix, Instagram, and Github.

This tutorial guides you through the process of installing Apache Cassandra on Debian 9.

Prerequisites

To be able to install packages on your Debian system you need to be logged in as a user with sudo privileges.

Installing Apache Cassandra

The recommended method to install Apache Cassandra on Debian 9 is by installing the deb package from the official Apache Cassandra repository.

At the time of writing this article, the latest version of Apache Cassandra is 3.11 and requires OpenJDK 8 to be installed on the machine.

To install the OpenJDK 8 package run the following command:

sudo apt update
sudo apt install openjdk-8-jdk

Once completed, verify it by printing the Java version:

java -version

The output should look something like this:

openjdk version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-2~deb9u1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

Install the apt-transport-https package that necessary to access a repository over HTTPS:

sudo apt install apt-transport-https

The next step is to enable the Apache Cassandra repository.

Import the repository’s public key using the following wget command:

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

The command above should output OK which means that the key has been successfully imported and packages from this repository will be considered trusted.

Add the Cassandra repository to your system sources’ list by running the command below:

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

Update the packages’ index and install the latest version of Apache Cassandra:

sudo apt update
sudo apt install cassandra

When the installation process is complete the Cassandra service will automatically start. You can verify that Cassandra is running by typing:

nodetool status

You should see something similar to this:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load        Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  114.55 KiB  256          100.0%            d8c27e24-ea26-4eeb-883c-5986218ba3ca  rack1

That’s it. Apache Cassandra has been installed on your Debian server.

Configuring Apache Cassandra

Apache Cassandra data is stored in the /var/lib/cassandra directory. Configuration files are located in /etc/cassandra and Java start-up options can be configured in the /etc/default/cassandra file.

By default, Cassandra listens on localhost only. If the client connecting to the database is also running on the same machine you don’t need to change the binding interface.

To interact with Cassandra through the command line, use the cqlsh tool which is shipped with the Cassandra package.

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

Renaming Apache Cassandra Cluster

By default, the Cassandra cluster is named “Test Cluster”. If you want to change it follow the steps bellow:

  1. First, login to the Cassandra CQL terminal by typing:

    cqlsh

    and run the following command to change the cluster name to “Linuxize Cluster”:

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

    Change “Linuxize Cluster” with your desired name. Once done, type exit to exit the terminal.

  2. Next, edit the cassandra.yaml configuration file and put your new cluster name.

    /etc/cassandra/cassandra.yaml
    cluster_name: 'Linuxize Cluster'
  3. Run the command below to clear the system cache:

    nodetool flush system
  4. Finally restart the Cassandra service by running:

    sudo systemctl restart cassandra

Conclusion

You have successfully installed Apache Cassandra on your Debian 9 server. For more information about how to get started with Cassandra visit their official Documentation page.

If you hit a problem or have feedback, leave a comment below.