Tutorial

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

Published on October 21, 2015
How To Install Cassandra and Run a Single-Node Cluster on Ubuntu 14.04

Introduction

Cassandra, or Apache Cassandra, is a highly scalable open source NoSQL database system, achieving great performance on multi-node setups.

In this tutorial, you’ll learn how to install and use it to run a single-node cluster on Ubuntu 14.04.

Prerequisite

To complete this tutorial, you will need the following:

Step 1 — Installing the Oracle Java Virtual Machine

Cassandra requires that the Oracle Java SE Runtime Environment (JRE) be installed. So, in this step, you’ll install and verify that it’s the default JRE.

To make the Oracle JRE package available, you’ll have to add a Personal Package Archives (PPA) using this command:

  1. sudo add-apt-repository ppa:webupd8team/java

Update the package database:

  1. sudo apt-get update

Then install the Oracle JRE. Installing this particular package not only installs it but also makes it the default JRE. When prompted, accept the license agreement:

  1. sudo apt-get install oracle-java8-set-default

After installing it, verify that it’s now the default JRE:

  1. java -version

You should see output similar to the following:

Output
java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Step 2 — Installing Cassandra

We’ll install Cassandra using packages from the official Apache Software Foundation repositories, so start by adding the repo so that the packages are available to your system. Note that Cassandra 2.2.2 is the latest version at the time of this publication. Change the 22x to match the latest version. For example, use 23x if Cassandra 2.3 is the latest version:

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

The add the repo’s source:

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

To avoid package signature warnings during package updates, we need to add three public keys from the Apache Software Foundation associated with the package repositories.

Add the first one using this pair of commands, which must be run one after the other:

  1. gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D
  2. gpg --export --armor F758CE318D77295D | sudo apt-key add -

Then add the second key:

  1. gpg --keyserver pgp.mit.edu --recv-keys 2B5C1B00
  2. gpg --export --armor 2B5C1B00 | sudo apt-key add -

Then add the third:

  1. gpg --keyserver pgp.mit.edu --recv-keys 0353B12C
  2. gpg --export --armor 0353B12C | sudo apt-key add -

Update the package database once again:

  1. sudo apt-get update

Finally, install Cassandra:

  1. sudo apt-get install cassandra

Step 3 — Troubleshooting and Starting Cassandra

Ordinarily, Cassandra should have been started automatically at this point. However, because of a bug, it does not. To confirm that it’s not running, type:

  1. sudo service cassandra status

If it is not running, the following output will be displayed:

Output
* could not access pidfile for Cassandra

This is a well-known issue with the latest versions of Cassandra on Ubuntu. We’ll try a few fixes. First, start by editing its init script. The parameter we’re going to modify is on line 60 of that script, so open it using:

  1. sudo nano +60 /etc/init.d/cassandra

That line should read:

/etc/init.d/cassandra
CMD_PATT="cassandra.+CassandraDaemon"

Change it to:

/etc/init.d/cassandra
CMD_PATT="cassandra"

Close and save the file, then reboot the server:

  1. sudo reboot

Or:

  1. sudo shutdown -r now

After logging back in, Cassandra should now be running. Verify:

  1. sudo service cassandra status

If you are successful, you will see:

Output
* Cassandra is running

Step 4 — Connecting to the Cluster

If you were able to successfully start Cassandra, check the status of the cluster:

  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 Host ID Rack UN 127.0.0.1 142.02 KB 256 ? 2053956d-7461-41e6-8dd2-0af59436f736 rack1 Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless

Then connect to it 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 5.0.1 | Cassandra 2.2.2 | CQL spec 3.3.1 | Native protocol v4] Use HELP for help. cqlsh>

Type exit to quit:

  1. exit

Conclusion

Congratulations! You now have a single-node Cassandra cluster running on Ubuntu 14.04. 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
Tammy Fox

editor


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 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!

I did all the instructions, but this work not correct. Sometime it work, but in most cases, during execution of the command: "sudo nodetool status", I get: "Connection refused" or "Killed" and cassandra is down.

This comment has been deleted

    I also added an 8 GB volume to my instance and linked /var/lib/cassandra to it. Stop Cassandra, move /var/lib/cassandra to the new mount point, and soft symlink back to /var/lib. Then start Cassandra. Make sure you do cat /proc/mounts to get the mount line you need for /etc/fstab.

    3.11 has CMD_PATT="Dcassandra-pidfile=.*cassandra\.pid" in /etc/init.d/cassandra.

    Oracle Java 8 Installer is not available any longer.

    I was unable to get the package to install. I am using

    openjdk version "1.8.0_191"
    OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
    OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
    

    Without rebooting, there’s a half-half chance that Cassandra will start. if without rebooting start facing problem is sudo service cassandra force-reload.

    Awesome work its been a lot of time I tried hard to install cassandra…but your article helped me thanks a lot…

    This comment has been deleted

      I tried installing The latest version of cassandra (8 dec 2016), encountered the same

      • could not access pidfile for Cassandra problem , but in the /etc/init.d/cassandra file CMD_PATT=“cassandra.+CassandraDaemon” is not present instead CMD_PATT=“Dcassandra-pidfile=.cassandra.pid" , I tried to edit that to CMD_PATT=“cassandra” as mentioned in the post but still am encountering the same problem" could not access pidfile for Cassandra”, could anyone give suggest any other solution to this problem , thank you so much in advance.

      house

      If I use deb-src, I am not able to install cassandra but with deb I was easily able to install it.

      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!

      Get our biweekly newsletter

      Sign up for Infrastructure as a Newsletter.

      Hollie's Hub for Good

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

      Become a contributor

      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

      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