在对Cassandra进行维护的时候,通常需要扩集群或者迁移数据,涉及到添加、移除节点。
Cassandra Version: Apache Cassandra 3.0.6
Add Nodes
Virtual nodes (vnodes) greatly simplify adding nodes to an existing cluster:
Calculating tokens and assigning them to each node is no longer required.
Rebalancing a cluster is no longer necessary because a node joining the cluster assumes responsibility for an even portion of the data.
确保新加节点和现有集群的Cassandra 版本一致
【操作步骤】
在新的机器上部署cassandra,但不要启动
通常都是从现有集群的一台机器上scp cassandra目录到新机器
基于现有集群所用的snitch
算法修改配置文件
cassandra-topology.properties or the cassandra-rackdc.properties
- 使用
PropertyFileSnitch
算法配置:cassandra-topology.properties - 使用
GossipingPropertyFileSnitch
,Ec2Snitch
,Ec2MultiRegionSnitch
, andGoogleCloudSnitch
算法配置:cassandra-rackdc.properties
ps: 这两个配置与机架和多数据中心有关,如果是同机架单数据中心则不用配置
修改配置cassandra.yaml
文件
name | desc |
---|---|
auto_bootstrap | 默认文件中是没有这个参数的,如果没有默认为true;如果有且为false修改为true |
cluster_name | 需要加入的集群名称 |
listen_address/broadcast_address | 用来与集群内其他节点通信的ip,通常为本机真实ip,不要填写127.0.0.1或localhost |
endpoint_snitch | 用于定位节点和路由请求的算法,与现有集群保持一致 |
num_tokens | 节点中vnodes的数量,与现有集群配置保持一致,如果当前机器配置更高可以按比例增加这个值,可以有更好的性能 |
seed_provider | 种子节点,至少保证有一个现有集群的节点,-seeds列表表示了新节点与现有集群通过哪些节点通信(种子节点无法引导,所以不要仅仅把要加入的新节点配置进去,也不要将集群所有节点配置成种子节点) |
启动新节点Cassandra
1 | ./bin/cassandra |
- 初始化system相关信息
1 | ...... |
- 寻找现有集群节点
1 | INFO 06:14:44 Node /xx.xxx.xx.xx is now part of the cluster |
- 新节点加入集群
1 | INFO 06:14:45 JOINING: waiting for ring information |
- 同步schema
1 | INFO 06:14:49 Initializing system_traces.events |
- Copy Schema数据
1 | INFO 06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Executing streaming plan for Bootstrap |
- 节点切换成NORMAL
1 | INFO 06:20:29 Node /xx.xxx.xx.xx state jump to NORMAL |
查看节点同步状态
./bin/nodetool status
- 数据同步期间节点的状态:
1 | Datacenter: dc1 |
- 数据同步结束后的状态:
1 | Datacenter: dc1 |
运行nodetool cleanup
nodetool options cleanup [keyspace_name [table_name] […] ]
在所有新节点都加入集群并且数据同步完成后,在之前旧的每一个节点上运行nodetool cleanup操作删除keys。
在做操作时保证一个节点结束后再运行下一个节点,不要并发执行,这样可以安全地推迟清理
Reomve Nodes
UN状态的节点下线
在要下线的节点运行nodetool decommission
命令
1 | nodetool <options> decommission |
该命令会将当前节点的range和请求交给其他节点管理,并且将数据同步给其他节点
DN状态的节点下线
在任何存活的节点运行nodetool removenode
命令
该命令会将当前集群下线的节点移除,并且将数据同步给其他节点
- 查看节点状态:
1 | Datacenter: DC1 |
1 | nodetool <options> removenode -- <status> | <force> | <ID> |
1 | nodetool removenode d0844a21-3698-4883-ab66-9e2fd5150edd |
节点下线失败
nodetool assassinate
1 | nodetool [options] assassinate <ip_address> |
1 | nodetool -u cassandra -pw cassandra assassinate 192.168.100.2 |
转载请注明出处