指定hbase-site.xml以提交

t9eec4r0  于 2021-06-10  发布在  Hbase
关注(0)|答案(1)|浏览(386)

我有一个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 "$@"

问题是它连接到localhost上的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))

但是我希望它是可配置的。
如何指定要使用的hbase-site.xml文件的路径?

6uxekuva

6uxekuva1#

可以将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 "$@"

请注意主设置为“Yarn簇”。任何其他选项都会使hbase-site.xml被忽略。

相关问题