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

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

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
多用户连接远程服务器Jupyter Notebook可以通过以下步骤实现: 1. 在远程服务器上配置Jupyter Notebook,可以参考引用中的配置文件内容。将配置文件中的`c.NotebookApp.ip`设置为`'*'`,`c.NotebookApp.password`设置为生成的密码密文,`c.NotebookApp.port`设置为一个闲置端口,`c.NotebookApp.open_browser`设置为`False`,`c.NotebookApp.allow_remote_access`和`c.NotebookApp.allow_root`设置为`True`,`c.NotebookApp.notebook_dir`设置为根目录路径。 2. 在本地主机上打开一个终端或命令行窗口,输入以下命令连接远程服务器: ``` ssh -p remote_port remote_user@remote_ip ``` 其中,`remote_port`是远程服务器的SSH端口号,`remote_user`是远程服务器用户名,`remote_ip`是远程服务器的IP地址。 3. 在远程服务器的终端或命令行窗口中输入以下命令启动Jupyter Notebook: ``` jupyter notebook --no-browser --port=remote_port ``` 其中,`remote_port`是之前配置的Jupyter Notebook的端口号。 4. 在本地主机上打开一个新的终端或命令行窗口,输入以下命令建立本地与远程服务器的连接: ``` ssh -p remote_port remote_user@remote_ip -L127.0.0.1:local_port:127.0.0.1:remote_port ``` 其中,`remote_port`是远程服务器Jupyter Notebook的端口号,`local_port`是本地主机上的一个未使用的端口号。 5. 在本地浏览器中输入以下地址访问Jupyter Notebook: ``` 127.0.0.1:local_port ``` 其中,`local_port`是之前配置的本地主机的端口号。 6. 输入之前配置的密码密文,即可登录Jupyter Notebook并进行多用户连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值