一. 基本概念
1. Primary Key,Partition Key,Clustering Key
以下面的Table为例子:
create table sample(
k_part_one text,
k_part_two int,
k_clust_one text,
k_clust_two int,
k_clust_three uuid,
data text,
PRIMARY KEY((k_part_one,k_part_two),k_clust_one,k_clust_two,k_clust_three)
)withCLUSTERING ORDER BY (k_clust_oneDESC,k_clust_two ASC);
Primary Key=Partition Key + Clustering Key,Partition Key是(k_part_one,k_part_two),Clustering Key是k_clust_one,k_clust_three。
Partition Key决定了数据存储在集群的哪个节点,Primary Key决定数据在当前节点的排序。
2. 集合类型
1) set 如:set<text>,有序集合{'f@baggins.com','baggins@gmail.com'}
2) list 如:list<text>,数组['rivendell','rohan' ]
3) map 如:map<timestamp,text>,字典{ '2013-9-22 12:01' : 'birthday wishes to Bilbo','2013-10-1 18:00': 'Check into Inn of Pracing Pony'}
3. 自定义类型(UDT)
CREATE TYPE mykeyspace.address (
street text,
city text,
zip_code int,
phones set<text>
);
二. 安装
下面以在windows 7 x64 安装Cassandra 2.1.14为例
1) 下载JDK并安装至C:\Program Files\Java\jdk1.8.0_91
2) 下载apache cassandra 2.1.14,并解压缩到D:\apache-cassandra-2.1.14
http://mirror.bit.edu.cn/apache/cassandra/2.1.14/apache-cassandra-2.1.14-bin.tar.gz
3) 修改D:\apache-cassandra-2.1.14\bin下的两个配置文件
a.cassandra.bat
在@REMlimitations under the License. 行下添加下面两行
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_91
set CASSANDRA_HOME=D:\apache-cassandra-2.1.14
b.cassandra.in.bat
在@REMlimitations under the License.行下添加下面两行
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_91
set CASSANDRA_HOME=D:\apache-cassandra-2.1.14
data
data\data
data\commitlog
也可以通过修改conf\cassandra.yaml配置文件,将目录创建在其它地方。
# Directories where Cassandra should store data on disk. Cassandra
# will spread data evenly across them,subject to the granularity of
# the configured compaction strategy.
# If not set,the default directory is $CASSANDRA_HOME/data/data.
# data_file_directories:
# - /var/lib/cassandra/data
# commit log. when running on magnetic HDD,this should be a
# separate spindle than the data directories.
# If not set,the default directory is $CASSANDRA_HOME/data/commitlog.
# commitlog_directory: /var/lib/cassandra/commitlog
a. 开启账号密码验证,使用cassandra/cassandra登录后,可以创建新用户
authenticator: AllowAllAuthenticator >authenticator: PasswordAuthenticator
b. 设置对外监听ip,否者只能以localhost访问
rpc_address: localhost > rpc_address: 10.128.42.166
6) 启动Cassandra
打开cmd,运行D:\apache-cassandra-2.1.14\bin\cassandra.bat
7) 验证Cassandra
打开cmd,切换到 D:\apache-cassandra-2.1.14\bin\目录
查看服务器状态:nodetool status
查看服务详细信息:nodetool info
三. 参考资料
http://www.slideshare.net/jaykumarpatel/cassandra-data-modeling-best-practices?next_slideshow=1
http://www.ebaytechblog.com/2012/07/16/cassandra-data-modeling-best-practices-part-1/
http://www.ebaytechblog.com/2012/08/14/cassandra-data-modeling-best-practices-part-2/
http://www.slideshare.net/patrickmcfadin/advanced-data-modeling-with-apache-cassandra
http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling
http://docs.datastax.com/en/cql/3.1/cql/cql_using/start_cql_win_t.html
http://datastax.github.io/csharp-driver/features/components/core/
原文链接:https://www.f2er.com/nosql/203646.html