vrijdag 26 maart 2010

Installing Cassandra on CentOS

Cassandra is an interesting distributed database system based on the ideas of Bigtable and Dynamo. So let's give it a try. We will make a single node setup for now.

The installation of Cassandra on CentOS is not that complicated, but there are some small things you need to know to get it working.

First of all Java needs to be installed to run Cassandra, as it is completely writen in Java. Installing Java with yum is quite easy, just enter:

# yum install java-1.6.0-openjdk.i386 (for 32-bit systems)
# yum install java-1.6.0-openjdk.x86_64 (for 64-bit systems)

Next download the latest binary from the the Cassandra website:

Unless you are setting up a production server, you can go for the beta release. An example of the download command:

# wget http://apache.ziply.com/cassandra/0.6.0/apache-cassandra-0.6.0-beta3-bin.tar.gz
(change the url to the latest version)

Now we need to uncompress the downloaded file:
tar -zxvf apache-cassandra-0.6.0-beta3-bin.tar.gz
(change the file name if you have a newer version of Cassandra)

Unfortunately the 0.6.0 release doesn't come with all dependencies, so we will need to install them manually:

* Log4J (download), from the archive copy the log4j-x.x.x.jar file into the /lib folder of Cassandra
* Google Collections (download), from the archive copy the google-collect.x.x.jar into the /lib folder of Cassandra
* Apache Commons Collections (download), from the archive copy the commons-collections-x.x.x.jar into the /lib folder of Cassandra
* Apache Commons Lang (download), from the archive copy the commons-lang-x.x.jar into the /lib folder of Cassandra
* SLF4J (download), from the archive copy the slf4j-api-x.x.x.jar and slf4j-log4jxx-x.x.x.jar into the /lib folder of Cassandra
* Apache Commons CLI (download), from the archive copy the commons-cli-x.x.jar into the /lib folder of Cassandra
* jLine (download), from the archive copy the jline-x.x.xx.jar into the /lib folder of Cassandra

Now we need to make some directories required by Cassandra:
# sudo mkdir -p /var/log/cassandra
# sudo mkdir -p /var/lib/cassandra

Last before starting it up, we have to check the config file:
# joe conf/storage-conf.xml (you can use another editor than joe if you like)

In the config file make sure that all paths mentioned exist, and fill the correct ip addresses where needed.

That should be all and we can now start Cassandra:
# bin/cassandra -f

And to see if it really works (assuming you don't seen any ugly error messages):
# bin/cassandra-cli --host localhost --port 9160

This start the client and we can try some commands:

cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John'
cassandra> set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
cassandra> set Keyspace1.Standard2['jsmith']['age'] = '42'
cassandra> get Keyspace1.Standard2['jsmith']

After this you should see the results of the records inserted being shown back from the database.

2 opmerkingen:

socalspiders zei

Thank you for your article.
Just a quick note: on the 0.7 beta1 the dependencies are included.
The only thing I had to do was to yum install which - missing on my system
Again. Thank you for your help :)

squall192 zei

muchas gracias por el articulo, me ha servido mucho.