下载和安装简介
http://cassandra.apache.org/download/
找到一个合适的下载链接,例如:
wget https://mirror.bit.edu.cn/apache/cassandra/3.11.6/apache-cassandra-3.11.6-bin.tar.gz
## 需要java环境 解压-启动
tar -zxvf apache-cassandra-3.11.6-bin.tar.gz
bin/cassandra -f ## -f” 选项指定cassandra在前台运行,如果不加的话会在后台运行
详情参考 https://www.w3cschool.cn/cassandra/cassandra_installation.html
常用数据类型
数据类型 |
描述 |
数据类型 |
描述 |
ascii |
ascii字符串 |
text |
表示UTF8编码的字符串 |
bigint |
64位整数 |
timestamp |
表示时间戳 |
blob |
二进制数组 实际16进制字符串 |
timeuuid |
时间相关uuid |
Boolean |
布尔值 |
uuid |
uuid |
counter |
表示计数器,支持原子性的增减,不支持直接赋值 |
varchar |
表示uTF8编码的字符串 |
decimal |
高精度小数 |
varint |
表示任意精度整数 |
double |
64位浮点数 |
list |
列表是一个或多个有序元素的集合。 |
float |
32位浮点数 |
map |
键值对的集合。 |
inet |
ipv4或ipv6协议的ip地址 |
set |
集合是一个或多个元素的集合。 |
int |
32位整数 |
图形化工具dev-center
我的资源里下载包,无积分留言
## 表示例
CREATE TABLE IF NOT EXISTS cps.ts_kv_cf (
entity_type text, // (DEVICE, CUSTOMER, TENANT)
entity_id timeuuid,
key text,
partition bigint,
ts bigint,
bool_v boolean,
str_v text,
long_v bigint,
dbl_v double,
PRIMARY KEY (( entity_type, entity_id, key, partition ), ts)
);
简单CQL示例
## 简单sql
use keyspace;
select * from table where 1=1 limit 10;
### timeuuid 类型坑 不用带上引号
select * from table where timeuuidType = 12345678
### 强制查询 partitioning_key不完整需要强制查询
select * from table ALLOW FILTERING;
### thingsboard示例、建表语句如上
select * from ts_kv_cf where entity_type = 'DEVICE' and entity_id = 2523e9d0-60f7-11e9-b7b8-edae55f030fc ALLOW FILTERING;
注意:cassandra的blob类型存储的是16进制,注意拿出来转换乱码;还是用datastax包来操作;
cassandra常用工具
bin/cqlsh
Connection error: ('Unable to connect to any servers', {'127.0.0.1': error(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
直接使用报错,可以指定Ip
./cqlsh 192.168.x.xx
## 指定端口空格就行 其他通过-h了解
./cqlsh 192.168.x.xx port
nodeTool
nodeTool可以做很多操作,自行查看官网或者-h
/bin/nodetool status 查看集群状态
status Up/DOWN tokens 每个节点的token数量 hostid 节点网络id rack 节点可用区
owns 节点拥有的数据的百分比乘以复制因子
个节点可以拥有33%的环,但是如果复制因子为3,则显示为100%。
其他查看官方文档 https://docs.datastax.com/en/cassandra-oss/3.x/cassandra/tools/toolsAboutNodetool.html
cassandra-stress 略
用于压力测试和基本基准测试的工具
参考博客--未验证
cassandra数据迁移
https://www.cnblogs.com/zzd-zxj/p/6293776.html
cassandra-migrate 也是个工具,但是迁移失败时该工具不会回滚数据库。 应手动还原备份
通过命令csv导出导入
Cassandra运维工具-Reaper安装与使用
https://www.jianshu.com/p/cbef477e2b55
Cassandra扩容踩坑记
https://www.jianshu.com/p/1dcca8f19894
refs :
https://cassandra.apache.org/doc/latest/
datastax文档
https://docs.datastax.com/en/landing_page/doc/landing_page/current.html