I’ve been getting increasingly interested in alternative databases of late. With alternative I mean non-relational databases of course.
There are a number of document / key value stores in development at the moment. They include projects like HBase, CouchDB, MongoDB and much more.
What has really grabbed my attention at the moment is Tokyo Cabinet. It’s a fascinating datastore that promises excellent performance along with great data security features like master-master replication.
This post isn’t about the features of Tokyo Cabinet, it’s about getting it installed so you can start playing with it yourself. The Igvita blog has a great write-up about why Tokyo Cabinet is relevant, so head over to Tokyo Cabinet: Beyond Key-Value Store for the juicy details. Once you’re impressed, head back here to install it and start playing!
The latest sources for Tokyo Cabinet at time of writing is 1.4.29 and Tokyo Tyrant is 1.1.31.
First, lets install some build dependencies:
sudo apt-get install checkinstall build-essential libbz2-dev zlib1g-dev libreadline5-dev
$ mkdir /src $ cd /src
We need to install Lua first. Download the sources, extract them and change into the source folder:
$ cd /src$ wget http://www.lua.org/ftp/lua-5.1.4.tar.gz$ tar zxf lua-5.1.4.tar.gz$ cd lua-5.1.4
Now lets compile it.
$ make linux test $ make install
Once that’s done, it should print out something like the following:
Hello world, from Lua 5.1!
Now we download and compile Tokyo Cabinet (latest version at time of writing is 1.4.29):
$ cd /src $ wget http://tokyocabinet.sourceforge.net/tokyocabinet-1.4.29.tar.gz $ tar xvf tokyocabinet-1.4.29.tar.gz $ cd tokyocabinet-1.4.29 $ ./configure; make; make install
Next up is Tokyo Tyrant (latest version at time of writing is 1.1.31):
$ cd /src $ wget http://tokyocabinet.sourceforge.net/tyrantpkg/tokyotyrant-1.1.31.tar.gz $ tar xvf tokyotyrant-1.1.31.tar.gz $ cd tokyotyrant-1.1.31 $ ./configure --enable-lua; make; make install
To test that Tokyo Tyrant is installed and working, type the following:
You should see something like the following:
2009-07-15T09:57:06-06:00 SYSTEM --------- logging started  -------- 2009-07-15T09:57:06-06:00 SYSTEM server configuration: host=(any) port=1978 2009-07-15T09:57:06-06:00 SYSTEM opening the database: * 2009-07-15T09:57:06-06:00 SYSTEM service started: 5469 2009-07-15T09:57:06-06:00 INFO timer thread 1 started 2009-07-15T09:57:06-06:00 INFO worker thread 1 started 2009-07-15T09:57:06-06:00 INFO worker thread 2 started 2009-07-15T09:57:06-06:00 INFO worker thread 3 started 2009-07-15T09:57:06-06:00 INFO worker thread 4 started 2009-07-15T09:57:06-06:00 INFO worker thread 5 started 2009-07-15T09:57:06-06:00 INFO worker thread 6 started 2009-07-15T09:57:06-06:00 INFO worker thread 7 started 2009-07-15T09:57:06-06:00 INFO worker thread 8 started 2009-07-15T09:57:06-06:00 SYSTEM listening started
To end the server, simply press Ctrl-C.
Of course, chances are you want the Tyrant server to start on bootup. To do this, we copy the ttservctl script to the /etc/init.d/ directory, make it executable and tell Ubuntu to start it at boot time:
$ cp /usr/local/sbin/ttservctl /etc/init.d $ chmod +x /etc/init.d/ttservctl $ update-rc.d myscript start 51 S .
Don’t forget the dot at the end of that last line.
You can now also use /etc/init.d/ttservctl/ to stop, start and restart the service.
Start the server:
Stop the server:
Restart the server:
Now that you have it installed, you can connect to it and use it with one of the available language bindings. Currently there are Ruby, Python, Perl and Java interfaces available. See the Tokyo Cabinet page for more details on using those.