How to Install Apache Cassandra NoSQL database on a Single Node Ubuntu 16.04
The Apache Cassandra is a distributed NoSQL database management system designed to handle large amounts of data. It's free and open source, and provides High-Availability with no single point of failure. The DBMS was originally developed by Facebook for its Facebook inbox search feature, and was released in 2008. However now, it's developed/maintained by the Apache Software Foundation Developers.
In this tutorial, we will discuss the basic Apache Cassandra installation process with single node. It's worth mentioning that we will install the Apache Cassandra using only one server, and all commands and instructions have been tested on Ubuntu 16.04.
What we will do:
- Install Java on Ubuntu 16.04
- Install NoSQL Database Apache Cassandra on Ubuntu 16.04
- Test Apache Cassandra Installation
- Ubuntu 16.04
- Root privileges
Step 1 - Installing Java 8 on Ubuntu 16.04
The NoSQL database Cassandra is cross-platform application written in Java. So needless to say, having java installed on the system is a primary requirement.
In this first step, we will install java 8 from the PPA repository. However, before adding the repository, make sure you have the python-software-properties package installed on your system. If not, then you can install it using the commands below.
sudo apt update
sudo apt install python-software-properties -y
After the installation is complete, add the new Java PPA repository to the system using the following command:
sudo add-apt-repository -y ppa:webupd8team/java
Then update all Ubuntu repositories.
sudo apt update
That's it. Now you can install Java 8 using command below.
sudo apt install oracle-java8-installer -y
As part of the installation process, you will be asked about the 'Oracle license terms' - choose 'Yes' and press Enter.
To verify that Java is now installed, execute the following command:
The system should show the version of Java installed - basically, an output similar to the following:
So there you go, Java 8 has been installed on your Ubuntu 16.04 system.
Step 2 - Installing Apache Cassandra on Ubuntu 16.04
Apache Cassandra can be installed from the binary tarball files. Alternatively, you can also install it using Debian packages from the Apache repository. In this tutorial, we will be using the latter method for installation.
As part of this approach, we need to add the Apache Cassandra repository, then add a new key, and then finally install the NoSQL database Apache Cassandra.
So to start off, add new Apache Cassandra repository the system using the following command.
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
Now add and sign the software developer key.
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
Moving on, now update Ubuntu repositories and then install Apache Cassandra. Use the following commands for this purpose:
sudo apt update
sudo apt install cassandra -y
After the installation is complete, start the Cassandra service and then enable it to run at the boot time using the following systemctl commands.
systemctl start cassandra
systemctl enable cassandra
To check the service status, use the following command.
systemctl status cassandra
Here's the output the aforementioned command produced on our machine:
So in this step, we successfully installed Apache Cassandra on Ubuntu 16.04 server, and got it up and running.
Step 3 - Basic Apache Cassandra management tools
In this step, we will do some tests on our NoSQL database installation. The Apache Cassandra provides some command-line tools for managing the service and database.
- Testing using nodetool
Basically, nodetool is the command-line utility for managing Apache Cassandra cluster. In our setup, we do not have the cluster, as we've only installed the NoSQL database on 1 server. But, we can still do some tests using the nodetool.
To begin with, run the nodetool command to get the Cassandra server status.
sudo nodetool status
And you should get an output similar to the following:
So as you can see, the Apache Cassandra is 'Up' with the 'Normal' state. And it's running under the localhost IP.
- Testing using cqlsh
The cqlsh is the command-line tool written in Python for executing the Cassandra Query Language (CQL) command. It's the Cassandra client command-line utility.
Simply run the 'cqlsh' command (as shown below).
And you should see output similar to the following:
As you can see, the output in our case reveals we're connected to our 'Test Cluster' that's running on localhost.