How To install Cassandra On Ubuntu Using Microsoft Azure Virtual Machine

Introduction

Apache Cassandra is highly scalable open source NoSQL database; it's fast and is used to store massive amounts of data. It is a best choice to use for small to big companies because of fault-tolerance on the commodity hardware or a Cloud infrastructure and for replicating across multiple datacenters for Cassandra.

In this tutorial, you will learn how to install Cassandra on Single Node Cluster, using Ubuntu 14.04 Microsoft Azure virtual machine.

Prerequisite

You need to complete the prerequisites given below.

  1. Ubuntu 14.04 Server on Microsoft Azure.
  2. A root user.

Here is my virtual machine on Microsoft Azure (UBUNTU 14.04).


Update Ubuntu Server

Update your Ubuntu Server. Using this command, get all the updates made by Ubuntu

sudo apt-get update

Install Oracle JRE

Cassandra requires Oracle Java SE Runtime Environment (JRE), which has been installed on Ubuntu 14.04. First, you have to install Oracle Java virtual machine on your Azure virtual machine. To install JRE, you will have to add a Personal Package Archives (PPA) into Ubuntu apt repository, using the commands given below.

sudo add-apt-repository ppa:webupd8team/java

and update the system again

sudo apt-get update

When Oracle JRE is installed and system is updated, run this command to make Oracle JRE default for Ubuntu. Because Cassandra, which is required to make Oracle JRE default is required to run on the Server.

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

Now, verify if Oracle JRE is default or not

java -version

As an output on my Server, it is shown below.

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)

Installing Cassandra

By default, Ubuntu repository don’t have Cassandra Package. Thus, we will add this repository from Apache Software Foundation repositories so that the packages are available to your system. Now, run this command to add repo into

/etc/apt/sources.list.d/cassandra.sources.list

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

Now, we need to add three public keys from the Apache Software Foundation, which are associated with the package repositories to avoid any type of warning generated by the Server.

Add the first one using the commands given below.

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

Add second Key

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

Add third key

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

Update the Server again.

sudo apt-get update

If you see an error or warning related to the keys, as shown below.

GPG error: http://www.apache.org 310x InRelease: The signatures given below can not be verified because the public key is not available: NO_PUBKEY A278B781FE4B2BDA

Add the public key A278B781FE4B2BDA, as shown below.

sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA

and repeat

sudo apt-get update

NOTE

Keys can be different and you can get a list of public keys from this link

https://www.apache.org/dist/cassandra/KEYS.

Now, every thing is done to install Cassandra on Ubuntu Server. Thus, be ready to install it.

Simply run the command given below.

sudo apt-get install cassandra

See the magic

Starting Cassandra

First, you have to check the status of Cassnadra in order to confirm, if it is running or not.

sudo service cassandra status

If it is not running, run the command given below.

sudo service cassandra start

Stop Cassandra Server and run the command given below.

sudo service cassandra stop

  1. Verify that Cassandra is running by invoking nodetool status from the command line.
  2. The default location of configuration files is /etc/cassand
  3. The default location of log and data directories is /var/log/cassandra and /var/lib/cassandra.
  4. Start-up options (heap size, etc) can be configured in /etc/default/cassandra.

Connecting to the Cassandra

Run the command given below to connect to Cassandra database.

cqlsh

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>

To exit

Cqlsh> exit

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now