cassandra权威指南读书笔记--配置cassadnra
阅读原文时间:2023年07月08日阅读:1

配置集群时,要求所有节点的集群名,分区器,snitch必须相同。种子节点最好相同。

种子节点:最好每个DC,配置2个,这样即使一个DC中一个种子节点挂了,仍然有一个中子节点可用。种子节点被认为是最先加入集群的,不会做数据迁移。其他节点都会优先连接种子节点加入集群。允许指定种子节点的实现,默认:org.apache.cassandra.locator.SeedProvider,这会从yaml文件中加载种子节点。
分区器:指定分区键如何排序。
Murmur3Partitioner,默认分区器,org.apache.cassandra.dht.Murmur3Partitioner,使用murmur3哈希算法生成token,使得分区键分布均匀随机。
RandomPartitioner,原来的默认分区器,使用加密hash,速度慢于murmur3,使用BigIntegerToken并应用MD5加密hash来确定分区键分布。
OrderPreservingPartitioner,有序分区器,token基于分区键的UTF-8字符串的排序,可以实现区间分片。会导致环不平衡,要经常使用nodetool loadbalance或者move操作。这样又会导致区间(多个分区键)查询并不比随机分区下的查询好多少。
ByteOrderedPartitioner,将数据处理为字节,根据字节去排序。

Snitch
endpoint_snitch可配置值:
org.apache.cassandra.locator.SimpleSnitch:没有机架感知策略,不适合多DC,副本策略只能选择SimpleStrategy。
org.apache.cassandra.locator.PropertyFileSnitch:使用cassandratopology.properties的标准java键/值属性文件来路由请求。副本策略设置NetworkTopologyStrategy。cassandra直接读文件确定节点在哪,发现节点时性能更高。
org.apache.cassandra.locator.GossipingPropertyFileSnitch:机架感知snitch。通过gossip交换机架和数据中心位置信息。使用cassandra-rackdc.properties文件定义,如果有cassandratopology.properties,也会使用。
org.apache.cassandra.locator.RackInferringSnitch:假定集群的节点按照一种一致的组网方案分布。比较各个节点IP的8位字节。如果第二个8位字节相同,认为在同一个DC。如果第三个8位字节的值相同,认为同一个机架。
云snitch:org.apache.cassandra.locator.Ec2Snitch和Ec2MultiRegionSnitch(Amazon EC2),org.apache.cassandra.locator.GoogleCloudSnitch,org.apache.cassandra.locator.CloudStackSnitch(Apache Cloudstack)
org.apache.cassandra.locator.DynamicEndPointSnitch:默认开启,包装上面选择的snitch。以下三个参数决定怎么动态snitch:dynamic_snitch_badness_threshold,dynamic_snitch_reset_interval_in_ms,dynamic_snitch_update_interval_in_ms

token:目前默认256,许多建议是32。我的使用经验是64。根据数据节点数,数量测试下最常用的模型的数据分布,确定的。
禁用虚拟节点:num_tokens设置为1,或者注释掉。同时设置initial_token.

网络配置:
listen_address(ip地址)和listen_interface(接口名比如eth0),2选1。
cassandra支持Thrift API(RPC),CQL(native transpot)。2.2之前,2个接口都支持,默认启用。3.0开始,默认禁用Thrift。CQL由start_native_transport来决定开启关闭,默认开启。
RPC端口,rpc_port,主要是Thrift 客户端使用。
rpc_keepalive,RPC和CQL都会用,默认为true,表示允许客户端保持长连接。
cassandra磁盘少了一个也可以保持运行。数据文件由disk_failure_policy决定,commitlog由commit_failure_policy决定。默认为stop,禁用客户端接口。
keyspace的durable_write:是否允许不写commitlog。默认为true,即写commitlog。
增加副本因子-->nodetool repair
减少副本因子-->nodetool clean
一般原则:写吞吐量=节点数除以副本因子。

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章