使用DataStax Java驱动程序1.0.4使用CQL连接到Cassandra时出现exception

我在我的笔记本电脑上运行了Cassandra 1.2.11。 我可以使用nodetoolcqlsh连接到它,但是当我尝试使用DataStax 1.0.4 Java API使用CQL 3.0进行连接时,我收到以下错误:

 com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1 ([localhost/127.0.0.1] Unexpected error during transport initialization (com.datastax.driver.core.TransportException: [localhost/127.0.0.1] Channel has been closed))) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:186) 

我使用以下代码进行连接,取自DataStax文档。 我尝试了几个端口号,包括离开withPort()调用,但似乎没有任何工作。

 Cluster cluster = new Cluster.Builder() .addContactPoints("localhost") .withPort(9160) .build(); 

使用telnet我可以validationCassandra服务器肯定在我指定的每个端口上监听。 我还validation了所有必需的库jar文件都在我的类路径中,如文档中所述。

事实certificate我错过了文档中的一个部分。

我使用的是早期版本的Cassandra中的旧cassandra.yaml配置文件,它没有启用Native Transport二进制协议。 以下代码段显示了我需要更改的设置:

 # Whether to start the native transport server. start_native_transport: true # port for the CQL native transport to listen for clients on native_transport_port: 9042 

重新启动Cassandra后,客户端能够成功连接并运行CQL 3.0命令。 请注意,必须更改创建连接的代码以使用文件中指定的端口,如下所示:

 Cluster cluster = new Cluster.Builder() .addContactPoints("localhost") .withPort(9042) .build(); 

另请注意,从Cassandra 1.2.5及更高版本开始,默认情况下启用本机传输。

尝试使用较新版本的cassandra版本使用旧版本的java驱动程序时,也会出现此错误。

我在Ubuntu中遇到了同样的问题。 我最近安装了以下命令,这是datastax指南

apt-get install cassandra = 2.0.11 dsc20 = 2.0.11-1

在此之前,我只使用了

apt-get install cassandra

那对我来说也是同样的问题。 我刚删除然后用第一个命令(datastax指南)安装它。

PS用于删除cassandra使用下面的命令

apt-get purge cassandra