Friday, May 24, 2013

Installing Cassandra on Mac OS X

I've recently posted some more tips on using Cassandra on Mac OSX: Cassandra on Mac

If you don't already have homebrew then install it from here.

Then it as simple as:

brew install cassandra

This doesn't install the python driver for the cqlsh command line tool. To do this install it first install python if you haven't got it already:

brew install python

This should have also installed pip - the python package manager - so you can then install the cql python module:

pip install cql

Now try and start cqlsh

You might get this:


Python CQL driver not installed, or not on PYTHONPATH.
You might try "easy_install cql".

One second didn't I just install the cql module?

This could be because the Python in your path is the Mac OS X version. Not the version you installed with home brew that has cql. I fixed this by adding /usr/local/bin to the start of my PATH as that is where the brew Python executable lives:

export PATH=/usr/local/bin/:$PATH

Unless you've started cassandra the next time you try cqlsh you'll get:


cqlsh
Connection error: Could not connect to localhost:9160

Now if you do a brew info on cassandra:

brew info cassandra


To have launchd start cassandra at login:
    ln -sfv /usr/local/opt/cassandra/*.plist ~/Library/LaunchAgents
Then to load cassandra now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.cassandra.plist

Unless you are going to use cassandra a lot I wouldn't set it to load on startup as it does use a reasonable amount of memory. Instead to just start it off:

launchctl load /usr/local/opt/cassandra/homebrew.mxcl.cassandra.plist 

Finally cqlsh should connect to cassandra:



cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 3.0.2 | Cassandra 1.2.5 | CQL spec 3.0.0 | Thrift protocol 19.36.0]
Use HELP for help.
cqlsh> 

Or if you prefer the older cassandra-cli interface to cassandra:


cassandra-cli
Connected to: "Test Cluster" on 127.0.0.1/9160
Welcome to Cassandra CLI version 1.2.5

Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.

[default@unknown


All done.




11 comments:

  1. thanks for your clear & helpful guide :)

    ReplyDelete
  2. Great guide!

    I am running Mavericks. The brew install left the homebrew.mxcl.cassandra.plist file in the /usr/local/Cellar/cassandra/ folder, so I cp it over to ~/Library/LaunchAgents/

    Also, I had to install JDK 7 (JDK, not JRE!) Cassandra won't run on 1.6, which comes with OS X. The failure on 1.6 is pretty nasty -- it loops over and over attempting to start.

    Thanks again!

    Steve


    ReplyDelete
  3. Thanks Steve - When I wrote this it was back on Cassandra 1.2 which did run with 1.6, for 2.* it will need 1.7.

    ReplyDelete
  4. Hi Christopher,
    Fantastic your blog helped.
    Downloaded tar.gz file and followed all the instructions thru other step-by-step but that failed.

    Merry XMAS. Happy Holidays.
    Thanks a lot.

    ReplyDelete
  5. Hi, which version of Cassandra does it install ? I would like to install the community edition, version 3.

    ReplyDelete
  6. Hi all,

    I just found out that one can also use "brew services", which seems to be a nice wrapper around the launchctl stuff:

    brew services start cassandra
    brew services stop cassandra
    brew services restart cassandra

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Hi ,

    cqlsh
    Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})


    Help .

    ReplyDelete
  9. Thank you for the tutorial on installation.. was helpful :)
    cassandra

    ReplyDelete