如果需要在不影响存储数据的情况下,更改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重要重要数据。