集群配置
cassandra的安装在前面已经记录过了,可以参考:
http://blog.csdn.net/zq9017197/article/details/17588581
现在假设已经在两台服务器上分别安装好了cassandra。
##在节点1修改配置文件conf/cassandra.yaml
cluster_name: 'Cluster01'
num_tokens: 256
- seeds: "10.10.10.8"
listen_address: 10.10.10.8
rpc_address: 10.10.10.8
endpoint_snitch: SimpleSnitch
##启动节点1(启动之前记得清空之前做实验留下的数据文件等)
# ./cassandra
[root@linux bin]# ./nodetool status
xss = -ea -javaagent:./../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms1013M -Xmx1013M -Xmn200M -XX:+HeapDumpOnOutOfMemoryError -Xss256k
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.10.10.8 40.8 KB 256 100.0% bf2906d4-d94a-4cae-a081-768699e61521 rack1
##节点2,修改配置文件conf/cassandra.yaml
cluster_name: 'Cluster01'
num_tokens: 256
- seeds: "10.10.10.8"
listen_address: 10.10.10.9
rpc_address: 10.10.10.9
endpoint_snitch: SimpleSnitch
##启动节点2(启动之前记得清空之前做实验留下的数据文件等)
# ./cassandra
[root@db bin]# ./nodetool status
xss = -ea -javaagent:./../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms1013M -Xmx1013M -Xmn200M -XX:+HeapDumpOnOutOfMemoryError -Xss256k
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.10.10.8 40.8 KB 256 100.0% bf2906d4-d94a-4cae-a081-768699e61521 rack1
UN 10.10.10.9 55.06 KB 256 100.0% f0c482ec-81a9-44dc-adb3-0232f66b50ae rack1
##节点2加入集群后节点1的响应信息
INFO [Thread-2] 2013-12-27 20:49:38,304 ThriftServer.java (line 135) Listening for thrift clients...
INFO [HANDSHAKE-/10.10.10.9] 2013-12-27 20:56:19,627 OutboundTcpConnection.java (line 386) Handshaking version with /10.10.10.9
INFO [GossipStage:1] 2013-12-27 20:56:21,423 Gossiper.java (line 870) Node /10.10.10.9 is now part of the cluster
INFO [HANDSHAKE-/10.10.10.9] 2013-12-27 20:56:21,437 OutboundTcpConnection.java (line 386) Handshaking version with /10.10.10.9
INFO [RequestResponseStage:3] 2013-12-27 20:56:21,455 Gossiper.java (line 833) InetAddress /10.10.10.9 is now UP
集群机制
一致性哈希
Gossip协议 ——用于在环内节点之间传播状态信息
Snitch ——支持多个数据中心
复制策略 ——数据的冗余策略
commit log
进行写操作时,首先要写commit log
只有操作被写入commit log的数据,才算写入成功
当发生掉电,实例崩溃等问题的时候,可以使用commit log进行恢复
memtable
数据操作成功写入到commit log后,就开始写入内存中的memtable
memtable中的数据达到一定阈值后,就开始写入硬盘中的SSTable,然后再内存中重新建立一个memtable接收下一批数据
上述刷写过程是非阻塞的
查询时先查询memtable
副本因子 ——控制数据的冗余份数
CREATE KEYSPACE Excelsior WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
CREATE KEYSPACE "Excalibur" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};