卡桑德拉安装备忘录

总结

在使用Vagrant启动的CentOS 6上设置Cassandra 3系的备忘录。
该备忘录参考了以下链接:
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 };

指定Keith空间

cqlsh> USE mykeyspace;
cqlsh:mykeyspace>

创建表格

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

将数据存储在用户中

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服务器,请修改以下两个地方。

#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>
bannerAds