Skip to main content
  1. Tutorials/

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

Tutorials NoSQL Ubuntu
Introduction>

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>

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:

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:

Installing Cassandra>

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>

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>