[NoSQL]Cassandra入門② – Cassandraのインストールと起動・停止

Facebook にシェア
このエントリーをはてなブックマークに追加
[`livedoor` not found]
LinkedIn にシェア
[`evernote` not found]
GREE にシェア
LINEで送る

Cassandraのセットアップ

まずCassandraのダウンロードを以下のサイトから行います。
The Apache Cassandra Projecrt

2013/6/15時点の最新モジュールは以下のリンクからダウンロード可能です。
こちら

以下は/opt/local下にインストールする手順となります。まず、/tmp下にダウンロードしたモジュールを配置してください。

$ cd /tmp
$ mkdir -p /opt/local
$ gzip -dc apache-cassandra-1.2.5-bin.tar.gz | tar xvf -
$ mv apache-cassandra-1.2.5 apache-cassandra
$ cd /opt/local
$ ln -s apache-cassandra-1.2.5 apache-cassandra

ポイントこれで、配置は完了です。最新バージョンへのUpdateが容易にできるように、シンボリックリンクでapache-cassandra-1.2.5へリンクさせています。

ロギング用のディレクトリ作成を行います。

$ mkdir -p /var/lib/cassandra/commitlog
$ mkdir -p /var/lib/cassandra/data
$ mkdir -p /var/log/cassandra
$ chown -R `whoami` /var/lib/cassandra
$ chwon -R `whoami` /var/log/cassandra

Cassandのクラスパス設定

以下の通り、2つの変数をエクスポートします。

$ vi ~/.bashrc
export CASSANDRA_HOME="/opt/local/apache-cassandra"
export CASSANDRA_CONF="$CASSANDRA_HOME/conf"

Cassandの起動(フォアグラウンド)

