// Tutorial //

How To Install Cassandra and Run a Single-Node Cluster On a Ubuntu VPS

Published on August 8, 2013
Default avatar
By Henrique Pinheiro
Developer and author at DigitalOcean.
How To Install Cassandra and Run a Single-Node Cluster On a Ubuntu VPS

Introduction

Cassandra, or Apache Cassandra, is a highly scalable open source database system, achieving great performance on multi-node setups. In this tutorial, you’ll learn how to install Cassandra, the Oracle Java VM, which is highly recommended for Cassandra, and how to run your first test single-node cluster.

Installing the Oracle Java VM

Make a temporary folder on your home directory to install Java.

mkdir ~/temp
cd ~/temp

The Cassandra documentation highly recommends the Oracle Java VM 8, so you’ll have to download it from Oracle’s website. It requires a free account, which you can register here. After you’ve created your account, download either the 32-bit or the 64-bit (recommended) version of Java 8. Once you’ve downloaded it, transfer it to your VPS using FTP or any other tool. You can find a tutorial on how to setup an FTP server here.

Now extract the contents of the archive:

tar -zxf jdk-8u65-linux-x64.tar.gz

You should now move it to the proper folder:

sudo mkdir /usr/local/java
sudo mv jdk1.8.0_65/ /usr/local/java

To make it the default Java VM on your VPS, add these lines to the /etc/profile file:

JAVA_HOME=/usr/local/java/jdk1.8.0_65
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jdk1.8.0_65
PATH=$PATH:$HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

by scrolling down after running:

sudo nano /etc/profile

and pasting it at the end of the file, like so:

How /etc/profile should look

After you’ve done this, press CTRL+O to save and CTRL+X to exit. Next, run the following lines so when the command “java” is called, it’s done so by the right VM.

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_65/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_65/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_65/bin/javaws" 1
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_65/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_65/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_65/bin/javaws

You should now reboot your VPS so everything is updated:

sudo reboot

When establishing a SSH connection again, test to see if everything is set properly by running:

java -version
echo $JAVA_HOME

If everything went OK, you should see this:

If Java was installed properly, you should see this

Installing Cassandra

To install Cassandra, download the binary files from the website, unpack them and move it to your personal folder:

cd ~/temp
wget http://mirror.cc.columbia.edu/pub/software/apache/cassandra/2.2.3/apache-cassandra-2.2.3-bin.tar.gz
tar -zxf apache-cassandra-2.2.3-bin.tar.gz
mv apache-cassandra-2.2.3 ~/cassandra

Next, make sure that the folders Cassandra accesses, such as the log folder, exists and that Cassandra has the right to write on it:

sudo mkdir /var/lib/cassandra
sudo mkdir /var/log/cassandra
sudo chown -R $USER:$GROUP /var/lib/cassandra
sudo chown -R $USER:$GROUP /var/log/cassandra

Now set Cassandra’s variables by running:

export CASSANDRA_HOME=~/cassandra
export PATH=$PATH:$CASSANDRA_HOME/bin

Running Cassandra

To run a single-node test cluster of Cassandra, you aren’t going to need to change anything on the cassandra.yaml file. Simply run:

sudo sh ~/cassandra/bin/cassandra

and then run:

sudo sh ~/cassandra/bin/cqlsh

and if it says "Connected to: 'Test Cluster'" as it does below, you are now running your single-node cluster.

root@cassandra:~# sudo sh ~/cassandra/bin/cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 2.2.3 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cqlsh>

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

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!

Obsolete information, Please take this post off or update it.

I can’t get this to work on Ubuntu 12.04. It seems that everything installs, but when I load the cli, it tells me that it cannot connect to the database. Everything says I’m doing it correct. This article needs updating too because cassandra has moved to 2.0.x and requires java 7. (The Java links above are broken.)

Instead of using 1.2.9 or any other version go to http://www.us.apache.org/dist/cassandra and replace the version with the latest, in my case I used http://www.us.apache.org/dist/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz

Please update the cassandra download URI

Precise and simple. Good to start

@asb kindly update the wget path to the latest cassandra version

This is pretty outdated, There are some interesting courses and tutorials on Cassandra here on Parleys: https://www.parleys.com/category/developer-training-tutorials/big-data/apache-cassandra

Works by changing it to latest version. Thanks it still helps a lot.

Latest stable version is Cassandra 2.0.12. You can still follow these instructions and change the wget command to the latest path in the tar.gz

I’m struggling to install 2.1.0 on Ubuntu in a virtualbox instance. I keep getting this when I attempt anything with nodetool:

$ nodetool status nodetool: Failed to connect to ‘127.0.0.1:7199’ - ConnectException: ‘Connection refused’.

Instructions followed: http://www.datastax.com/documentation/cassandra/2.1/cassandra/install/installDeb_t.html?