http://gihyo.jp/dev/serial/01/cassandra/0002
上記記事は Windows なので Ubuntu でやってみる.
インストール
ダウンロードして展開するだけ……
あと,環境変数も追加
$ cd ~/opt $ wget http://ftp.kddilabs.jp/infosystems/apache/cassandra/0.6.1/apache-cassandra-0.6.1-bin.tar.gz $ tar zxvf apache-cassandra-0.6.1-bin.tar.gz
バージョンアップのためにシンボリックリンクも貼っておく
$ ln -s ~/opt/apache-cassandra-0.6.1 ~/opt/cassandra
環境変数はこんな感じ
export JAVA_HOME=/usr/lib/jvm/java-6-sun/ export CASSANDRA_HOME=/home/yoshiori/opt/cassandra export CASSANDRA_CONF=$CASSANDRA_HOME/conf export CASSANDRA_MAIN=org.apache.cassandra.thrift.CassandraDaemon
$ echo $JAVA_HOME /usr/lib/jvm/java-6-sun/ echo $CASSANDRA_HOME /home/yoshiori/opt/cassandra $ echo $CASSANDRA_CONF /home/yoshiori/opt/cassandra/conf $ echo $CASSANDRA_MAIN org.apache.cassandra.thrift.CassandraDaemon
設定ファイルを書き変える
データとコミットログの出力先を設定
$ emacs ~/opt/cassandra/conf/storage-conf.xml
<CommitLogDirectory>/var/lib/cassandra/commitlog</CommitLogDirectory> <DataFileDirectories> <DataFileDirectory>/var/lib/cassandra/data</DataFileDirectory> </DataFileDirectories>
これを下記のように修正
<CommitLogDirectory>/home/yoshiori/opt/cassandra/commitlog</CommitLogDirectory> <DataFileDirectories> <DataFileDirectory>/home/yoshiori/opt/cassandra/data</DataFileDirectory> </DataFileDirectories>
JMX のポートの書き換え
*nix の場合は cassandra.in.sh に起動引数があるので,それを修正
$ emacs ~/opt/cassandra/bin/cassandra.in.sh
# Arguments to pass to the JVM JVM_OPTS=" \ -ea \ -Xms128M \ -Xmx1G \ -XX:TargetSurvivorRatio=90 \ -XX:+AggressiveOpts \ -XX:+UseParNewGC \ -XX:+UseConcMarkSweepGC \ -XX:+CMSParallelRemarkEnabled \ -XX:+HeapDumpOnOutOfMemoryError \ -XX:SurvivorRatio=128 \ -XX:MaxTenuringThreshold=0 \ -Dcom.sun.management.jmxremote.port=8080 \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false" $ emacs ~/opt/cassandra/bin/cassandra.in.sh
com.sun.management.jmxremote.port を修正
JVM_OPTS=" \ -ea \ -Xms128M \ -Xmx1G \ -XX:TargetSurvivorRatio=90 \ -XX:+AggressiveOpts \ -XX:+UseParNewGC \ -XX:+UseConcMarkSweepGC \ -XX:+CMSParallelRemarkEnabled \ -XX:+HeapDumpOnOutOfMemoryError \ -XX:SurvivorRatio=128 \ -XX:MaxTenuringThreshold=0 \ -Dcom.sun.management.jmxremote.port=9081 \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false" $ emacs ~/opt/cassandra/bin/cassandra.in.sh
以上で設定全部完了
起動してみる
*nix の場合は bin/cassandra で起動できる.
引数に -f を付けると foreground で実行出来るのでテスト時はそれで実行する
$ ./cassandra -f INFO 18:06:42,809 Auto DiskAccessMode determined to be standard INFO 18:06:43,033 Sampling index for /home/yoshiori/opt/cassandra/data/Keyspace1/Standard2-1-Data.db INFO 18:06:43,054 Sampling index for /home/yoshiori/opt/cassandra/data/system/LocationInfo-1-Data.db INFO 18:06:43,057 Replaying /home/yoshiori/opt/cassandra/commitlog/CommitLog-1273049112963.log INFO 18:06:43,084 Creating new commitlog segment /home/yoshiori/opt/cassandra/commitlog/CommitLog-1273050403084.log INFO 18:06:43,100 LocationInfo has reached its threshold; switching in a fresh Memtable at CommitLogContext(file='/home/yoshiori/opt/cassandra/commitlog/CommitLog-1273050403084.log', position=121) INFO 18:06:43,101 Enqueuing flush of Memtable(LocationInfo)@1677625 INFO 18:06:43,105 Writing Memtable(LocationInfo)@1677625 INFO 18:06:43,160 Completed flushing /home/yoshiori/opt/cassandra/data/system/LocationInfo-2-Data.db INFO 18:06:43,167 Log replay complete INFO 18:06:43,198 Saved Token found: 111493218491592662932686463489543037999 INFO 18:06:43,199 Saved ClusterName found: Test Cluster INFO 18:06:43,207 Starting up server gossip INFO 18:06:43,247 Binding thrift service to localhost/127.0.0.1:9160 INFO 18:06:43,251 Cassandra starting up...
わーい!!
起動した!!!