Wednesday, March 21, 2018

How To Install & Setup Apache Cassandra and Run a Single Node cluster on Ubuntu 16.04

Apache Cassandra -
Apache Cassandra is an open source distributed database management system design to handled large amount of data across many commodity servers, provide high availability with no single point of failure.

Cassandra offers capabilities that relational database other NoSQL databases simply cannot match as continues availability linear scale performance, operational simplicity, and easy data distribution across multiple data centers and cloud availability zones.

Prerequisites- 

  • JDK 
  • User with sudo access 
Step 1- 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.

The first step is to add the webupd8team ppa repository using below command.
$ sudo add-apt-repository ppa:webupd8team/java
Press Enter to continue 
After added repository, update the package database. Use command below
$ sudo apt-get update
After package database update install JRE package, use the following command.
$ sudo apt-get -y install oracle-java8-installer
Accept License Agreement
Access License Term
Once the Java 8 installation complete, Your terminal output should be like this.

Check the installed version of Java using the command below.
$ 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)

Step 2- Install Apache Cassandra
Now, We can start the installation of Apache Cassandra from the official software foundation repository, So start by adding the official repository to your Ubuntu machine. Use command below to add repository
$ echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
Add the Apache Cassandra repository keys:
$ curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
After added repository Key, update the package database. Use command below
$ sudo apt-get update
After system updates, now let’s install Cassandra 37x on your Ubuntu 16 LTS. This is the latest stable version of Cassandra.

Add the public Key
$ sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA
After added repository Key, update the package database. Use command below
$ sudo apt-get update
Now, Run the below command to install Cassandra on your Ubuntu system and press ‘y’ key to continue.
$ sudo apt-get install cassandra

Step 3- Start Cassandra Service
Now Cassandra service should be up and be running on your system.

To confirm that it’s not running, use below command to check its status. 
$ sudo systemctl status cassandra.service
If you did not get the running status, then flow the command below in your command line terminal to start its service.
$ sudo systemctl start cassandra.service
Step 4- Connecting to the Cluster:
Once Cassandra Service up and running, Check the status of the cluster using the command below
$ sudo nodetool status
In the output, UN means it’s Up and Normal. Then connect to it using its interactive command line interface ‘cqlsh’.
$ cqlsh
Step 5- Using Apache Cassandra
Let's test our created environment by creating a database and add a table with data.

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

cqlsh> use mytestdb;
Create table

cqlsh:mytestdb> CREATE TABLE Linux (id int PRIMARY KEY, title text, year text);
Let’s describe the table that we just created.

cqlsh:mytestdb> DESC Linux;

CREATE TABLE mytestdb.linux (
    id int PRIMARY KEY,
    title text,
    year text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';
The table is ready, now you can use to add some data in it.

Apache Cassandra Installation has done successfully.

1 comment: