Pages

Sunday, October 13, 2013

Step by step guide to setup Cassandra and cqlsh in windows

Today I started to play with Cassandra by installing it in my windows machine. Though the instructions in the cassandra download site is clear and precise, I faced few issues in setting it up. So I thought of sharing the information for fellow developers.

Step 1: Download Cassandra from http://cassandra.apache.org/download/. The current latest version is 2.0.1. It is a tar.gz file. Download and extract it in some location in your machine. For example C:\3\apache-cassandra-2.0.1

Step 2: You can start cassandra server by calling cassandra.bat available with in the bin directory. It should startup the Cassandra server (Note: You should have Java home environment variable set to start the server)

Step 3: Now to interact with Cassandra database you need the cqlsh interactive command tool. Here is the small twist. There is none in the cassandra download package. So there is a work around we should do before adding records to the database.

3a) Download python from the below location http://www.python.org/download/releases/. Be careful here. Though the python latest version is 3.x, there is problem with installing thrift library with the latest version of Python. So download and install 2.7 version of Python.
3b) Install Thrift library by downloading it from the below location http://pypi.python.org/pypi/thrift. Install thrift module by executing the below command python setup.py install

If the python version not supported you may get this error . Revert back to version 2.7.x version of Python and then it should run like a charm

Step 4 : Now you should install cql module for python which is available with in cassandra download.  The setup.py file is available in the below location C:\3\apache-cassandra-2.0.1\pylib. Again run the command python setup.py install. 

Step 5:  Now you can run the command python cqlsh localhost 9160 and it will start the cql interactive command.  Here you can start issuing the commands llike keyspace creation etc.

CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

CREATE TABLE users (user_id int PRIMARY KEY,  fname text,  lname text);

INSERT INTO users (user_id,  fname, lname) VALUES (1745, 'john', 'smith');
INSERT INTO users (user_id,  fname, lname)  VALUES (1744, 'john', 'doe');
INSERT INTO users (user_id,  fname, lname)  VALUES (1746, 'john', 'smith');


6 comments:

  1. Windows is fine. Is someone iterestet to use it on linux look up here: http://alexander.holbreich.org/2013/10/installing-apache-cassandra/

    ReplyDelete
  2. I get a connection error could not connect to localhost:9160

    ReplyDelete
  3. Okay, the problem was solved. I could not start cassandra due to the bloody UAC. Restarted it with admin rights, and it was able to connect to 9160 and I was able to make keyspaces using cmd. Thanks!

    ReplyDelete
  4. unable to execute CQL script :unconfigured columnfamily

    ReplyDelete
  5. getting error _main_ module not found in cqlshlib

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete

 
Blogger Templates