实践一:配置多个host
客户端配置多个cluster host,这样做有两个好处:
- 避免单点问题
- 客户端请求负载均衡(round-robin)
方法一、
HFactory.getOrCreateCluster("MyCluster","host1:9160,host2:9160,host3:9160")
方法二、
HFactory.getOrCreateCluster("MyCluster","host0:9160")
cluster.addHost(new CassandraHost("host1", 9160), true);
cluster.addHost(new CassandraHost("host2", 9160), true);
cluster.addHost(new CassandraHost("host3", 9160), true);
注意:addHost()方法第二个参数为true才会真正生效
--end
本文介绍如何通过两种方法在客户端配置多个Cassandra节点以实现负载均衡和避免单点故障,包括直接配置多个节点地址及逐个添加节点的方法。
4149

被折叠的 条评论
为什么被折叠?



