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

本文介绍如何在Spark集群的Master节点上为多个用户提供独立的Jupyter Notebook服务。通过配置不同的端口、工作目录及密码,确保每位用户都能拥有个性化的交互式计算环境。

如题,搭了一个  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 用户使用了

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值