$ /opt/local/apache-cassandra/bin/cassandra -f
xss = -ea -javaagent:./bin/../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms501M -Xmx501M -Xmn125M -XX:+HeapDumpOnOutOfMemoryError -Xss180k
INFO 18:38:40,430 Logging initialized
INFO 18:38:40,444 JVM vendor/version: Java HotSpot(TM) 64-Bit Server VM/1.6.0_25
ERROR 18:38:40,447 Your JVM is out of date. Please upgrade to the newest Oracle Java 6.
INFO 18:38:40,447 Heap size: 512229376/513277952
INFO 18:38:40,448 Classpath: ./bin/../conf:./bin/../build/classes/main:./bin/../build/classes/thrift:./bin/../lib/antlr-3.2.jar:./bin/../lib/apache-cassandra-1.2.5.jar:./bin/../lib/apache-cassandra-clientutil-1.2.5.jar:./bin/../lib/apache-cassandra-thrift-1.2.5.jar:./bin/../lib/avro-1.4.0-fixes.jar:./bin/../lib/avro-1.4.0-sources-fixes.jar:./bin/../lib/commons-cli-1.1.jar:./bin/../lib/commons-codec-1.2.jar:./bin/../lib/commons-lang-2.6.jar:./bin/../lib/compress-lzf-0.8.4.jar:./bin/../lib/concurrentlinkedhashmap-lru-1.3.jar:./bin/../lib/guava-13.0.1.jar:./bin/../lib/high-scale-lib-1.1.2.jar:./bin/../lib/jackson-core-asl-1.9.2.jar:./bin/../lib/jackson-mapper-asl-1.9.2.jar:./bin/../lib/jamm-0.2.5.jar:./bin/../lib/jbcrypt-0.3m.jar:./bin/../lib/jline-1.0.jar:./bin/../lib/json-simple-1.1.jar:./bin/../lib/libthrift-0.7.0.jar:./bin/../lib/log4j-1.2.16.jar:./bin/../lib/lz4-1.1.0.jar:./bin/../lib/metrics-core-2.0.3.jar:./bin/../lib/netty-3.5.9.Final.jar:./bin/../lib/servlet-api-2.5-20081211.jar:./bin/../lib/slf4j-api-1.7.2.jar:./bin/../lib/slf4j-log4j12-1.7.2.jar:./bin/../lib/snakeyaml-1.6.jar:./bin/../lib/snappy-java-1.0.4.1.jar:./bin/../lib/snaptree-0.1.jar:./bin/../lib/jamm-0.2.5.jar
INFO 18:38:40,450 JNA not found. Native methods will be disabled.
INFO 18:38:40,462 Loading settings from file:/opt/local/apache-cassandra-1.2.5/conf/cassandra.yaml
INFO 18:38:40,860 Data files directories: [/var/lib/cassandra/data]
INFO 18:38:40,860 Commit log directory: /var/lib/cassandra/commitlog
INFO 18:38:40,861 DiskAccessMode 'auto' determined to be mmap, indexAccessMode is mmap
INFO 18:38:40,861 disk_failure_policy is stop
INFO 18:38:40,867 Global memtable threshold is enabled at 163MB
INFO 18:38:41,014 Not using multi-threaded compaction
INFO 18:38:41,546 Initializing key cache with capacity of 24 MBs.
INFO 18:38:41,559 Scheduling key cache save to each 14400 seconds (going to save all keys).
INFO 18:38:41,560 Initializing row cache with capacity of 0 MBs and provider org.apache.cassandra.cache.SerializingCacheProvider
INFO 18:38:41,572 Scheduling row cache save to each 0 seconds (going to save all keys).
INFO 18:38:42,069 Couldn't detect any schema definitions in local storage.
INFO 18:38:42,070 To create keyspaces and column families, see 'help create keyspace' in the CLI, or set up a schema using the thrift system_* calls.
INFO 18:38:42,176 No commitlog files found; skipping replay
INFO 18:38:42,445 Cassandra version: 1.2.5
INFO 18:38:42,445 Thrift API version: 19.36.0
INFO 18:38:42,446 CQL supported versions: 2.0.0,3.0.3 (default: 3.0.3)
INFO 18:38:42,485 Loading persisted ring state
INFO 18:38:42,489 Starting up server gossip
WARN 18:38:42,495 No host ID found, created 15bc5418-8502-4bda-a3ad-0ce2849358d2 (Note: This should happen exactly once per node).
INFO 18:38:42,511 Enqueuing flush of Memtable-local@954564833(361/361 serialized/live bytes, 15 ops)
INFO 18:38:42,514 Writing Memtable-local@954564833(361/361 serialized/live bytes, 15 ops)
INFO 18:38:42,590 Completed flushing /var/lib/cassandra/data/system/local/system-local-ic-1-Data.db (353 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=50413)
INFO 18:38:42,689 Starting Messaging Service on port 7000
WARN 18:38:42,754 Generated random token [-7233050428828279550]. Random tokens will result in an unbalanced ring; see http://wiki.apache.org/cassandra/Operations
INFO 18:38:42,755 Enqueuing flush of Memtable-local@1443443454(84/84 serialized/live bytes, 4 ops)
INFO 18:38:42,756 Writing Memtable-local@1443443454(84/84 serialized/live bytes, 4 ops)
INFO 18:38:42,773 Completed flushing /var/lib/cassandra/data/system/local/system-local-ic-2-Data.db (120 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=50688)
INFO 18:38:42,783 Enqueuing flush of Memtable-local@747621499(51/51 serialized/live bytes, 2 ops)
INFO 18:38:42,784 Writing Memtable-local@747621499(51/51 serialized/live bytes, 2 ops)
INFO 18:38:42,797 Completed flushing /var/lib/cassandra/data/system/local/system-local-ic-3-Data.db (110 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=50863)
INFO 18:38:42,815 Node localhost/127.0.0.1 state jump to normal
INFO 18:38:42,817 Startup completed! Now serving reads.
INFO 18:38:42,819 Create new Keyspace: system_auth, rep strategy:SimpleStrategy{}, strategy_options: {replication_factor=1}, durable_writes: true
INFO 18:38:42,865 Enqueuing flush of Memtable-schema_keyspaces@1498906841(389/389 serialized/live bytes, 11 ops)
INFO 18:38:42,867 Writing Memtable-schema_keyspaces@1498906841(389/389 serialized/live bytes, 11 ops)
INFO 18:38:42,879 Completed flushing /var/lib/cassandra/data/system/schema_keyspaces/system-schema_keyspaces-ic-1-Data.db (260 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=51104)
INFO 18:38:42,880 Enqueuing flush of Memtable-schema_columnfamilies@1147066451(21775/21775 serialized/live bytes, 352 ops)
INFO 18:38:42,881 Writing Memtable-schema_columnfamilies@1147066451(21775/21775 serialized/live bytes, 352 ops)
INFO 18:38:42,909 Completed flushing /var/lib/cassandra/data/system/schema_columnfamilies/system-schema_columnfamilies-ic-1-Data.db (4474 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=51104)
INFO 18:38:42,911 Enqueuing flush of Memtable-schema_columns@163450945(21903/21903 serialized/live bytes, 332 ops)
INFO 18:38:42,912 Writing Memtable-schema_columns@163450945(21903/21903 serialized/live bytes, 332 ops)
INFO 18:38:42,939 Completed flushing /var/lib/cassandra/data/system/schema_columns/system-schema_columns-ic-1-Data.db (3772 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=51104)
INFO 18:38:43,106 Create new ColumnFamily: org.apache.cassandra.config.CFMetaData@2fbef1ac[cfId=473588ad-9c79-38be-8b59-e06c10456ba0,ksName=system_auth,cfName=users,cfType=Standard,comparator=org.apache.cassandra.db.marshal.CompositeType(org.apache.cassandra.db.marshal.UTF8Type),subcolumncomparator=<null>,comment=,readRepairChance=0.1,dclocalReadRepairChance=0.0,replicateOnWrite=true,gcGraceSeconds=7776000,defaultValidator=org.apache.cassandra.db.marshal.BytesType,keyValidator=org.apache.cassandra.db.marshal.UTF8Type,minCompactionThreshold=4,maxCompactionThreshold=32,keyAliases=[java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]],columnAliases=[],valueAlias=<null>,column_metadata={java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]=ColumnDefinition{name=7375706572, validator=org.apache.cassandra.db.marshal.BooleanType, index_type=null, index_name='null', component_index=0}},compactionStrategyClass=class org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy,compactionStrategyOptions={},compressionOptions={sstable_compression=org.apache.cassandra.io.compress.SnappyCompressor},bloomFilterFpChance=0.01,caching=KEYS_ONLY,populateIoCacheOnFlush=false]
INFO 18:38:43,126 Enqueuing flush of Memtable-schema_columnfamilies@26362458(1097/1097 serialized/live bytes, 20 ops)
INFO 18:38:43,127 Writing Memtable-schema_columnfamilies@26362458(1097/1097 serialized/live bytes, 20 ops)
INFO 18:38:43,137 Completed flushing /var/lib/cassandra/data/system/schema_columnfamilies/system-schema_columnfamilies-ic-2-Data.db (698 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=52888)
INFO 18:38:43,138 Enqueuing flush of Memtable-schema_columns@1226090823(251/251 serialized/live bytes, 5 ops)
INFO 18:38:43,139 Writing Memtable-schema_columns@1226090823(251/251 serialized/live bytes, 5 ops)
INFO 18:38:43,152 Completed flushing /var/lib/cassandra/data/system/schema_columns/system-schema_columns-ic-2-Data.db (209 bytes) for commitlog position ReplayPosition(segmentId=1371289121990, position=52888)
INFO 18:38:43,314 Starting listening for CQL clients on localhost/127.0.0.1:9042...
INFO 18:38:43,334 Binding thrift service to localhost/127.0.0.1:9160
INFO 18:38:43,377 Using TFramedTransport with a max frame size of 15728640 bytes.
INFO 18:38:43,386 Using synchronous/threadpool thrift server on localhost : 9160
INFO 18:38:43,386 Listening for thrift clients...

