プログラマでありたい

おっさんになっても、プログラマでありつづけたい

Apache Cassandraのインストール

 ちょこちょこっとCouchDBを触ってみたことがあるのですが、どうやらオープンソースの分散DBはCassandra中心で回りそうなのでそっちを使ってみることにしました。ということで、お約束のインストールメモです。

環境

Cent-OS5.4 (Amazon EC2上のrightscale-us-east/CentOS_5.4_i386_v5.2.0_Alpha.manifest.xml ami-0859bb61)
java version "1.6.0_14" (デフォルトインストール済み)
インストールしたもの
Apache Ant 1.8.0

準備

公式ページからダウンロードできます。
バージョンは、0.6.1を選びました。

ビルドから起動まで

antでビルドする以外、殆ど不要です。
環境にあわせて、confの編集をしてください。

#cd apache-cassandra-0.6.1-src
#ant
 中略
BUILD SUCCESSFUL
# chmod 755 bin/cassandra
# chmod 755 bin/cassandra-cli
# bin/cassandra -f
 INFO 00:36:08,630 Auto DiskAccessMode determined to be standard
 INFO 00:36:09,159 Saved Token not found. Using 71869193890648876842090602795170258475
 INFO 00:36:09,159 Saved ClusterName not found. Using Test Cluster
 INFO 00:36:09,166 Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1271910969166.log
 INFO 00:36:09,232 Starting up server gossip
 INFO 00:36:09,319 Binding thrift service to localhost/127.0.0.1:9160
 INFO 00:36:09,323 Cassandra starting up...

クライアントツールで触ってみます。

# bin/cassandra-cli --host localhost --port 9160
Connected to: "Test Cluster" on localhost/9160
Welcome to cassandra CLI.

Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
cassandra> help
List of all CLI commands:
?                                                                  Same as help.
help                                                          Display this help.
connect <hostname>/<port>                             Connect to thrift service.
describe keyspace <keyspacename>                              Describe keyspace.
exit                                                                   Exit CLI.
quit                                                                   Exit CLI.
show config file                                Display contents of config file.
show cluster name                                          Display cluster name.
show keyspaces                                           Show list of keyspaces.
show api version                                        Show server API version.
get <ksp>.<cf>['<key>']                                  Get a slice of columns.
get <ksp>.<cf>['<key>']['<super>']                   Get a slice of sub columns.
get <ksp>.<cf>['<key>']['<col>']                             Get a column value.
get <ksp>.<cf>['<key>']['<super>']['<col>']              Get a sub column value.
set <ksp>.<cf>['<key>']['<col>'] = '<value>'                       Set a column.
set <ksp>.<cf>['<key>']['<super>']['<col>'] = '<value>'        Set a sub column.
del <ksp>.<cf>['<key>']                                           Delete record.
del <ksp>.<cf>['<key>']['<col>']                                  Delete column.
del <ksp>.<cf>['<key>']['<super>']['<col>']                   Delete sub column.
count <ksp>.<cf>['<key>']                               Count columns in record.
count <ksp>.<cf>['<key>']['<super>']            Count columns in a super column.
cassandra> show keyspaces
Keyspace1
system

cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John'
Value inserted.
cassandra> get Keyspace1.Standard2['jsmith']
=> (column=first, value=John, timestamp=1271911743088000)
Returned 1 results.
cassandra> set Keyspace1.Standard2['jsmith']['last'] = 'Smith'
Value inserted.
cassandra> set Keyspace1.Standard2['jsmith']['age'] = '42'
Value inserted.
cassandra> get Keyspace1.Standard2['jsmith']
=> (column=last, value=Smith, timestamp=1271911770333000)
=> (column=first, value=John, timestamp=1271911743088000)
=> (column=age, value=42, timestamp=1271911776381000)
Returned 3 results.
cassandra> exit

 割と簡単に起動とお試しまで出来ました。
今回はrootで起動しているのですが、ユーザ権限で行う場合は/var/lib/cassandraや/var/log/cassandraを作成して権限を与えておく必要があります。
 また今回はクラスタとか組んでいないですし、Keyspaceの作成とか全然やっていないので、そのうち掘り下げて試してみようかと思います。amazon ec2でクラスタ組む場合は、インナーのアドレスとかがあるのでちょっとややこしいみたいです。


参考:
GettingStarted - Cassandra Wiki
CassandraCli - Cassandra Wiki
johanoskarsson's cassandra-ec2 at master - GitHu