/How To setup Cassandra and run a Single-Node Cluster on Ubuntu 16.04

How To setup Cassandra and run a Single-Node Cluster on Ubuntu 16.04

Apache Cassandra is an open source distributed database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. Cassandra offers capabilities that relational databases and other NoSQL databases simply cannot match such as: continuous availability, linear scale performance, operational simplicity and easy data distribution across multiple data centers and cloud availability zones. Cassandra’s architecture is responsible for its ability to scale, perform, and offer continuous uptime. Rather than using a legacy master-slave or a manual and difficult-to-maintain shared architecture, Cassandra has a masterless “ring” design that is elegant, easy to setup, and easy to maintain.

Let’s see how we are going to install and use it to run a single-node cluster on Ubuntu 16.04.

System Update:

Update our system to latest updates and security patches available before installing other prerequisites and Cassandra, . You can run the command below to get the latest updates.

$ sudo apt-get update

Installing JDK 8:

Apache Cassandra is run on top of Java Virtual Machine (JVM). We’ll install Oracle JDK 8 on the system before we install Apache Cassandra. Apache Cassandra can also run on OpenJDK, IBM JVM and Azul Zing JVM.

We will install Oracle JDK using the Webupd8 team team PPA repository. First step is to add the webupd8team ppa repository using below command.

$ sudo add-apt-repository ppa:webupd8team/java

Press [ENTER] to continue or ctrl-c to cancel adding it.

You need to press enter to continue adding the webupd8team PPA repository. Then update the package database and install JDK 8 by flowing below command.

$ sudo apt-get update

JDK Key

Now install the Oracle JRE package, this will not only installs but also makes it the default JRE.

$ sudo apt-get -y install oracle-java8-installer

Accept the license agreement when prompted.

oracle-java

Then accepting the Oracle Binary Code License Terms by Choosing ‘Yes’ option.

oracle-java-license

Once installation of Java 8 complete, you can check the current java version by running command below

ubuntu@ubuntu-16:~$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Installing Apache Cassandra:

No we can start installing Apache Cassandra ,from the official Apache Software Foundation repositories, so start by adding the repo so that the packages are available to the system by adding the repo’s source.

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

Then add the following three public keys from the Apache Software Foundation associated with the package repositories to avoid package signature warnings.

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

Add the second key using below commands.

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

To add third keys run the below commands.

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

After this once again update your system, so that ‘apt-get’ can read the metadata of Cassandra repository.

cassandra-key

After system updates, now let’s install Cassandra 37x on your Ubuntu 14 LTS. This is the latest stable version of Cassandra.

Run the below command to install Cassandra on your Ubuntu system and pres ‘y’ key to continue.

$ sudo apt-get install cassandra

intall-casandra

Starting Cassandra service:

Now Cassandra service should be up and running on your system.

To confirm that it’s not running, use below command to check its status.

$ sudo service cassandra status 

If you did not get the running status, then flow the command below in your command line terminal to start its service.

$ sudo service cassandra start

Connecting to the Cluster:

Once your Cassandra service is up and running , check the status of the cluster using below command.

$ sudo nodetool status 
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  103.01 KiB  256          100.0%            da43244b-b1f1-4426-9b24-9ea3cb31ecb4  rack1

In the output, UN means it’s Up and Normal. Then connect to it using its interactive command line interface ‘cqlsh’.

$ cqlsh 

connecting-cluster

Using Apache Cassandra:

Let’s try our Cassandra installation by creating a test database. First of all let’s create a keyspace, this is a namespace for tables. The keyspace name below is ‘mydb’.

cqlsh> CREATE KEYSPACE mydb WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; 

Use the keyspace that we just created.

cqlsh> use mydb;

Create the movies table.

cqlsh:moviedb> CREATE TABLE books (id int PRIMARY KEY, title text, year text);

Let’s describe the table that we just created .

cqlsh:mydb> DESC books;

using cassandra

The table is ready, now you can to add some data in it.

Conclusion:

Cassandra’s data model offers the convenience of column indexes with the performance of log-structured updates, strong support for denormalization and materialized views, and powerful built-in caching. In this article we learned about installation of Apache Cassandra from its official repository. Now you can start exploring this single node installation of Apache Cassandra after some basic configuration and usage of Apache Cassandra.

Request a Free Trial along with a Free Cloud Strategy Session with our Experts.

Spend 30 minutes with our experts to discuss how to design, migrate and/or architect your cloud solution to help you meet your objectives. Following the expert session, we'll set you up with a free trial that is personally tailored to your needs.

Don't have any questions? Simply let us know and we can skip the expert session.

Contact Us Today
2016-07-08T20:29:11+00:00 July 5th, 2016|0 Comments

Leave A Comment