Cassandra Development Environment in Mac OS Snow Leopard
I just started working with Cassandra so I am no expert on the subject, and this post is more about self documentation of what I did to get it working on my laptop, running Snow Leopard, than an expert’s How to guide. If it helps you out all the better, and leave your comments.
Getting Cassandra to run on Mac OSX is very easy just download the latest binary from http://cassandra.apache.org/. At the time of this writing the version was 0.6.3, but I updated the important parts to 0.7rc3 so it should work with that version as well.
Create the directories Cassandra needs to work:
sudo mkdir -p /opt/cassandra
sudo chown -R `whoami` /opt/cassandra
sudo mkdir -p /var/log/cassandra
sudo chown -R `whoami` /var/log/cassandra
sudo touch /var/log/cassandra/system.log
sudo mkdir -p /var/lib/cassandra
sudo chown -R `whoami` /var/lib/cassandra
Get Cassandra and copy it to /opt/cassandra. In this example I used wget. Notice that the version numbers may change so use the correct link for your version from http://cassandra.apache.org/download/
tar xzf apache-cassandra-0.6.3-bin.tar.gz
If all is ok you should now see
INFO 22:01:15,273 Auto DiskAccessMode determined to be mmap
INFO 22:01:15,887 Saved Token not found. Using 114412163776176127313248360017471199843
INFO 22:01:15,888 Saved ClusterName not found. Using Test Cluster
INFO 22:01:15,898 Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1278036075898.log
INFO 22:01:15,937 LocationInfo has reached its threshold; switching in a fresh Memtable at CommitLogContext(file='/var/lib/cassandra/commitlog/CommitLog-1278036075898.log', position=419)
INFO 22:01:15,946 Enqueuing flush of Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:15,954 Writing Memtable-LocationInfo@1373164447(169 bytes, 4 operations)
INFO 22:01:16,262 Completed flushing /var/lib/cassandra/data/system/LocationInfo-1-Data.db
INFO 22:01:16,295 Starting up server gossip
INFO 22:01:16,406 Binding thrift service to localhost/127.0.0.1:9160
INFO 22:01:16,414 Cassandra starting up...
Now lets test Cassandra. Open a new Terminal window, or tab, and:
./cassandra-cli --host localhost --port 9160
Cassandra 0.7rc3 output and testing is a bit different so check with the comments bellow.
At the prompt (for 0.6.x)
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']
(column=age, value=42; timestamp=1249930062801)
(column=first, value=John; timestamp=1249930053103)
(column=last, value=Smith; timestamp=1249930058345)
Returned 3 rows.
If you’re able to get the values out of Keyspace1 all is good and Cassandra is up and running.
If you are installing 0.7 or higher the test Keyspace1 is not loaded automatically and you need to run jconsole to load the “schema”. And go to MBeans -> org.apache.cassandra.service -> StorageService -> Operations -> loadSchemaFromYAML as documented on LiveSchemaUpdates
Please note that jconsole needs to connect to localhost on port 8080, to talk to Cassandra. Do not use the Thrift port 9160.
Now lets install Chiton, a GTK GUI written in Python that will allow us to view the data stored in Cassandra.
git clone git://github.com/driftx/chiton.git
In order to fulfill a Chiton dependecies we also need
- Twisted 8.1.0 or later
- Thrift (latest svn)
- PyGTK 2.14 or later
First download and install Apple’s Xcode if you don’t have it already then, get a PyGTK Mac OS build from http://www.daimi.au.dk/%7Emadsk/files/
Copy PyGTK to /Develper as instructed in the README.txt of the PyGTK package.
- Get simplejson from http://pypi.python.org/pypi/simplejson
- Get Twisted from http://twistedmatrix.com/trac/wiki/Downloads and install the Twisted.mpkg package from the dmg file you just downloaded
- Get Telephus using
git clone git://github.com/driftx/Telephus.git
- Get Thrift using
svn co http://svn.apache.org/repos/asf/thrift/trunk thrift
Now for each of the packages, except Thrift run
sudo python setup.py install
If you want to use Python 2.6 run
sudo python2.6 setup.py install
Compiling thrift. Go to the directory to which you checked out Thrift from the SVN
Because of the time it may take to compile all the updates, you may skip the
port selfupdate and
port upgrade outdated. But if you start getting compilation errors you MUST do them and wait :(
My iMac took 5 hours!!!
sudo port selfupdate
sudo port upgrade outdated
sudo port install boost pkgconfig libevent
cp /opt/local/share/aclocal/pkg.m4 ./aclocal
./configure --with-boost=/opt/local --with-libevent=/opt/local --prefix=/opt/local
sudo make install
thrift --gen py:new_style cassandra.thrift
cp -a ./gen-py/cassandra ~/chiton-temp/
(thank you Rich for the configure details
All we need to do is add the PYTHONPATH to our ~/.profile. Using your favorite editor open ~/.profile and add:
The directories in your PYTHONPATH may be a bit different, but the idea is to add all the directories where all the packages we just installed are located. If you miss one you will get import errors when running chiton-client.
Reconfigure Cassandra to allow the Thrift connections from Chiton, you need to set ThriftFramedTransport to true in cassandra’s storage-conf.xml. In my system
If all is well you should now be able to run chiton-client. Login to localhost on port 9160. Don’t forget to have Cassandra daemon running (cassandra -f).
Since we changed the Thrift access to framed, from now on if you want to use the cassandra-cli don’t forget the –framed command line option. Cassandra 0.6.3 daemon crashes with:
ERROR 23:50:24,264 Uncaught exception in thread Thread[pool-1-thread-5,5,main]
java.lang.OutOfMemoryError: Java heap space
if you don’t use –framed.
Hope this guide helps you get your development machine ready to work with Cassandra.