LoginSignup
3
3

More than 5 years have passed since last update.

cassandraセットアップメモ

Last updated at Posted at 2018-09-30

概要

vagrantで起動したcentos6にcassandra3系をセットアップしたメモ。
以下を参考にしました。
https://wiki.apache.org/cassandra/GettingStarted_JP

準備

jdk8をインストール

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
自分の環境にはすでに入っていたのでスキップ。

❯ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)

cassandraを取得

以下から取得
http://www.apache.org/dyn/closer.lua/cassandra/3.11.1/apache-cassandra-3.11.1-bin.tar.gz

❯ wget http://archive.apache.org/dist/cassandra/3.11.1/apache-cassandra-3.11.1-bin.tar.gz

解凍

❯ tar xzvf apache-cassandra-3.11.1-bin.tar.gz
apache-cassandra-3.11.1/bin/
apache-cassandra-3.11.1/conf/
apache-cassandra-3.11.1/conf/triggers/
...

❯ cd apache-cassandra-3.11.1

~/apache-cassandra-3.11.1 localhost.localdomain
❯ ll
合計 488K
drwxr-xr-x. 2 vagrant vagrant 4.0K 10月  1 01:10 bin
drwxr-xr-x. 3 vagrant vagrant 4.0K 10月  1 01:10 conf
drwxr-xr-x. 4 vagrant vagrant   45 10月  1 01:10 doc
drwxr-xr-x. 2 vagrant vagrant   30 10月  1 01:10 interface
drwxr-xr-x. 3 vagrant vagrant 4.0K 10月  1 01:10 javadoc
drwxr-xr-x. 4 vagrant vagrant 4.0K 10月  1 01:10 lib
drwxr-xr-x. 3 vagrant vagrant   38 10月  1 01:10 pylib
drwxr-xr-x. 4 vagrant vagrant  135 10月  1 01:10 tools
-rw-r--r--. 1 vagrant vagrant 347K 10月  3  2017 CHANGES.txt
-rw-r--r--. 1 vagrant vagrant  12K 10月  3  2017 LICENSE.txt
-rw-r--r--. 1 vagrant vagrant 105K 10月  3  2017 NEWS.txt
-rw-r--r--. 1 vagrant vagrant 2.8K 10月  3  2017 NOTICE.txt

起動

~/apache-cassandra-3.11.1 localhost.localdomain
❯ bin/cassandra -f
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
...

接続

cqlshでcassandraインスタンスに接続

❯ bin/cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

使ってみる

キースペース作成

cqlsh> CREATE KEYSPACE mykeyspace
   ... WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };

キースペースを指定

cqlsh> USE mykeyspace;
cqlsh:mykeyspace>

テーブル作成

cqlsh:mykeyspace> CREATE TABLE users (
              ...   user_id int PRIMARY KEY,
              ...   fname text,
              ...   lname text
              ... );

usersにデータをストア

cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
              ...   VALUES (1745, 'john', 'smith');
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
              ...   VALUES (1744, 'john', 'doe');
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
              ...   VALUES (1746, 'john', 'smith');

取得

cqlsh:mykeyspace> SELECT * FROM users;

 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1744 |  john |   doe
    1746 |  john | smith

(3 rows)

インデックス作成

cqlsh:mykeyspace> CREATE INDEX ON users (lname);
cqlsh:mykeyspace> SELECT * FROM users WHERE lname = 'smith';

 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1746 |  john | smith

(2 rows)

ひとまず、単一ノードのセットアップは完了。

Macからの接続

デフォルトでは接続できない。

❯ cqlsh 192.168.33.10
Connection error: ('Unable to connect to any servers', {'192.168.33.10': error(61, "Tried connecting to [('192.168.33.10', 9042)]. Last error: Connection refused")})

Thrift RPCサーバを起動させるため
以下2箇所を修正する

conf/cassandra.yaml
#start_rpc: false
start_rpc: true
#rpc_address: localhost
rpc_address: 192.168.33.10

設定ファイル編集後、cassandraを再起動すると接続できる

❯ cqlsh 192.168.33.10
Connected to Test Cluster at 192.168.33.10:9042.
[cqlsh 5.0.1 | Cassandra 3.11.1 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3