# cassandra **Repository Path**: doc_space/cassandra ## Basic Information - **Project Name**: cassandra - **Description**: 基于python的cassandra入门操作 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-04-20 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #**Cassandra快速入门** ### 1. Cassandra发展简史 Cassandra的最初开发工作就是由两位从Amazon跳槽到Facebook的Dynamo工程师完成的,Java语言编写,2008年7月由Facebook开放源码,2009年1月成为Apache孵化器项目。 ### 2. Cassandra的优点特性 * 高度可扩展性 * 高度可用性,无单点故障,P2P去中心化处理 * NOSQL列族实现 * 非常高的写入吞吐量和良好的读取吞吐量 * CQL查询语言 * 范围查询 * 可调节的一致性 * 灵活的模式 ### 3. Cassandra应用场景 通常在如下情况下可以考虑使用Cassandra: * 待处理的数据量很大 * 数据量超过关系型数据库的承载能力 * 大量集群 #**Cassandra安装与运行** ### 1. Windows下载并安装Cassandra * 安装JDK1.6或者以上版本 * 下载Cassandra,下载网址 http://cassandra.apache.org/download/ * 解压缩Cassandra,运行bin目录下的cassandra.bat,启动服务 * 运行bin目录下的cassandra-cli.bat启动连接 ### 2. Cassandra目录结构 * bin * conf * interface * javadoc * lib ### 3. Cassandra的常用配置参数 * cluster_name集群的名字,默认Test Cluster * listen_address监听的IP或主机 * commitlog_directories commitlog的保存路径 * data_file_directories 数据文件的存放目录 * save_caches_directories 缓存存放目录 * commit_failure_policy(stop,stop_commit,ignore)提交失败时采取的策略 * disk_failure_policy(stop,stop_paranoid,best_effort,ignore)磁盘故障 * endpoint_snitch 定位节点和路由请求 * rpc_address 监听客户端连接的地址 * seed_provider 需要联系的节点地址 * compaction_throughput_mb_per_sec 限定特定吞吐量下的压缩速率 * memtable_total_space_in_mb 最大使用的内存空间数量 * concurrent_reads 并发读取数量 * concurrent_writes 并发写数量 * incremental_backups 是否增量备份 * snapshot_before_compaction 压缩前执行快照 ### 4. Linux下安装运行Cassandra * 安装JDK1.6或者以上版本 * 下载Cassandra,下载网址 http://cassandra.apache.org/download/ * 解压缩Cassandra,运行bin目录下的cassandra,启动服务 * 运行bin目录下的cassandra-cli启动连接 ### 5. cassandra配置 * 为了让其他的机器可以访问本服务器,需要将本机的ip作为启动参数,可以将cassandra.yaml文件中的 ``` rpc_address: localhost ``` 改为 ``` rpc_address: 192.168.100.104 ``` * 为了要客户端通过用户名和密码登陆,在服务端将cassandra.yaml文件中的 ``` authenticator: AllowAllAuthenticator ``` 改为 ``` authenticator: PasswordAuthenticator ``` 然后重启服务,然后通过 ``` ./cqlsh 192.168.100.104 -ucassandra -pcassandra ``` 登陆cassandra数据库后,创建用户并删除默认超级用户 ``` CREATE USER root WITH PASSWORD '123456' SUPPER; DROP USER cassandra; ``` 登陆通过如下命令: ``` ./cqlsh 192.168.100.104 -uroot -p123456 ``` cql操作举例,很多操作类似于关系型数据库SQL的 ``` # 创建键空间stock create keyspace if not exists stock with replication={'class':'SimpleStrategy','replication_factor':1}; # 修改键空间stock alter keyspace stock with replication={'class':'SimpleStrategy','replication_factor':2} # 查看键空间stock属性 desc keyspace stock; # 删除键空间stock drop keyspace stock; # 创建users表 create table users(sid text primary key, name text, age int); # 查看表结构 desc table users ``` * 为了在windows上注册服务,需要下载prunsrv.exe用来注册cassandra服务 下载位置: ``` http://archive.apache.org/dist/commons/daemon/binaries/windows/ ```