cassandra多数据中心的配置

cassandra默认建keyspace的时候,是需要制定拓扑策略的,小数据就直接用单数据中心的simpleStrategy了,网上资料都没具体提如何配置多数据中心,这里简单贴一下

cassandra.yaml里面修改endpoint_snitch


具体的snitch方式有

simpleSnitch

默认的,单数据中心

GossipingPropertyFileSnitch

官方推荐在生产环境下使用,本节点的rack和dc名字保存在cassandra-rackdc.properties,并且会通过gossip这个p2p协议传播到所有节点上去
如果cassandra-topology.properties文件存在,cassandra会把两个properties文件的结果合并,如果两个properties文件里面有有同一个节点的配置,以cassandra-rackdc.properties的配置为准。

PropertyFileSnitch

dc和rack通过显式的定义在cassandra-topology.properties文件里面

建keyspace的时候,这样指定

CREATE KEYSPACE "test_keyspace" WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2};

意思是采用网络多数据中心策略,有两个数据中心,dc1的replica factor为3,dc2的replica factor为2

参考的地址http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/create_keyspace_r.html