2017-08-10 13 views
0

は3.7datastaxカサンドラのJava NoHostAvailableException

インストールが成功したのApache Cassandraのバージョンの新規インストールを持っていたと私はすべての問題アウトでcqlshにアクセスすることができます。

[[email protected] bin]$ cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.7 | CQL spec 3.4.2 | Native protocol v4]

しかし、DataStax Cassandraクライアントで接続しようとすると、NoHostAvailableExceptionが発生します。ここ

iは、以下に示すコンソールの

import com.datastax.driver.core.*; 
public class DBHitTEst { 
public static void main(String[] args) throws Exception { 
    // TODO Auto-generated method stub 
    Session session = null; 
    Cluster cluster = Cluster.builder() 
      .addContactPoints("127.0.0.1").withPort(9042) 
      .build(); 
    System.out.println("Connecting to cluster ..."); 
    session = cluster.connect(); 
    System.out.print("Connected !"+session); 
}} 

例外を試みたサンプルコードです。

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Connecting to cluster ... Aug 10, 2017 7:58:23 AM io.netty.channel.ChannelInitializer channelRegistered WARNING: Failed to initialize a channel. Closing: [id: 0x7d2724c5] java.lang.NoSuchMethodError: io.netty.util.AttributeKey.valueOf(Ljava/lang/String;)Lio/netty/util/AttributeKey; at com.datastax.driver.core.Message.(Message.java:39) at com.datastax.driver.core.Connection$Initializer.initChannel(Connection.java:1425) . . . Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:9042] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:232) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79) at com.datastax.driver.core.Cluster$Manager.negotiateProtocolVersionAndConnect(Cluster.java:1600) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1518) at com.datastax.driver.core.Cluster.init(Cluster.java:159) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:305) at com.datastax.driver.core.Cluster.connect(Cluster.java:247) at com.cassandra.db.executables.DBHitTEst.main(DBHitTEst.java:14)

ライブラリ

cassandra-driver-core-3.3.0.jar 
guava-23.0.jar 
log4j-api-2.8.2.jar 
metrics-core-3.0.2.jar 
netty-all-4.0.9.Final.jar 
slf4j-api-1.7.25.jar 

重要なのconfigsを参照しcassandra.yaml

start_rpc: false 
start_native_transport: true 
native_transport_port: 9042 
rpc_address: localhost 
rpc_port: 9160 
listen_address: localhost 
seeds: "127.0.0.1" 

その他のシステム細目

です0
[[email protected] conf]$ hostname 
LOGDPM01 

[[email protected] conf]$ more /etc/hosts 
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 
::1   localhost localhost.localdomain localhost6 localhost6.localdomain6 

[[email protected] conf]$ ping LOGDPM01 
PING LOGDPM01 (10.0.2.15) 56(84) bytes of data. 
64 bytes from LOGDPM01 (10.0.2.15): icmp_seq=1 ttl=64 time=0.055 ms 

centos VMを実行しています。私はどこが間違っているか教えてください。

+0

VMでC *を実行していて、そのVMの外からコードを実行しようとしていますか? 'netstat -anp |を実行します。あなたのコードを実行しているホスト上でgrep 9042'を実行します。 –

+0

C *とコードの両方が同じVMにありません – user3619698

+0

run 'netstat -anp |アプリケーションを起動する前に "grep 9042'を実行して出力してください –

答えて

0

ライブラリーのミスマッチがコンソールに表示されたという警告を投げていました。

WARNING: Failed to initialize a channel. Closing: [id: 0x7d2724c5] java.lang.NoSuchMethodError: io.netty.util.AttributeKey.valueOf(Ljava/lang/String;)Lio/netty/util/AttributeKey; at com.datastax.driver.core.Message.(Message.java:39) at com.datastax.driver.core.Connection$Initializer.initChannel(Connection.java:1425) . . .

Cassandraインストールのlibフォルダから正しいライブラリを選択すると、問題が直接ソートされました。

関連する問題