官网地址 Apache Cassandra | Apache Cassandra Documentation
下载链接:Apache Downloads
windows下安装:windows系统下cassandra的安装方法_sxjlinux的博客-CSDN博客
此版本没有找到bat文件,所以没有使用;
在ubuntu20下,解压,
编辑 cassandra/conf/cassandra-env.sh
脚本,取消注释:
#MAX_HEAP_SIZE="4G"
#HEAP_NEWSIZE="800M"
如果不更改直接启动,则报错
./bin/cassandra -R
这样就能正常启动了,
如果需要设置服务地址,需要设置:
rpc_address: 10.128.6.1
broadcast_rpc_address: 10.128.6.1
客户端连接一下:
./bin/cqlsh
服务器用户的配置:设置cassandra用户名和密码 - 走看看
cassandra如何设置用户名和密码_弹指三挥间的博客-CSDN博客_cassandra 用户名密码
查一下命名空间:
describe keyspaces
创建一个自己的:
CREATE KEYSPACE IF NOT EXISTS robinDb WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};
use robinDb;
创建一个表:
【Cassandra】数据类型和基础语法_清平乐的技术专栏的博客-CSDN博客_cassandra 数据类型
cassandra表中主键的类型_Lang-1210的博客-CSDN博客_cassandra主键
这里使用id的哈希作为作为Partition Key ,使用用户ID与时间戳作为Clustering Key,另外一个列存储json数据;
create table u_inbox(p int, id bigint, tm bigint, c text, PRIMARY KEY(p, id, tm ) );
查看一下:
describe tables;
# 输出
CREATE TABLE robindb.u_inbox (
p int,
id bigint,
tm bigint,
c text,
PRIMARY KEY (p, id, tm)
) WITH CLUSTERING ORDER BY (id ASC, tm ASC)
AND additional_write_policy = '99p'
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND cdc = false
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND default_time_to_live = 0
AND extensions = {}
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair = 'BLOCKING'
AND speculative_retry = '99p';
插入数据并查询:
insert into u_inbox(p, id, tm, c) VALUES(1, 13610501000, 1, 'test it');
insert into u_inbox(p, id, tm, c) VALUES(1, 13610501000, 2, 'test it');
insert into u_inbox(p, id, tm, c) VALUES(1, 13610501000, 3, 'test it');
insert into u_inbox(p, id, tm, c) VALUES(1, 13610501000, 4, 'test it');
select * from u_inbox where p=1 and id=13610501000 and tm> 1;
cqlsh:robindb> select * from u_inbox;
p | id | tm | c
---+-------------+----+---------
1 | 13610501000 | 1 | test it
1 | 13610501000 | 2 | test it
1 | 13610501000 | 3 | test it
1 | 13610501000 | 4 | test it
使用go操作数据库的方式一(cql方式):http://t.csdn.cn/1oIWG
方式二:GitHub - gocassa/gocassa: A high level Cassandra library in Go, on top of gocql
试用了,不行,太旧了!
后记:目前有了C++版本的数据库替代Scylla, 性能号称可以提高10倍, http://t.csdn.cn/ICG5p
官方文档:Getting Started | Scylla Docs