NoSQL Zone is brought to you in partnership with:

A computer science undergraduate at University of Colombo. Pavithra is a DZone MVB and is not an employee of DZone and has posted 16 posts at DZone. You can read more from them at their website. View Full User Profile

Installing Apache Cassandra on Ubuntu

08.07.2012
| 31567 views |
  • submit to reddit
Apache Cassandra is a distributed, extremely scalable, highly available and fault tolerant NoSQL database initiated by facebook, later open sourced as an apache project. Cassandra data model is inspired by Google Bigtable and it's distribution model is inspired by Amazon Dynamo. If you are interested to know more about Cassandra you can refer to the paper written by Facebook.

This post will guide you how to install Cassandra on Ubuntu 12.04.
  1. Install the new updates using following commands
        sudo apt-get update  
        sudo apt-get upgrade  
  2. open /etc/apt/sources.list using the following command
    1. sudo gedit /etc/apt/sources.list  
    and add the following lines to it
        deb http://www.apache.org/dist/cassandra/debian 10x main  
        deb-src http://www.apache.org/dist/cassandra/debian 10x main  
  3. Run update again and you will get the following error. This means you need to add the PUBLIC_KEY. In next step you will understand how to add this PUBLIC_KEY.
    1.     GPG error: http://www.apache.org unstable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4BD736A82B5C1B00  
  4. Register and add a PUBLIC_KEY key and update again, note that you may need to change the key accordingly
        gpg --keyserver wwwkeys.pgp.net --recv-keys 4BD736A82B5C1B00  
        sudo apt-key add ~/.gnupg/pubring.gpg  
        sudo apt-get update  
  5. Install Cassandra using the following command
    1.     sudo apt-get install cassandra  
  6. Start Cassandra server using the following command
    1.     sudo cassandra -f  
    After starting the Cassandra server you will see it has started listening for thrift clients.
        ....  
        ....  
        ....  
        INFO 12:18:29,140 Listening for thrift clients...  
  7. To stop Cassandra server process first find the Process ID for Cassandra and kill it.

    To find the process ID use following command
    1.     ps auwx | grep cassandra  
    Output will be something like this. According to that 3595 is the process ID for cassandra.
    1.     root      3595  0.0  0.0  60048  1908 pts/0    S+   12:18   0:00 sudo cassandra -f  
    To kill the process use the following command
    1.     sudo kill [pid]
    After killing the process you will see Cassandra server has stopped listening to thrift clients.
    INFO 13:04:08,663 Stop listening to thrift clients  
    INFO 13:04:08,666 Waiting for messaging service to quiesce  
    INFO 13:04:08,667 MessagingService shutting down server thread.
  8. Use following command to start Cassandra as a service
    1.     sudo /etc/init.d/cassandra start  
  9. Use following command to stop Cassandra service
    1.     sudo /etc/init.d/cassandra stop  
Installation will create following directories. Uses of them are mentioned within the brackets.
  • /var/lib/cassandra (data directories)
  • /var/log/cassandra (log directory)
  • /var/run/cassandra (runtime files)
  • /usr/share/cassandra (environment settings)
  • /usr/share/cassandra/lib (JAR files)
  • /usr/bin (binary files)
  • /usr/sbin
  • /etc/cassandra (configuration files)
  • /etc/init.d (service startup script)
  • /etc/security/limits.d (cassandra user limits)
  • /etc/default
Installing JNA (Java Native Access) on Linux platforms can improve Cassandra memory usage. To install JNA, download jna.jar from here and add it to /usr/share/cassandra/lib directory.

If you get the following error while you try to start a Cassandra server, means that cassandra is already running in the background somewhere. You will need to kill the process that is running in the background first. You can probably use the above mentioned stop command to stop any Cassandra servers running background. view plainprint?
  1. Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is:   
  2.  java.net.BindException: Address already in use  
Here I have done the packaged installation, alternatively you can install Cassandra binary tarball installation on Ubuntu. Use this link for that.

References

Official Package To Install On Debian(tm) (not a product of Debian(tm))
Published at DZone with permission of Pavithra Gunasekara, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Dean Schulze replied on Sat, 2012/11/10 - 11:53am

This doesn't work on Ubuntu.  It throws this Exception on startup:

FileNotFoundException: /var/log/cassandra/system.log (Permission denied)I've done the following but still get the Exception:

sudo chown -R cassandra: /var/lib/cassandra

sudo chown -R cassandra: /var/log/cassandra

but still get the same error.


Dean Schulze replied on Sat, 2012/11/10 - 12:04pm in response to: Dean Schulze

What finally allowed it to run was the following:

sudo chmod -R 777 /var/lib/cassandra

sudo chmod -R 777 /var/log/cassandra

That opens up those directories too much but 755 doesn't wok.  The packaging is broken for Ubuntu.



Sergio Viera replied on Fri, 2013/05/10 - 7:23am

Great post!

Just a little correction:

To find the process ID use following command

ps aux | grep cassandra

instead

ps auwx | grep cassandra

Mark Araj replied on Sat, 2014/03/08 - 6:30pm

Ran into this error : 

http://mail-archives.apache.org/mod_mbox/incubator-cassandra-user/201307.mbox/%3CCAAwnuDuw1uXMtjbT_u4TArMhvgEpU_NWZ-wRbBUaPWKkDcrvxw@mail.gmail.com%3E

Sounds like the issue hasn't been fixed for a while now, unless I should be looking somewhere else. I think it will have to be manual installation for now ! 

Edit - This should fix the above issue - basically get the latest version -

http://wiki.apache.org/cassandra/DebianPackaging

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.