Cassandra 入门
一. 基本概念 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 (
二. 安装 下面以在windows 7 x64 安装Cassandra 2.1.14为例 1) 下载JDK并安装至C:Program FilesJavajdk1.8.0_91 http://download.oracle.com/otn-pub/java/jdk/8u91-b15/jdk-8u91-windows-x64.exe?AuthParam=1465374689_e7b7ab5575db24a9221c618360f4fa5d 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.14bin下的两个配置文件 a.cassandra.bat 在@REMlimitations under the License. 行下添加下面两行 set JAVA_HOME=C:Program FilesJavajdk1.8.0_91 b.cassandra.in.bat 在@REMlimitations under the License.行下添加下面两行 set JAVA_HOME=C:Program FilesJavajdk1.8.0_91 data datadata datacommitlog 也可以通过修改confcassandra.yaml配置文件,将目录创建在其它地方。
5)修改配置文件confcassandra.yaml 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.14bincassandra.bat 7) 验证Cassandra 打开cmd,切换到 D:apache-cassandra-2.1.14bin目录 查看服务器状态: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/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |