java.io.IOException: 在127.0.0.1:9042处打开连接到Cassandra的本地连接失败。

问题描述 投票:0回答:1

I 找到一个类似的帖子 但它没有帮助。

我已经使用Cassandra工作了一段时间,现在我正在尝试设置spark和spark-cassandra-connector。我正在使用IntelliJ IDEA来做这件事(第一次使用IntelliJ IDEA和Scala,所以,你懂的)。

我的操作系统是Windows 10。这是我所做的。

Inside .spark-2.4.5-bin-hadoop2.7bin。: spark-class.cmd org.apache.spark.deploy.master.Master

内部 .spark-2.4.5-bin-hadoop2.7bin。: spark-class.cmd org.apache.spark.deploy.worker.Worker -c 1 spark://192.168.0.3:7077

build.gradle

apply plugin: 'scala'
apply plugin: 'idea'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

idea {
    project {
        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

dependencies {
    compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.4.5'
    compile group: 'org.apache.spark', name: 'spark-sql_2.11', version: '2.4.5'
    compile group: 'org.scala-lang', name: 'scala-library', version: '2.11.11'
    compile group: 'com.datastax.spark', name: 'spark-cassandra-connector_2.11', version: '2.4.0'
}

configurations.all {
    resolutionStrategy {
        force 'com.google.guava:guava:12.0.1'
    }
}

compileScala.targetCompatibility = "1.8"
compileScala.sourceCompatibility = "1.8"

SparkModule.scala

package org.sentinel.spark_module

import org.apache.spark.{SparkConf, SparkContext}
import com.datastax.spark.connector._

object SentinelSparkModule {
  def main(args: Array[String]) {
    val conf = new SparkConf().set("spark.cassandra.connection.host", "127.0.0.1")
      .set("spark.cassandra.connection.port", "9042")
      .setAppName("Sentinel").setMaster("spark://192.168.0.3:7077")

    val sc = new SparkContext(conf)
    val rdd = sc.cassandraTable("keyspace", "table")
    val values = rdd.groupBy((CassandraRow) => {
      @throws[Exception]
      def call(row: Nothing) = CassandraRow.getString("column")
    }).take(10).foreach(println)    
  }
}

即使发生了错误,我仍然可以看到应用程序运行在 http:/localhost:8080 直到我在IDE中停止执行。enter image description here

摘录完整的堆栈转储。

线程main中出现异常 java.io.IOException: 未能打开本地 在{127.0.0.1}:9042连接到Cassandra。

原因是:com.datastax.driver.core.exception.NoHostAvailableException。全部 尝试查询失败的主机(已尝试。127.0.0.1:9042 (com.datastax.driver.core.exceptions.OperationTimedOutException。 ([127.0.0.1:9042] 操作已超时))

最后,尽管它说已经超时了,但我在编码时也从我的web应用(node.js)中查询Cassandra,查询工作正常。所以,我不知道为什么会是Cassandra的问题,但是,我想可能是这样。

谢谢你

EDIT:

我加入了 compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '3.0.0' 和同样的错误。(版本兼容性表)

EDIT:

nodetool status 显示。

Datacenter: datacenter1
========================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load        Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  138.59 MiB  256          100.0%            77d808e6-5c57-494a-b6fb-7e73593dbb46  rack1

EDIT:

cqlsh 127.0.0.1 9042 显示:

WARNING: console codepage must be set to cp65001 to support utf-8 encoding on Windows platforms.
If you experience encoding problems, change your console codepage with 'chcp 65001' before starting cqlsh.

Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
WARNING: pyreadline dependency missing.  Install to enable tab completion.
cqlsh>
scala apache-spark cassandra datastax spark-cassandra-connector
1个回答
0
投票

Cassandra是否也运行在 192.168.0.3? 你有没有尝试改变 spark.cassandra.connection.host192.168.0.3 而不是?你看到这个错误的原因是由于你的Spark执行器不能连接到Cassandra,在 127.0.0.1. 我对你的设置一无所知,你可能已经试过了,但可能解决方案就是这么简单。

© www.soinside.com 2019 - 2024. All rights reserved.