Installing Cassandra in your local machine for experimental or development purposes is as easy as downloading and unzipping the tarball (the .tar
compressed file). For development purposes, Cassandra does not have any extreme requirements. Any modern computer with 1 GB of RAM and a dual core processor is good to test the water. Anything higher than that is great. All the examples in this chapter are done on a laptop with 4 GB of RAM, a dual core processor, and the Ubuntu 13.04 operating system. Cassandra is supported on all major platforms; after all, it's Java. Here are the steps to install Cassandra locally:
Install Oracle Java 1.6 (Java 6) or higher. Installing the JVM is sufficient, but you may need the Java Development Kit (JDK) if you are planning to code in Java.
# Check if you have Java ~$ java -version java version "1.7.0_21" Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
If you do not have Java, you may want to follow the installation details for your machine from the Oracle Java website (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
Download Cassandra 1.1.x version from the Cassandra website, http://archive.apache.org/dist/cassandra/. This book uses Cassandra 1.1.11, which was the latest at the time of writing this book.
Note
By the time you read this book, you might have version 1.2.x or Cassandra 2.0, which have some differences. So, better stick to the 1.1.x version. We will see how to work with later versions and the new stuff that they offer in a later chapter.
Uncompress this file to a suitable directory.
# Download Cassandra $ wget http://archive.apache.org/dist/cassandra/1.1.11/apache-cassandra-1.1.11-bin.tar.gz # Untar to /home/nishant/apps/ $ tar xvzf apache-cassandra-1.1.11-bin.tar.gz -C /home/nishant/apps/
The unzipped file location is
/home/nishant/apps/apache-cassandra-1.1.11
. Let's call this locationCASSANDRA_HOME
. Wherever we refer toCASSANDRA_HOME
in this book, always assume it to be the location where Cassandra is installed.Configure a directory where Cassandra will store all the data. Edit
$CASSANDRA_HOME/conf/cassandra.yaml
.Set a cluster name using the following code:
cluster_name: 'nishant_sandbox'
Set the data directory using the following code:
data_file_directories: - /home/nishant/apps/data/cassandra/data
Set the commit log directory:
commitlog_directory: /home/nishant/apps/data/cassandra/commitlog
Set the saved caches directory:
saved_caches_directory: /home/nishant/apps/data/cassandra/saved_caches
Set the logging location. Edit
$CASSANDRA_HOME/conf/log4j-server.properties
:log4j.appender.R.File=/tmp/cassandra.log
With this, you are ready to start Cassandra. Fire up your shell, and type in $CASSANDRA_HOME/bin/cassandra -f
. In this command, -f
stands for foreground. You can keep viewing the logs and Ctrl + C to shut the server down. If you want to run it in the background, do not use the -f
option. The server is ready when you see Bootstrap/Replace/Move completed! Now serving reads
in the startup log as shown:
$ /home/nishant/apps/apache-cassandra-1.1.11/bin/cassandra -f xss = -ea -javaagent:/home/nishant/apps/apache-cassandra-1.1.11/bin/../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms1024M -Xmx1024M -Xmn200M -XX:+HeapDumpOnOutOfMemoryError -Xss180k INFO 20:16:02,297 Logging initialized [-- snip --] INFO 20:16:08,386 Node localhost/127.0.0.1 state jump to normal INFO 20:16:08,394 Bootstrap/Replace/Move completed! Now serving reads.