Cassandra修改集群名稱


如果需要在不影響存儲數據的情況下,更改cassandra集群名字,可采用如下步驟:
1. 對集群所有節點(for each node)依次連接CQLSH,使用如下命令: 
UPDATE system.local SET cluster_name = '<cluster_name>' where key='local';
2. 在該集群的所有節點(for each node)執行
nodetool flush system (推薦)
或 
nodetool flush
3. 將cassandra.yaml中的cluster_name更新為新的集群名稱
4. 重啟cassandra集群
 
 
本地更改cluster name測試:
集群節點:192.168.50.130(node1)、192.168.50.131(node2)、192.168.50.128(node3)
集群名稱:CjjCluster (修改前)
 
依次更新每個節點過程:
1. 更新系統各個表:
[root@node2 ~]# cqlsh 192.168.50.131
Connected to CjjCluster at 192.168.50.131:9042.
[cqlsh 5.0.1 | Cassandra 2.1.19 | CQL spec 3.2.1 | Native protocol v3]
Use HELP for help.
cqlsh> UPDATE system.local SET cluster_name = 'Cjj JCPT Test' where key='local';
cqlsh> exit;
[root@node2 ~]# cqlsh 192.168.50.131
Connected to CjjCluster at 192.168.50.130:9042.
[cqlsh 5.0.1 | Cassandra 2.1.19 | CQL spec 3.2.1 | Native protocol v3]
Use HELP for help.
cqlsh> UPDATE system.local SET cluster_name = 'Cjj JCPT Test' where key='local';
cqlsh> exit;
[root@node2 ~]# cqlsh 192.168.50.128
Connected to CjjCluster at 192.168.50.128:9042.
[cqlsh 5.0.1 | Cassandra 2.1.19 | CQL spec 3.2.1 | Native protocol v3]
Use HELP for help.
cqlsh> UPDATE system.local SET cluster_name = 'Cjj JCPT Test' where key='local';
cqlsh> exit;
 
2. 將所有個節點的memtable刷為commitlog
[root@node2 ~]# nodetool flush system
[root@node1 ~]# nodetool flush system
[root@node3 ~]# nodetool flush system
 
3. 更改cassandra.yaml中的cluster_name
4. 重新啟動集群即可,看集群狀態
[root@node2 ~]# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 192.168.50.128 800.29 KB 256 67.1% 1be00d94-1185-463d-a2e6-50d398bdd0c5 rack1
UN 192.168.50.131 1.42 MB 256 65.9% d371cbfe-b83f-4c6e-8f87-a8c1e3316f6c rack1
UN 192.168.50.130 1.15 MB 256 67.0% b26a5cb5-39c8-48fe-ad7f-7134476b7fe6 rack1

  

操作不當,重啟節點可能有如下錯誤:
org.apache.cassandra.exceptions.ConfigurationException: Saved cluster name XXX2 != configured XXX2
一般這種錯誤是由於沒有在每個節點上更新,因此要注意(for each node),這個很關鍵。
 
另外如果實在解決不了,有一種不推薦的方法,可以刪除cassandra的data/data/system目錄下的所有文件,之后重命名cassandra.yaml中的cluster_name,重新啟動集群即可,不過不推薦這種方法,因為不確定是否刪除system重要重要數據。
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM