将 IPython notebook 连接到不同机器中的 spark master 运行

Connecting IPython notebook to spark master running in different machines

我不知道这是否已在 SO 中得到解答,但我找不到解决我的问题的方法。

我在 Google 容器引擎的 docker 容器中有一个 IPython 笔记本 运行,该容器基于此映像 jupyter/all-spark-notebook

我还有一个用 google cloud dataproc

创建的 spark 集群

Spark master 和 notebook 运行 在 不同的 VM 但在 相同的区域和区域.

我的问题是我试图从 IPython 笔记本连接到 spark master 但没有成功。我在 python notebook

中使用了这段代码
import pyspark
conf = pyspark.SparkConf()
conf.setMaster("spark://<spark-master-ip or spark-master-hostname>:7077")

我刚开始使用 spark,所以我确定我遗漏了一些东西(身份验证、安全......),

我在那里发现的是通过 SSH tunnel

连接本地浏览器

有人做过这种设置吗?

提前致谢

Dataproc 将 Spark on YARN, so you need to set master to 'yarn-client'. You also need to point Spark at your YARN ResourceManager, which requires a under-documented SparkConf -> Hadoop Configuration conversion. You also have to tell Spark about HDFS on the cluster, so it can stage resources for YARN. You could use Google Cloud Storage instead of HDFS, if you baked The Google Cloud Storage Connector for Hadoop 运行到您的图像中。

尝试:

import pyspark
conf = pyspark.SparkConf()
conf.setMaster('yarn-client')
conf.setAppName('My Jupyter Notebook')

# 'spark.hadoop.foo.bar' sets key 'foo.bar' in the Hadoop Configuaration.
conf.set('spark.hadoop.yarn.resourcemanager.address', '<spark-master-hostname>')
conf.set('spark.hadoop.fs.default.name', 'hdfs://<spark-master-hostname>/')

sc = pyspark.SparkContext(conf=conf)

对于更永久的配置,您可以将它们烘焙到本地文件 'core-site.xml' 中,如 here 所述,将其放在本地目录中,然后将 HADOOP_CONF_DIR 设置为该目录你的环境。

还值得注意的是,虽然位于同一区域对性能很重要,但位于同一区域 Network and allowing TCP between internal IP addresses in that network that allows your VMs to communicate. If you are using the default network, then the default-allow-internal firewall rule 应该就足够了。

希望对您有所帮助。