指定hbase-site.xml以spark-submit

Pet*_*scu 5 hbase scala apache-spark

我有一个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 "$@"
Run Code Online (Sandbox Code Playgroud)

问题是这连接到localhost上的zookeeper,但是我希望它连接到另一台服务器上的zookeeper(HBase所在的服务器).

硬编码此信息有效:

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))
Run Code Online (Sandbox Code Playgroud)

但是我希望它可以配置.

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

mga*_*ido 3

您可以将 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 "$@"
Run Code Online (Sandbox Code Playgroud)

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