您的位置:首页 > 编程语言 > Python开发

<Jupyter Notebook>如何用一台服务器给多个 Jupyter 用户提供服务

2017-07-14 11:22 6025 查看
如题,搭了一个  spark 集群,在 master 上安装了 jupyter notebook. 随后发现团队有多个人想在 master 上用 jupyter 操作,又不方便大家用一个账户,于是就创建了多个账户.

方法很简单:

jupyter notebook 命令有一个 --config <config_file_path> 的可选参数,默认使用当前目录下的 jupyter_notebook_config.py,可填入 绝对路径 指定配置文件。

只要给每个用户写一个配置文件(至少端口、工作目录的配置要不同),然后分别运行 jupyter notebook --config jupyter_notebook_config_username.py 即可。

实例

文件目录:[root@master .jupyter]# ls
jupyter_notebook_config_hs.py jupyter_notebook_config.py jupyter_notebook_config.py.bak jupyter_notebook_config_zq.py migrated
其中 jupyter_notebook_config.py 是第一个用户的配置文件,jupyter_notebook_config_hs.py 是用户 hs 的配置文件,jupyter_notebook_config_zq.py 是用户 zq 的配置文件。
文件内容示例:

jupyter_notebook_config.py

1 # Configuration file for jupyter-notebook.
2 c = get_config()
3 c.IPKernelApp.pylab = 'inline'
4 c.NotebookApp.ip = '*'
5 c.NotebookApp.open_browser = False
6 c.NotebookApp.password = 'sha1:61c764d76b49:01e5f2ec3d6d0ba262b472281d025d3c4e1fe565'
7 c.NotebookApp.port = 6789
8 c.NotebookApp.notebook_dir = '/home/me/ipython'
执行 jupyter notebook & 或 jupyter note book --config /root/.jupyter/jupyter_note_book_config.py & 启动服务

客户端在浏览器上 通过 <ip地址>:6789 访问

jupyter_notebook_config_hs.py
1 # Configuration file for jupyter-notebook.
2 c = get_config()
3 c.IPKernelApp.pylab = 'inline'
4 c.NotebookApp.ip = '*'
5 c.NotebookApp.open_browser = False
6 c.NotebookApp.password = 'sha1:976bc4e3d0db:df5983c005e2d95c061426ba90c74086c57e76fd'
7 c.NotebookApp.port = 7777
8 c.NotebookApp.notebook_dir = '/home/hs/ipython'
执行 jupyter note book --config /root/.jupyter/jupyter_note_book_config_hs.py & 启动服务

客户端在浏览器上 通过 <ip地址>:7777 访问

至此,该服务器就可以给多个端口、密码不同的 jupyter notebook 用户使用了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