(单用户/多用户)远程连接GPU服务器上的jupyter notebook解决方案
远程连接GPU服务器上的jupyter notebook
序言
——————
近期由于要跑一些cv方向的代码,自己的电脑GPU太垃圾,根本跑不动。正好实验室有GPU服务器,配了2块Nvidia Geforce RTX 2080 Ti。然后就涉及到需要在自己的笔记本上远程连接服务器上的jupyter notebook来使用GPU服务器上的算力。以下分为单用户和多用户的解决方案。
单用户就是1个账号上运行1个jupyter notebook服务,只需要分配一个端口;多用户就是你一个账号要开n个jupyter notebook服务,需要分配多个端口。
单用户连接jupyter notebook解决方案
以下操作均在GPU服务器上进行。
安装jupyter notebook
-
安装Anaconda3
bash Anaconda3-2019.10-Linux-x86_64.sh(需要去官网下载)
-
创建虚拟环境
conda create -n xxx python=3.7
-
**虚拟环境
conda actiavte xxx
-
安装jupyter notebook
conda install jupyter notebook
配置jupyter notebook远程
-
生成配置文件
jupyter notebook --generate-config(在虚拟环境里运行)
上述代码会在~/.jupyter下生成一个jupyter_notebook_config.py文件。
-
修改配置文件
vi ~/.jupyter/jupyter_notebook_config.py
修改内容:(记得去掉每行前面的’#’)
c.NotebookApp.ip='*' #表示同一网络的主机都可访问 c.NotebookApp.password = u'sha密文' c.NotebookApp.open_browser = False c.NotebookApp.port =8888 #随便指定一个端口(这个需要看是不是冲突)
sha密文生成方式。
In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]:'sha1:xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxx'
-
运行jupyter notebook
jupyter notebook(在虚拟环境内输入)
运行效果如下:
可见图中jupyter notebook是GPU服务器IP:8800
-
在浏览器输入GPU服务器IP:8800
多用户连接jupyter notebook解决方案
问题
多用户是在配置好上述单用户的情况下,比如我们还有另一个虚拟环境xxx2,这个环境我们也需要使用jupyter notebook,而且在很多情况下我们需要同时使用,因为有些代码是需要跑很长时间的。多个jupyter notebook意味着需要多个端口,也同时意味着需要多个配置文件。但是,我们上面只生成了一个配置文件,这该怎么办?
解决方案
-
复制单用户时的jupyter_notebook_config.py文件,并且命名为jpconfig.py,同时修改
端口号
,保证不冲突。cp ~/.jupyter/jupyter_notebook_config.py ~/.jupyter/jpconfig.py
-
在另一个虚拟环境内启动jupyter notebook时手动指定配置文件,否则会默认使用~/.jupyter/jupyter_notebook_config.py作为配置文件
jupyter notebook --config ~/.jupyter/jpconfig.py
-
在浏览器同时访问GPU服务器上的多个虚拟环境下的jupyter notebook.
GPU服务器IP:8800 GPU服务器IP:8900
效果如下图: