Cassandra叢集運維[Add & Remove Nodes]
在對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
./bin/cassandra
- 初始化system相關資訊
...... INFO06:14:41 Initializing system.IndexInfo INFO06:14:42 Initializing system.batches INFO06:14:42 Initializing system.paxos INFO06:14:42 Initializing system.local INFO06:14:42 Initializing system.peers INFO06:14:42 Initializing system.peer_events INFO06:14:42 Initializing system.range_xfers INFO06:14:42 Initializing system.compaction_history INFO06:14:42 Initializing system.sstable_activity INFO06:14:42 Initializing system.size_estimates INFO06:14:42 Initializing system.available_ranges INFO06:14:42 Initializing system.views_builds_in_progress INFO06:14:42 Initializing system.built_views INFO06:14:42 Initializing system.hints INFO06:14:42 Initializing system.batchlog ......
- 尋找現有叢集節點
INFO06:14:44 Node /xx.xxx.xx.xx is now part of the cluster INFO06:14:44 Node /xx.xxx.xx.xx is now part of the cluster INFO06:14:44 Node /xx.xxx.xx.xx is now part of the cluster INFO06:14:44 Handshaking version with /xx.xxx.xx.xx INFO06:14:44 Handshaking version with /xx.xxx.xx.xx INFO06:14:44 InetAddress /xx.xxx.xx.xx is now UP INFO06:14:44 InetAddress /xx.xxx.xx.xx is now UP INFO06:14:44 InetAddress /xx.xxx.xx.xx is now UP
- 新節點加入叢集
INFO06:14:45 JOINING: waiting for ring information INFO06:14:45 Updating topology for all endpoints that have changed
- 同步schema
INFO06:14:49 Initializing system_traces.events INFO06:14:49 Initializing system_traces.sessions INFO06:14:49 Initializing system_distributed.parent_repair_history INFO06:14:49 Initializing system_distributed.repair_history INFO06:14:49 Initializing system_auth.resource_role_permissons_index INFO06:14:49 Initializing system_auth.role_members INFO06:14:49 Initializing system_auth.role_permissions INFO06:14:49 Initializing system_auth.roles INFO06:14:49 JOINING: waiting for schema information to complete
- Copy Schema資料
INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Executing streaming plan for Bootstrap INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Starting streaming to /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Starting streaming to /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Starting streaming to /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4, ID#0] Beginning stream session with /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4, ID#0] Beginning stream session with /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4, ID#0] Beginning stream session with /xx.xxx.xx.xx INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4 ID#0] Prepare completed. Receiving 48 files(358160851 bytes), sending 0 files(0 bytes) INFO06:15:22 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4 ID#0] Prepare completed. Receiving 35 files(132483825 bytes), sending 0 files(0 bytes) INFO06:15:23 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4 ID#0] Prepare completed. Receiving 46 files(174538642 bytes), sending 0 files(0 bytes) INFO06:16:54 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Session with /xx.xxx.xx.xx is complete INFO06:17:38 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Session with /xx.xxx.xx.xx is complete INFO06:20:28 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] Session with /xx.xxx.xx.xx is complete INFO06:20:28 [Stream #317a30b0-d29d-11e8-aa92-e9ebc9b827d4] All sessions completed
- 節點切換成NORMAL
INFO06:20:29 Node /xx.xxx.xx.xx state jump to NORMAL INFO06:20:29 Waiting for gossip to settle before accepting client requests...
檢視節點同步狀態
./bin/nodetool status
- 資料同步期間節點的狀態:
Datacenter: dc1 =============== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving --AddressLoadTokensOwns (effective)Host IDRack UNxx.xxx.xx.xx1.53 GB256100.0%30ed942d-6827-469b-aab9-7fb649c6c3d7rack1 UNxx.xxx.xx.xx1.38 GB256100.0%96736106-e95d-4c54-aabf-41666071bc59rack1 UNxx.xxx.xx.xx1.07 GB256100.0%4351af17-2e68-4b46-a78f-fad900e44d13rack1 UJ新加節點57.87 MB256?f3f590ac-9835-47bb-b4d8-6e17ea2916acrack1
- 資料同步結束後的狀態:
Datacenter: dc1 =============== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving --AddressLoadTokensOwns (effective)Host IDRack UNxx.xxx.xx.xx1.53 GB25669.2%30ed942d-6827-469b-aab9-7fb649c6c3d7rack1 UNxx.xxx.xx.xx1.38 GB25679.3%96736106-e95d-4c54-aabf-41666071bc59rack1 UNxx.xxx.xx.xx1.07 GB25678.0%4351af17-2e68-4b46-a78f-fad900e44d13rack1 UNxx.xxx.xx.xx581.43 MB25673.5%f3f590ac-9835-47bb-b4d8-6e17ea2916acrack1
執行nodetool cleanup
nodetool options cleanup [keyspace_name [table_name] […] ]
在所有新節點都加入叢集並且資料同步完成後,在之前舊的每一個節點上執行nodetool cleanup操作刪除keys。
在做操作時保證一個節點結束後再執行下一個節點,不要併發執行,這樣可以安全地推遲清理
Reomve Nodes
UN狀態的節點下線
在要下線的節點執行nodetool decommission
命令
nodetool <options> decommission
該命令會將當前節點的range和請求交給其他節點管理,並且將資料同步給其他節點
DN狀態的節點下線
在任何存活的節點執行nodetool removenode
命令
該命令會將當前叢集下線的節點移除,並且將資料同步給其他節點
- 檢視節點狀態:
Datacenter: DC1 =============== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving --AddressLoadTokensOwns (effective)Host IDRack UN192.168.2.101112.82 KB25631.7%420129fc-0d84-42b0-be41-ef7dd3a8ad06RAC1 DN192.168.2.10391.11 KB25633.9%d0844a21-3698-4883-ab66-9e2fd5150eddRAC1 UN192.168.2.102124.42 KB25632.6%8d5ed9f4-7764-4dbd-bad8-43fddce94b7cRAC1
> nodetool <options> removenode -- <status> | <force> | <ID>
> nodetool removenode d0844a21-3698-4883-ab66-9e2fd5150edd
節點下線失敗
nodetool assassinate
nodetool [options] assassinate <ip_address>
nodetool -u cassandra -pw cassandra assassinate 192.168.100.2
轉載請註明出處