简体   繁体   English

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

[英]Exception when connecting to Cassandra with CQL using DataStax Java driver 1.0.4

I have Cassandra 1.2.11 running on my laptop. 我在我的笔记本电脑上运行了Cassandra 1.2.11。 I can connect to it using nodetool and cqlsh but when I try and use the DataStax 1.0.4 Java API to connect using CQL 3.0 I get the following error: 我可以使用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)

I am using the following code to connect, taken from the DataStax documentation. 我使用以下代码进行连接,取自DataStax文档。 I have tried several port number, including leaving the withPort() call out but nothing seems to work. 我尝试了几个端口号,包括离开withPort()调用,但似乎没有任何工作。

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

Using telnet I can verify that the Cassandra server is definitely listening at each of the ports I have specified. 使用telnet我可以验证Cassandra服务器肯定在我指定的每个端口上监听。 I have also verified that all the required library jar files are on my classpath as described in the documentation. 我还验证了所有必需的库jar文件都在我的类路径中,如文档中所述。

It turns out I missed a section in the documentation . 事实证明我错过了文档中的一个部分。

I was using an old cassandra.yaml configuration file from an earlier version of Cassandra and it didn't enable the Native Transport binary protocol. 我使用的是早期版本的Cassandra中的旧cassandra.yaml配置文件,它没有启用Native Transport二进制协议。 The following snippet shows the settings that I needed to change: 以下代码段显示了我需要更改的设置:

# 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 

After restarting Cassandra the client was able to connect successfully and run CQL 3.0 commands. 重新启动Cassandra后,客户端能够成功连接并运行CQL 3.0命令。 Note that the code to create the connection must be changed to use the port specified in the file, like this: 请注意,必须更改创建连接的代码以使用文件中指定的端口,如下所示:

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

Also, note that from Cassandra 1.2.5 and above, the native transport is enabled by default. 另请注意,从Cassandra 1.2.5及更高版本开始,默认情况下启用本机传输。

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

I have the same issue in Ubuntu. 我在Ubuntu中遇到了同样的问题。 I installed recently with the below command which was the datastax guideline 我最近安装了以下命令,这是datastax指南

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

before that I used just 在此之前,我只使用了

apt-get install cassandra apt-get install cassandra

then it makes the same issue for me. 那对我来说也是同样的问题。 I just removed then installed it with the first command (datastax guideline). 我刚删除然后用第一个命令(datastax指南)安装它。

PS For remove the cassandra use below command PS用于删除cassandra使用以下命令

apt-get purge cassandra apt-get purge cassandra

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有Datastax Java驱动程序的CQL向Cassandra添加任意列? - How to add arbitrary columns to Cassandra using CQL with Datastax Java driver? 使用Datastax CQL驱动程序插入Cassandra时设置TTL - Setting TTLs when inserting into Cassandra with the Datastax CQL driver Datastax Solr Java驱动程序CQL - Datastax Solr Java Driver CQL 通过 ssl 连接 cassandra 与 datastax cassandra JAVA 驱动程序 - connecting cassandra through ssl with datastax cassandra JAVA driver Cassandra 1.2.6 java datastax驱动程序EXCEPTION没有为流0设置处理程序 - Cassandra 1.2.6 java datastax driver EXCEPTION No handler set for stream 0 无法使用Cassandra Datastax Java驱动程序连接到Cassandra节点之一 - Unable to connect to one of the Cassandra nodes using Cassandra Datastax Java Driver 是否可以通过datastax驱动程序向Cssandra集群提交CQL脚本? - Is it possible to submit a CQL script to a cassandra cluster via the datastax driver? 如何使用datastax java驱动程序有效地使用批量写入cassandra? - How to efficiently use Batch writes to cassandra using datastax java driver? Cassandra:使用 DataStax Java 驱动程序选择一系列 TimeUUID - Cassandra: Selecting a Range of TimeUUIDs using the DataStax Java Driver 如何在Cassandra中使用datastax java驱动程序有效地使用准备好的语句? - How to use prepared statement efficiently using datastax java driver in Cassandra?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM