码迷,mamicode.com
首页 > 数据库 > 详细

Cassandra非关系型数据库

时间:2015-11-08 22:16:43      阅读:372      评论:0      收藏:0      [点我收藏+]

标签:

由于在工作中用到了Cassandra非关系型数据库,因此总结一下常用操作。Cassandra使用Java语言编写的,因此在安装之前,首先需要安装JDK。自己使用的版本为apache-cassandra-2.1.11-bin.tar.gz,在Ubuntu 12.04上进行安装。由于目前仅仅在单机上面实验,因此集群部分以后整理。

1. Cassandra安装和配置

(1)~/.bashrc环境变量配置

export CASSANDRA_HOME=/usr/local/cassandra/apache-cassandra-2.1.11

export PATH=${CASSANDRA_HOME}/bin:$PATH

(2)修改Cassandra配置文件

Cassandra配置文件为$CASSANDRA_HOME/conf/cassandra.yaml,如下所示:

  • 默认集群名(cluster_name):‘Test Cluster‘
  • 默认缓存文件存放路径(saved_caches_directory):$CASSANDRA_HOME/data/saved_caches
  • 默认数据文件存放路径(data_file_directories):$CASSANDRA_HOME/data/data
  • 默认commitlog存放路径(commitlog_directory):$CASSANDRA_HOME/data/commitlog
  • 默认的Cassandra服务地址(rpc_address):localhost
  • 默认的Cassandra服务端口(rpc_port):9160
  • 默认的CQL本地服务端口(native_transport_port):9042

说明:自己全部采用默认配置选项。

(3)修改Cassandra用户名和密码

  • 把配置文件cassandra.yaml中的authenticator: AllowAllAuthenticator修改为authenticator: PasswordAuthenticator。
  • 启动默认账户./cqlsh -ucassandra -pcassandra,创建用户create user ssw with password ‘913292836‘ superuser;
  • 删除默认帐号drop user cassandra;然后使用新的账户和密码进行登录。

 

2.  Cassandra基本操作

Cassandra中的keyspace相当于关系数据库的database,column family相当于table。

(1)创建keyspace

CREATE KEYSPACE test WITH REPLICATION = {class: SimpleStrategy, replication_factor: 1 };

(2)创建table

CREATE TABLE test.words (word text PRIMARY KEY, count int);

(3)插入数据

INSERT INTO test.words (word, count) VALUES (foo, 20);
INSERT INTO test.words (word, count) VALUES (bar, 20);

(4)查找数据

SELECT * FROM words;

查找结果,如下所示:

技术分享

说明:自己的重点是Spark RDDs和Cassandra tables的互操作。

 

参考文献:

[1] 如何安装和配置CASSANDRA:http://www.cnblogs.com/gpcuster/archive/2010/03/25/1695490.html

[2] 如何设置cassandra用户名和密码:http://zhaoyanblog.com/archives/307.html

[3] 分布式Key-Value存储系统:Cassandra入门:http://www.ibm.com/developerworks/cn/opensource/os-cn-cassandra/

[4] Cassandra Query Language (CQL) v3.2.0:http://cassandra.apache.org/doc/cql3/CQL-2.1.html

[5] Cassandra学习指南:http://heipark.iteye.com/blog/1902918

[6] DataStax Spark Cassandra Connector:https://github.com/datastax/spark-cassandra-connector

Cassandra非关系型数据库

标签:

原文地址:http://www.cnblogs.com/shengshengwang/p/4948382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!