具有的Apache Cassandra的版本的全新安裝3.7datastax卡桑德拉的Java NoHostAvailableException
安裝成功,我可以用任何問題訪問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。
下面是示例代碼我試圖在控制檯
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"
其他系統細節
[[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.Kindly讓我知道我在哪裏錯了?
你在虛擬機上運行C *並試圖從該虛擬機之外運行你的代碼?運行'netstat -anp | grep 9042'在主機上運行你的代碼。 –
不是C *和代碼都在同一個VM中 – user3619698
run'netstat -anp | grep 9042'在開始應用之前給出輸出 –