读书人

cassandra 学习日志

发布时间: 2012-09-04 14:19:30 作者: rapoo

cassandra 学习日记

本文所有实例的测试环境如下:

操作系统:Windows7(32位)

cassandra:apache-cassandra-0.6.1

JDK:jdk1.6.0_14

?

1、安装cassandra

?

???? 1.1> 下载地址:http://cassandra.apache.org/

?

???? 1.2> 修改基本的配置

????????? 一、先修改storage-conf.xml:

????????????? 欲修改节点名称如下:

?????????????? DataFileDirectory、CommitLogDirectory

?????????????? 以上两个个均为文件路径,根据自己的情况做更改。

?

????????? 二、修改 log4j.properties

?????????????? 把日志路径改为自己的就行了;看日志便于排查问题。

?

????????? 其它配置项修改

??????????????? 根据配置文件的说明,即可定制自己的配置!如果看不明白说明的话,请在网上先搜索下!

?

???? 1.3> 环境变量配置(针对windows操作系统)

??????????? CASSANDRA_HOME:自己的CASSANDRA根路径

??????????? 例如:CASSANDRA_HOME:D:\apache-cassandra-0.5.1

?

???? 1.4> 启动cassandra

?????????? 执行 bin/cassandra.bat(windows)?? bin/cassandra (Linux)

?????????? 看到启动页的最后一行为如下内容,即为启动成功!

???????? ? “ INFO - Starting up server gossip”

?

???? 1.5> 配置结束

?

2、 cassandra 数据模型

?

?????? set Keyspace1.Standard1['jsmith']['first'] = 'John'
????????????????? \??????????????????? \???????????????? \?????? ? ? \???????? ??? \
?????????????????? \??????????????????? \???????????????? \_ key?? \????????? ?? \_ value
??????????????????? \??????????????????? \?????????????????? ? ? ?????? \_ column
????????? ? ? ? ? ?? \_ keyspace? \_ column family

?

? ? ? [Keyspace]
??????????? Cassandra中的最大组织单元,其中包含了一系列Column family。

????? [Column family(CF)]
??????????? CF是某个特定Key的数据集合,每个CF物理上被存放在单独的文件中。

????? [Key]
??????????? 数据必须通过Key来访问,Cassandra允许范围查询.
??????????? 例如:start => ‘10050′, :finish => ‘10070′

????? [Column]

#cassandra-cli connect <ip> 9160

?

????????? windows:

????????? 先执行cassandra-cli.bat

????????? 再输入 connect <ip> 9160,然后回车。

?

????????? 3.1.2 set、 get、 del、 count

?

????????????? set 新增和编辑

????????????? get 查询

????????????? del? 删除

????????????? count? 按照参数统计记录数

?

????????????? 如果编辑某条数据,只需set新的value即可;用法跟Map一样!

?

????????????? 例子如下:

?

cassandra> set Keyspace1.Standard2['jsmith']['first'] = 'John'Value inserted.cassandra> get Keyspace1.Standard2['jsmith']['first']=> (column=first, value=John, timestamp=1273452409212000)cassandra> del Keyspace1.Standard2['jsmith']['first']column removed.

?

????????? 3.1.3 其它命令

?

????????????? 1、describe keyspace <keyspacename>????????????????????????????? Describe keyspace.
????????????? 2、exit?????????????????????????????????????????????????????????????????? Exit CLI.
????????????? 3、quit?????????????????????????????????????????????????????????????????? Exit CLI.
????????????? 4、show config file??????????????????????????????? Display contents of config file.
????????????? 5、show cluster name????????????????????????????????????????? Display cluster name.
????????????? 6、show keyspaces?????????????????????????????????????????? Show list of keyspaces.
????????????? 7、show api version??????????????????????????????????????? Show server API version.

?

??? 3.2 代码连接(java)

?

?

?

?

?

读书人网 >其他数据库

热点推荐