// Tutorial //

How To Install Cassandra and Run a Single-Node Cluster on Ubuntu 22.04

Published on July 8, 2022
How To Install Cassandra and Run a Single-Node Cluster on Ubuntu 22.04

The author selected the Free and Open Source Fund to receive a donation as part of the Write for DOnations program.

Introduction

Apache Cassandra is an open-source, masterless, and distributed NoSQL database system. Cassandra is considered highly suited for mission-critical applications and multi-node setups because it’s scalable, elastic, and fault-tolerant. Cassandra database management works through a node system, and nodes are held within a cluster.

In this tutorial, you’ll install and use Cassandra to run a single-node cluster on Ubuntu 22.04.

Prerequisites

To complete this tutorial, you will need the following:

Note: If you update the package database and upgrade the server with the commands sudo apt update and sudo apt upgrade, rebooting your server before starting Step 1 in this article will stop the prompt encountered in Step 1 from popping up again.

Step 1 — Installing Cassandra

You’ll install Cassandra using packages from the official Apache Software Foundation repositories. You will start by adding the repo so the packages are available to your system.

To begin, log in to your server:

  1. ssh sammy@your-server-ip

Update the package database:

  1. sudo apt update

Then update the system:

  1. sudo apt upgrade

Confirm the installation with y.

During the upgrade process, you may receive a prompt in your terminal (see the image below) requesting input about the kernel version installed and prompting you to reboot the server. You will not see these prompts if you upgraded and rebooted the server in the initial setup phase:

Ubuntu 22.04 kernel upgrade/reboot prompt

Press Enter to close the prompt, but make a note to reboot the server after completing this tutorial.

You may also receive the prompt shown below. If you do, press Enter to accept the default option.

Ubuntu 22.04 service restart prompt

When the update has completed, use the following command to add the official Cassandra repository to the system:

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

The echo command will write the string in quotation marks to a standard output, which is piped (|) to the tee command. The tee command writes it to the cassandra.sources.list file. The -a flag instructs tee to append the line to the end of the file. Otherwise, it would overwrite existing content, if any.

At the time of writing, the latest version of Cassandra is 4.0.4.The command references 40x because you are adding the repository for the 4.0 series of Cassandra.

If successfully added, the output should be:

Output
deb http://www.apache.org/dist/cassandra/debian 40x main

Then, using the wget and tee commands, add the repository’s keys to the list of trusted keys in the system:

  1. wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo tee /etc/apt/trusted.gpg.d/cassandra.asc

In this piped command, wget downloads the KEYS file, which is then piped (|) to the tee command. The tee command writes the input it received to the cassandra.asc file. The q option instructs the wget command to suppress its normal output, and the O option instructs wget to write the file it downloaded to standard output (-). This option is the uppercase letter O, not the number zero.

Refresh the package database once again:

  1. sudo apt update

Finally, install Cassandra:

  1. sudo apt install cassandra

If prompted, confirm the installation with y.

With that, Cassandra should now be installed on the server. In the next section, you’ll confirm that the Cassandra daemon is running.

Step 2 — Confirming the Cassandra Daemon Is Running

With the package installed, the Cassandra daemon should have started automatically.

To confirm that it is running, use this command:

  1. sudo systemctl status cassandra

The output should be similar to the following:

Output
● cassandra.service - LSB: distributed storage system for structured data Loaded: loaded (/etc/init.d/cassandra; generated) Active: active (running) since Tue 2022-06-28 03:25:52 UTC; 1min 32s ago Docs: man:systemd-sysv-generator(8) Process: 4606 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS) Tasks: 52 (limit: 9495) Memory: 2.2G CPU: 17.401s CGroup: /system.slice/cassandra.service └─4723 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOutOfMemoryError -Xss256k -XX:+AlwaysPreTouch -XX> Jun 28 03:25:52 ubuntu-cass systemd[1]: Starting LSB: distributed storage system for structured data... Jun 28 03:25:52 ubuntu-cass systemd[1]: Started LSB: distributed storage system for structured data.

If the output indicates that the daemon failed to start with an oom-kill error, the daemon could not start because the system ran out of memory. To resolve the issue, add more RAM to your server. If you are using a DigitalOcean Droplet, you can resize the Droplet from the Console or using the API.

Now that you’ve confirmed that the Cassandra daemon is running, you’ll next check the status of the cluster and connect to it.

Step 3 — Connecting to the Cluster

To connect to the cluster, you will use the nodetool utility.

To check the cluster’s status, type:

  1. sudo nodetool status

In the output, UN means it’s Up and Normal:

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% d9618485-4c16-4feb-8a2a-632192c0d587 rack1

Then connect to the cluster using its interactive command line interface cqlsh:

  1. cqlsh

You will see it connect:

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

Type exit to quit:

  1. exit

Conclusion

Congratulations! You now have a single-node Cassandra cluster running on Ubuntu 22.04. You can set up a multi-node cluster with How To Install Cassandra and Run a Multi-Node Cluster. More information about Cassandra is available at the project’s website.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
finid

author


Default avatar

Technical Editor


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hello dear future readers,

unfortunately this tutorial did not work as intended. I got the following error when trying to install cassandra:

sudo apt install cassandra
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  cassandra-tools
The following NEW packages will be installed:
  cassandra
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 47.5 MB of archives.
After this operation, 58.8 MB of additional disk space will be used.
Err:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.5
  404  Not Found [IP: 135.181.214.104 443]
E: Failed to fetch https://downloads.apache.org/cassandra/debian/pool/main/c/cassandra/cassandra_4.0.5_all.deb  404  Not Found [IP: 135.181.214.104 443]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

Therefore I searched a little and found out that the cassandra RedHat and Debian repositories have been moved. In order to get it to work I only did the first the commands of section 1 of this tutorial. Afterwards I visited Cassandras Download Tutorial and executed those steps.

I then followed the rest of this post starting at section 2. I hope this helps anyone who experiences the same issue.

Happy hacking, Alex

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel