Installing Cassandra and Running a Single-Node Cluster on Ubuntu 14.04
Cassandra, or Apache Cassandra, is a very scalable open source NoSQL database system, capable of reaching high performance on multi-node setups.
In this tutorial will teach you how to install and use Cassandra to run a single-node cluster on an Ubuntu 14.04 server.
In order to use this tutorial, you will need the following things:
- Ubuntu 14.04 VPS
- A non-root user with sudo privileges.
Installing the Oracle Java Virtual Machine
Cassandra needs the Oracle Java SE Runtime Environment (JRE) to be installed. So, you should install and confirm that it is the default JRE.
For the Oracle JRE Package to be available, you will need to append a Persona Package Archive (PPA) with the following commands.
sudo add-apt-repository ppa:webupd8team/java
Next you should update the package database.
sudo apt-get update
Afterwards Install the Oracle JRE. Installing this specific package, does not install only it but will cause it to be the default JRE. Once asked, accept the license agreement.
sudo apt-get install oracle-java8-set-default
Once this is installed, confirm that it is currently the default JRE.
You will see an output similar to the one 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)
Obtain Cassandra with packages from the official Apache Software Foundation repositories and begin by appending the repo, so you will have the packages available in your system.
At the time this tutorial was written, Cassandra 3.6 was the latest version. In case it is not currently, you may change it to match the latest one. For example, replace it with ‘37x’ in case Cassandra 3.7 is the latest one.
echo "deb http://www.apache.org/dist/cassandra/debian 36x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
Now append the repo’s source.
echo "deb-src http://www.apache.org/dist/cassandra/debian 36x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
To avoid package signature warnings when doing any package updates, you will have to add three public keys provided by the Apache Software Foundation associated with the package repositories.
Append the first one with the following pair of commands, run them one after the other.
gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D gpg --export --armor F758CE318D77295D | sudo apt-key add
Then append the second key.
gpg --keyserver pgp.mit.edu --recv-keys 2B5C1B00 gpg --export --armor 2B5C1B00 | sudo apt-key add –
And, lastly, the third one.
gpg --keyserver pgp.mit.edu --recv-keys 0353B12C gpg --export --armor 0353B12C | sudo apt-key add –
Once more, update the package database.
sudo apt-get update
And now you can install Cassandra.
sudo apt-get install cassandra
Troubleshooting and Starting Cassandra
Normally, Cassandra would have started automatically by now however, because of a bug, it will not. To verify whether its running or not, use the following command.
sudo service cassandra status
In case it is not running, you will receive the output below.
Output * could not access pidfile for Cassandra
This is a pretty known issue occurring often with the latest versions of Cassandra on Ubuntu. First, you should attempt a couple of fixes, starting by modifying the ‘init’ script. The parameter you will be editing is on line 60 of the script, so open it with the following command.
sudo nano +60 /etc/init.d/cassandra
The line should read as below.
Replace it with the following.
Save and exit the file, then restart the server.
sudo shutdown -r now
Once you have logged back in, Cassandra should be running: Confirm again with the below.
sudo service cassandra status
You will know if the fix was successful because this output will appear as shown below.
Output * Cassandra is running
Connecting to the Cluster
In case the attempt to start Cassandra was successful, check the status of the cluster.
sudo nodetool status
When you are in the output, ‘UN’ means it’s Up and Normal:
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns Host ID Rack UN 127.0.0.1 142.02 KB 256 ? 2053956d-7461-41e6-8dd2-0af59436f736 rack1
Note: Non-system key spaces do not have the same replication settings, effective ownership information is meaningless
Afterwards, connect to it with its interactive command line interface ‘cqlsh’.
You should see it connect.
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>
Type exit to quit.
Now you should have your single-node Cassandra cluster running on an Ubuntu 14.04 server.
For more information about Cassandra, navigate over to the project’s website: project’s website.