(停止)Ctrl + C

INFO 18:40:50,458 Stop listening to thrift clients
INFO 18:40:50,476 Stop listening for CQL clients
INFO 18:40:50,481 Announcing shutdown
INFO 18:40:52,487 Waiting for messaging service to quiesce
INFO 18:40:52,489 MessagingService shutting down server thread.

Cassandの起動(バックグラウンド)

まず、/etc/init.d下に起動スクリプトを作成します。

$ touch /etc/init.d/cassandra
$ chmod 755 /etc/init.d/cassandra
$ vi /etc/init.d/cassandra

起動スクリプトは以下のとおりです。

# description: cassandra
# processname: cassandra
#!/bin/sh

CASSANDRA_BIN=/opt/local/apache-cassandra/bin/cassandra
CASSANDRA_PID=/var/run/cassandra.pid

case "$1" in
  start)
     $CASSANDRA_BIN -p $CASSANDRA_PID
     echo "Running Cassandra"
     ;;
  stop)
     kill `cat $CASSANDRA_PID`
     rm -f $CASSANDRA_PID
     echo "Stopped Cassandra"
     ;;
  status)
     ls $CASSANDRA_PID >/dev/null 2>&1
     case "$?" in
       0)
         echo "Running Cassandra"
         ;;
       2)
         echo "Stopped Cassandra"
         ;;
       *)
         echo "Unknow status Cassandra"
         exit 1
     esac
     ;;
  *)
     echo "Usage: $0 {start|stop|status}"
     exit 1
