问题描述
今天我在使用 datastax 连接到 cassandra 时遇到了一个问题。我有错误 “尝试查询的所有主机均失败”。最终我发现这是由于 SSL 终止导致连接没有发生。
问题:
- 我从 Tableplus 等本地客户端连接到 cassandra。我已将 SSl 设置为“已禁用”,但仍然可以连接。为什么我在使用 datastax 驱动程序时无法以相同的方式连接。
我的 Nodetool 状态如下
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 70.68 KiB 256 100.0% cf65f26b-db8e-490b-bd38-ec8d74112b67 rack1
#
#
解决方法
感谢@Luciana 的参与。但这里最终对我有用。最初我没有空的 clusterBuilder.withSSL();
。但后来
之前
Cluster.Builder clusterBuilder = Cluster.builder();
if (sslEnabled) {
clusterBuilder.withSSL(getSslOptions());
}
之后
Cluster.Builder clusterBuilder = Cluster.builder();
clusterBuilder.withSSL();
if (sslEnabled) {
clusterBuilder.withSSL(getSslOptions());
}
我通过 Datastax 文档找到了 https://docs.datastax.com/en/developer/java-driver/3.0/manual/ssl/
希望这会有所帮助。我并不声称这可以解决所有类似的错误,但这可能是可以解决此连接问题的原因之一。