SSブログ

Cassandra 3.9 をさわってみる [プログラミング]

まず java8 をインストールする
あと python という名前のコマンドで python2.7 がインストールされている必要がある

binary tarball file を使うことにする
http://cassandra.apache.org/doc/latest/getting_started/installing.html#installation-from-binary-tarball-files
cassandra の最新が 3.9 のようなので apache-cassandra-3.9-bin.tar.gz をダウンロードしてきて
$ tar zxvf apache-cassandra-3.9-bin.tar.gz
で展開。
展開したディレクトリの中の bin ディレクトリにパスを通す。
自分の場合は、
export PATH="$PATH:$HOME/apache-cassandra-3.9/bin"
みたいな感じにした。

これで
$ cassandra
でサーバー実行
$ cqlsh
でコマンドシェル実行できた
$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.9 | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh>

使い方は↓ここら辺が参考になった
http://symfoware.blog68.fc2.com/blog-entry-1917.html

以下、自分が実行した例
cqlsh> create keyspace sample WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};
cqlsh> DESCRIBE keyspaces;

system_schema  system_auth  system  sample  system_distributed  system_traces

cqlsh> use sample;
cqlsh:sample> create table test (
          ...     id int,
          ...     s text,
          ...     primary key(id)
          ... );
cqlsh:sample> describe tables;

test

cqlsh:sample> INSERT INTO test (id, s) VALUES (1, 'test1');
cqlsh:sample> INSERT INTO test (id, s) VALUES (2, 'test2');
cqlsh:sample> SELECT * FROM test;

 id | s
----+-------
  1 | test1
  2 | test2

(2 rows)
cqlsh:sample>



(追記)

cqlsh は、 python 製の pip でインストールできるコマンドなので
ダウンロードした tarball の じゃなくても

sudo pip install cqlsh

でインストールできる。

macOS Sierra の場合
$ sudo easy_install -U six
で、システムの python 2.7 の six をアップグレードしないとダメかも


この /usr/local/bin/cqlsh にインストールされるコマンドを実行しても良い・・・はずなのだが

$ cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': ProtocolError("cql_version '3.3.1' is not supported by remote (w/ native protocol). Supported versions: [u'3.4.2']",)})

エラーで接続できない。クライアントの要求する CQL バージョンの方を
サーバーが受け付けられないということらしい

$ cqlsh --cqlversion=3.4.2

って指定するとエラーにならないんだけどいいのかな?

~/.cassandra/cqlshrc に
[cql]
version = 3.4.2

と書いても同じらしい
コメント(0)  トラックバック(0) 
共通テーマ:日記・雑感

コメント 0

コメントの受付は締め切りました

Facebook コメント

トラックバック 0