Installation Instructions to get Cassandra on Ubuntu

Introduction

The following are instructions to get Cassandra installed on your servers.

You may also want to install Cassandra directly from a file distributed from the Cassandra website (if you want to work with a version on the edge.) In that case, the Java installation instructions still apply to you, however, the Cassandra installation then falls in your lap...

Java

Cassandra uses Java so you want to install Java first. In order to get the latest version of Java directly from Oracle, you want to install the PPA update source as follow:

sudo vim /etc/apt/sources.list.d/webupd8team-java-trusty.list

The content of that file is expected to be the following (deb-src is optional):

deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main

You are invited to change the name 'trusty' with the current version of Ubuntu you are running.

Now you want to add the signature key in order to avoid warnings saying that the software to be installed is not trusted. The following is the command to run to add the key to the apt system:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <key>

The signature key can be found on the PPA:

https://launchpad.net/~webupd8team/+archive/ubuntu/java

Click on the Technical details about this PPA and the key shows up. It looks like this at this time: 1024R/EEA14886, the key is the part after the slash; EEA14886 in this example. So the final command becomes:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886

Another way to find the key is to run the following command:

sudo apt-get update

and get the warning about the fact that the PPA is not trusted.

W: GPG error: http://ppa.launchpad.net trusty Release: the following signatures couldn't be verified because the public key is not available: NO_PUBKEY C2518248EEA14886

As you can see, the EEA14886 appears in this message. The key is exactly 8 hexadecimal digits.

Note that if you do not mind getting the PPA source information added anywhere (likely in the main sources.list file), then you may use the following PPA command:

sudo add-apt-repository ppa:webupd8team/java

This will automatically setup the key for you, but the deb definition is probably not at the right place. Just like the manual add, you have to run an update after the add:

sudo apt-get update

Now that you have the Java source in place, you may install the packages with:

sudo apt-get install oracle-java8-installer

Obviously, you want to select the proper version of Java. At this time it would be 8. Cassandra should be compatible with Java 7 and Java 6 if you need to use those older versions on your server (although it is recommended that you use dedicated servers for each Cassandra node—note that the server may be a VPN, but what I mean here is that it should only be used for Cassandra.)

Note that in general the newer versions of OpenJDK work with Cassandra. However, Cassandra developers nearly only test with the official Oracle version so it is safer to use that version.

Cassandra

Once you're done installing Java, you may now install Cassandra.

Installing the packages is easy, although just like with Java, we recommend that you install the sources as defined here:

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

In the file add the following two lines (the deb-src is optional, though):

deb http://www.apache.org/dist/cassandra/debian 20x main
deb-src http://www.apache.org/dist/cassandra/debian 20x main

The 20x represents the version of Cassandra you are interested in. At time of writing there is already a version 3, however, Snap was developed with libQtCassandra and there is no guarantee that it would work properly with Cassandra 3.x (not tested yet.)

Just like the Java PPA, you want to add the key. At time of writing the Cassandra key seems to be the following:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 2B5C1B00

Now that you have the key ready, you have to update your database:

sudo apt-get update

Finally, you can install Cassandra with the following command:

sudo apt-get cassandra

Note that Cassandra will immediately get started. However, it will be making use of the default setup which creates a local one node cluster. In order to setup a complete cluster, you will want to edit the Cassandra settings. You may do so with:

sudo vim /etc/cassandra/cassandra.yaml

One of the main setting to be changed in a cluster is the IP address on which your node is running. For example, you may want to change 127.0.0.1 as follow:

listen_address: 10.0.0.1
rpc_address: 10.0.0.1

The other thing to change before you start making use of your cluster, is the endpoint_snitch parameter. Although it is possible to change it at a later time, it requires downtime if you want to do that safely... In most cases:

endpoint_snitch: GossipingPropertyFileSnitch
   -- or --
endpoint_snitch: PropertyFileSnitch

And then edit the cassandra-rackdc.properties or cassandra-topology.properties files to define the Cassandra cluster.

After changes to the Cassandra cluster, make sure to restart the server so the changes are taken in account:

sudo service cassandra restart

Again, the changes to the endpoint_snitch, and probably other parameters, is required before you start creating a context in your Cassandra cluster. If you do not do that in the correct order, you can end up with corrupt data.

There are many other settings under /etc/cassandra. Refer to the Cassandra documentation for more details.

Replication Factor

By default the database keyspace is created with a replication factor of 1. This is because in most cases developers are going to test on their system with a single node.

Once you are ready to add more nodes (remember that we recommend a minimum of 3, although for data safety, 4 should be the minimum.) The replication factor should be around N / 2 with at least 2 and eventually a little more than half until you get more than 10 nodes. At that point you may want to stop increasing the replication factor.

To do that change with CQL, you can use the following command (after starting the command line tool: cqlsh)

ALTER KEYSPACE snap_websites WITH REPLICATION =
        { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };

Make sure to change the count from 2 to whatever you want to use. At some point we will offer the root user a way to change those settings from the Browser, although really there is a problem with that in the fact that you need to also run:

nodetool repair

on each of the affected Cassandra node. It is not exactly trivial.

Upgrades

All of this gives you the ability to do upgrades with the least effort:

sudo apt-get update
sudo apt-get upgrade

Just like with other Ubuntu packages.

Note, however, that major upgrades require some manual work changing the deb sources.

Also, when upgrade to a new release of Ubuntu, the upgrade process is likely to comment out all your special sources. Once the upgrade is done, make sure to verify your sources and re-establish them as required.

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly