Report this

What is the reason for this report?

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

Published on August 9, 2013
Henrique Pinheiro

By Henrique Pinheiro

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>

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

Learn more about our products

About the author

Henrique Pinheiro
Henrique Pinheiro
Author
Category:

Still looking for an answer?

Was this helpful?
Leave a comment...

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!

wget on cassandra version 1.2.8 doesn’t work but using 1.2.9 does wget http://www.us.apache.org/dist/cassandra/1.2.9/apache-cassandra-1.2.9-bin.tar.gz

@yodit: Thanks, I’ve updated the article.

I highly recommend using this to get Cassandra going under Ubuntu:

http://www.datastax.com/documentation/gettingstarted/getting_started/gettingStartedDeb_t.html

Cassandra 1.2.9 link not working, for this moment works http://www.us.apache.org/dist/cassandra/1.2.12/apache-cassandra-1.2.12-bin.tar.gz

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

This is a very simple method for installing Oracle JDK 7 on the server which is needed for the latest versions of Cassandra

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.)

super to users

Very old procedure, Please update this.

I’ve updated the download URL to point to the latest release of Cassandra’s 1.2.x branch.

@astarr are you aware that Cassandra is very mature now and new stable release is wget http://www.us.apache.org/dist/cassandra/2.0.6/apache-cassandra-2.0.6-bin.tar.gz , Please update this and also We can install using Debian package management system so do that also.

Or if you wants i will write whole procedure here so that it will be very easy for all to replicate that procedure again and again.

Has anyone managed to install Cassandra 2.1.0?

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?

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

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

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

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

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

Precise and simple. Good to start

Please update the cassandra download URI

Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.