How to Install Apache Cassandra on Debian 9

In this tutorial, we will show you how to install Apache Cassandra on a Debian 9 VPS.

Apache Cassandra is a free and open-source distributed NoSQL database management system that provides High-Availability with no single point of failure. Cassandra does not use the table model seen in MySQL, MSSQL or PostgreSQL – rather, it uses a cluster model. It is designed to handle large amounts of data across commodity hardware. It provides linear scalability by adding a new machine to it without any interruption to applications. Apache Cassandra is used by many popular organizations including Apple, NetFlix, eBay, and Easou.

Let’s begin with the installation.

Prerequisites

  • For the purposes of this tutorial, we will use a Debian 9 VPS.
  • The latest version of Java 8, either the Oracle Java Standard Edition 8 or OpenJDK 8 is installed.
  • Full SSH root access or a user with sudo privileges is also required.

Step 1: Connect via SSH and Update the OS

Connect to your server via SSH as the root user using the following command:

ssh root@IP_ADDRESS -p PORT_NUMBER

Remember to replace “IP_ADDRESS” and “PORT_NUMBER” with your server’s respective IP address and SSH port number.

Before starting with the installation, you will need to update your OS packages to their latest versions. It’s easy to do, and it won’t take more than a few minutes.

You can do this by running the following command:

apt-get update 
apt-get upgrade

Once the updates are completed, we can move on to the next step.

Step 2: Install Java 8

Apache Cassandra requires the latest version of Java 8 to be installed. To install Java 8 on your Debian 9 VPS, run the following command:

apt-get install openjdk-8-jdk

Next, verify the Java installation by running the following command, which will print the Java version:

java -version

The output should look something like this:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1~deb9u1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Step 3: Install Apache Cassandra

To install Apache Cassandra on your server, we need to add the Apache Cassandra repository.

Add the Cassandra repository by running the following command:

echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | tee -a /etc/apt/sources.list.d/cassandra.sources.list

Add the Apache Cassandra repository keys using the following command:

curl https://www.apache.org/dist/cassandra/KEYS | apt-key add -
apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA

Next, update the package index and install Apache Cassandra using the following command:

apt-get update
apt-get install cassandra

Once installed, start the Apache Cassandra service and enable it to start after system reboot with the following command:

systemctl start cassandra
systemctl enable cassandra

To check the service status, use the following command.

systemctl status cassandra

We should see the following output:

● cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; generated; vendor preset: enabled)
Active: active (running) since Wed 2019-07-24 16:31:25 UTC; 10s ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/cassandra.service
└─9545 java -Xloggc:/var/log/cassandra/gc.log -ea -XX:+UseThreadPr…on

Jul 24 16:31:25 cassandra systemd[1]: Starting LSB: distributed storage sys…a...
Jul 24 16:31:25 cassandra systemd[1]: Started LSB: distributed storage syst…ata.
Hint: Some lines were ellipsized, use -l to show in full.

Step 4: Test the Apache Cassandra Installation

Apache Cassandra provides a nodetool command-line utility for managing Apache Cassandra cluster. Here, we can do some tests using the nodetool to verify the Cassandra cluster.

To begin with, run the nodetool command to get the Cassandra server status.

nodetool status

And you should get an output similar to the following:

Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 103.65 KiB 256 100.0% 562b6fc4-f5dc-4e64-ab42-4bbe490f9358 rack1

As you can see, the Apache Cassandra is ‘Up’ with the ‘Normal’ state. And it’s running under the localhost IP.

Step 5: Configure Apache Cassandra

Apache Cassandra stores all of its configuration files in the /etc/cassandra directory and data is stored in the /var/lib/cassandra directory.

By default, Apache Cassandra is configured to listen on localhost only and you don’t need to change the default configuration file if the client is also running on the same host.

You can also connect Apache Cassandra with Cassandra Query Language (CQL) command-line utility.

Simply run the following command to interact with Apache Cassandra:

cqlsh

The output will be similar to the following:

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>

By default, the Apache Cassandra cluster is named “Test Cluster” as shown in the above output. You can change the cluster name with the following command:

cqlsh> UPDATE system.local SET cluster_name = 'RoseHosting Cluster' WHERE KEY = 'local';

Change ‘RoseHosting Cluster’ with your desired name. Once done type exit to exit from the console. Next, open the cassandra.yaml configuration file and provide your new cluster name.

nano /etc/cassandra/cassandra.yaml

Change the following line with your desired name:

cluster_name: 'RoseHosting Cluster'

Save and close the file. Then, clear the system cache with the following command:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
nodetool flush system

Finally, restart the Apache Cassandra service to apply the configuration changes:

systemctl restart cassandra

Next, log in again with cqlsh and verify the new cluster name is visible.

cqlsh

The output will be similar to the following:

Connected to RoseHosting 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>

Congratulations. We have successfully installed Apache Cassandra on our Debian 9 VPS. If you are new to Apache Cassandra, it is recommended to use the official documentation as a starting point. The documentation is available at the Apache Cassandra documentation page, and it will help you learn how to configure and use the service for your projects.

Follow this guide for installing Apache Cassandra on Ubuntu 20.04


Of course, you don’t have to install Apache Cassandra on a Debian 9 by yourself if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Apache Cassandra on a Debian 9 on your server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to Install Apache Cassandra on Debian 9, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Leave a Comment