美文网首页
jupyter notebook+Spark配置远程登录服务器

jupyter notebook+Spark配置远程登录服务器

作者: foochane | 来源:发表于2019-04-27 15:24 被阅读0次

    1 配置远程登录服务器上的jupyter notebook

    1.1 安装jupyter notebook

    安装Anaconda,就已经自动jupyter notebook,没有的话自己从新安装。

    1.2 生成密码

    进入shell,按如下内容进行输入

    $ ipython
    In [1]: from IPython.lib import passwd
    In [2]: passwd()
    Enter password: #输入远程登陆时的密码(服务器密码)
    Verify password: #确认密码
    Out[2]: 'sha1:0exxxxxxxxxxxxxxxxxx3999xxx2d856'
    

    1.3 生成mycert.pem

    输入

    $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
    

    填入相关信息,生成mycert.pem文件

    1.4 配置jupyter notebook

    生成配置文件

    $ jupyter-notebook --generate-config
    

    修改~/.jupyter/jupyter_notebook_config.py文件:

    c.NotebookApp.password = u'sha1:' #刚刚生成的SHA密钥
    c.NotebookApp.certfile = u'/home/hadoop/.jupyter/mycert.pem' #mycert.pem文件位置
    c.NotebookApp.ip = 'Master' #本机ip
    c.NotebookApp.port = 9999 #端口
    

    1.5 本地登录

    在服务器输入:

    $ jupyter notebook --ip=Master --no-browser --allow-root
    

    之后会打印访问链接,输入到本地浏览器打开即可。

    2 Jupyter连接pyspark

    在服务器端,添加的~/.bashrc文件中添加如下环境变量:

    #py-spark
    export PYTHONPATH=/usr/local/bigdata/spark/python:$PYTHONPATH #pythonpath指向spark目录下的python文件夹
    export PYTHONPATH=/usr/local/bigdata/spark/python/lib/py4j-0.10.7-src.zip:$PYTHONPATH# 指向py4j包,没有的话下载一个
    export PYSPARK_PYTHON=python3 #使用python3
    export PYSPARK_DRIVER_PYTHON=jupyter 
    export PYSPARK_DRIVER_PYTHON_OPTS="notebook --ip=Master --no-browser --allow-root" 
    

    $ source ~/.bashrc 使其生效。

    在服务器终端中输入

    $ pyspark
    

    之后同样会打印出访问链接,输入到本地浏览器访问即可。

    相关文章

      网友评论

          本文标题:jupyter notebook+Spark配置远程登录服务器

          本文链接:https://www.haomeiwen.com/subject/utdknqtx.html