esac
exit 0

起動テスト・停止テスト

$ /etc/init.d/cassandra start
$/etc/init.d/cassandra status
 Running Cassandra
$ ps -ef | grep cassandra
 root     20745     1  7 14:52 pts/0    00:00:03 /usr/java/default/bin/java -ea -javaagent:/opt/local/apache-cassandra/bin/../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms501M -Xmx501M -Xmn125M -XX:+HeapDumpOnOutOfMemoryError -Xss180k -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:SurvivorRatio=8 -XX:MaxTenuringThreshold=1 -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseTLAB -Djava.net.preferIPv4Stack=true -Dcom.sun.management.jmxremote.port=7199 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dlog4j.configuration=log4j-server.properties -Dlog4j.defaultInitOverride=true -Dcassandra-pidfile=/var/run/cassandra.pid -cp /opt/local/apache-cassandra/bin/../conf:/opt/local/apache-cassandra/bin/../build/classes/main:/opt/local/apache-cassandra/bin/../build/classes/thrift:/opt/local/apache-cassandra/bin/../lib/antlr-3.2.jar:/opt/local/apache-cassandra/bin/../lib/apache-cassandra-1.2.5.jar:/opt/local/apache-cassandra/bin/../lib/apache-cassandra-clientutil-1.2.5.jar:/opt/local/apache-cassandra/bin/../lib/apache-cassandra-thrift-1.2.5.jar:/opt/local/apache-cassandra/bin/../lib/avro-1.4.0-fixes.jar:/opt/local/apache-cassandra/bin/../lib/avro-1.4.0-sources-fixes.jar:/opt/local/apache-cassandra/bin/../lib/commons-cli-1.1.jar:/opt/local/apache-cassandra/bin/../lib/commons-codec-1.2.jar:/opt/local/apache-cassandra/bin/../lib/commons-lang-2.6.jar:/opt/local/apache-cassandra/bin/../lib/compress-lzf-0.8.4.jar:/opt/local/apache-cassandra/bin/../lib/concurrentlinkedhashmap-lru-1.3.jar:/opt/local/apache-cassandra/bin/../lib/guava-13.0.1.jar:/opt/local/apache-cassandra/bin/../lib/high-scale-lib-1.1.2.jar:/opt/local/apache-cassandra/bin/../lib/jackson-core-asl-1.9.2.jar:/opt/local/apache-cassandra/bin/../lib/jackson-mapper-asl-1.9.2.jar:/opt/local/apache-cassandra/bin/../lib/jamm-0.2.5.jar:/opt/local/apache-cassandra/bin/../lib/jbcrypt-0.3m.jar:/opt/local/apache-cassandra/bin/../lib/jline-1.0.jar:/opt/local/apache-cassandra/bin/../lib/json-simple-1.1.jar:/opt/local/apache-cassandra/bin/../lib/libthrift-0.7.0.jar:/opt/local/apache-cassandra/bin/../lib/log4j-1.2.16.jar:/opt/local/apache-cassandra/bin/../lib/lz4-1.1.0.jar:/opt/local/apache-cassandra/bin/../lib/metrics-core-2.0.3.jar:/opt/local/apache-cassandra/bin/../lib/netty-3.5.9.Final.jar:/opt/local/apache-cassandra/bin/../lib/servlet-api-2.5-20081211.jar:/opt/local/apache-cassandra/bin/../lib/slf4j-api-1.7.2.jar:/opt/local/apache-cassandra/bin/../lib/slf4j-log4j12-1.7.2.jar:/opt/local/apache-cassandra/bin/../lib/snakeyaml-1.6.jar:/opt/local/apache-cassandra/bin/../lib/snappy-java-1.0.4.1.jar:/opt/local/apache-cassandra/bin/../lib/snaptree-0.1.jar org.apache.cassandra.service.CassandraDaemon
$ /etc/init.d/cassandra stop
 Stopped Cassandra
$ /etc/init.d/cassandra status
 Stopped Cassandra

必要に応じてサービスにも登録してください。(ここでは割愛します。)

コメントを残す