jupyter部署和端口转发 - peter-xbs/CommonCodes GitHub Wiki

远端Jupyter运行前配置

jupyter-notebook --generate-config

将生成~/.jupter/jupyter_notebook_config.py文件

执行编辑

c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port=8889
c.NotebookApp.allow_remote_access = True

jupyter-notebook password 设置密码

jupyter设置虚拟环境

激活虚拟环境

  • 执行安装Ipykernel
pip install ipykernel ipython
  • 虚拟环境命名(显示在jupyter页面的名称)
ipython kernel install --user --name xxx
  • 虚拟环境删除(将从Jupyter中移除显示)
jupyter kernelspec remove pytorch1.6

远端jupyter运行

jupyter-notebook --allow-root

本地ssh命令实现端口转发

# ssh -L local-port:target-host:target-port tunnel-host 

输入远端ECS密码即可 或者使用下图更友好的方式建立一个shell脚本运行进行转发

#!/usr/bin/expect

spawn ssh -N -f -L localhost:port_local:localhost:port_server user@host

expect "assword:"

send "xxx\r"

interact

含跳板机的端口转发

HOST-A(local) --> Host-B(jump server) --> Host-C(GPU server) 在本地终端运行下述命令即可打通隧道:

ssh -L<Port-A>:localhost:<Port-B> user@Host-B -t ssh -L<Port-B>:localhost:<Port-C> user@Host-C

或者vscode可以链通情况下也可

⚠️ **GitHub.com Fallback** ⚠️