scala - 指定 hbase-site.xml 进行 spark-submit

标签 scala apache-spark hbase

我有一个 spark 作业(用 Scala 编写),它从在另一台服务器上找到的 HBase 表中检索数据。为了做到这一点,我首先创建了 HBaseContext像这样:val hBaseContext:HBaseContext = new HBaseContext(sparkContext, HBaseConfiguration.create())
当我运行 spark 作业时,我使用 spark-submit 并指定所需的参数。像这样的东西:

spark-submit  --master=local[*] --executor-memory 4g --executor-cores 2 --num-executors 2 --jars $(for x in `ls -1 ~/spark_libs/*.jar`; do readlink -f $x; done | paste -s | sed -e 's/\t/,/g') --class com.sparksJob.MyMainClass myJarFile.jar "$@"

问题是它连接到本地主机上的zookeeper,但是我希望它连接到另一台服务器(HBase所在的服务器)上的zookeeper。

硬编码此信息有效:
val configuration: Configuration = new Configuration()
configuration.set("hbase.zookeeper.quorum", "10.190.144.8")
configuration.set("hbase.zookeeper.property.clientPort", "2181")
val hBaseContext:HBaseContext = new HBaseContext(sparkContext, HBaseConfiguration.create(configuration))

但是,我希望它可配置。

如何指定 spark-submit 要使用的 hbase-site.xml 文件的路径?

最佳答案

您可以将 hbase-site.xml 作为 --files 选项的参数传递。你的例子会变成:

spark-submit  --master yarn-cluster --files /etc/hbase/conf/hbase-site.xml --executor-memory 4g --executor-cores 2 --num-executors 2 --jars $(for x in `ls -1 ~/spark_libs/*.jar`; do readlink -f $x; done | paste -s | sed -e 's/\t/,/g') --class com.sparksJob.MyMainClass myJarFile.jar "$@"

注意 master 设置为 yarn-cluster。任何其他选项都会使 hbase-site.xml 被忽略。

关于scala - 指定 hbase-site.xml 进行 spark-submit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39494527/

相关文章:

eclipse - 用于 Eclipse 的 Scala IDE : Any way to "quickfix" imports?

scalafx + intellij : NoClassDefFoundError: javafx/scene/shape/CullFace

scala - 为什么会出现Conflicting cross-version suffixes的错误?

scala - 反序列化后 DateTime 不等于自身

python - 无法在 PySpark 中创建数据框

apache-spark - spark2 + yarn - 准备 AM 容器时出现空指针异常

java - HBase 在运行时给出 "JAVA_HOME is not set"

scala - 如何将一组 RelationalGroupedDataset 传递给函数?

java - Hbase 扫描正在返回已删除的行

java - 用Pig将二进制文件存储到hbase