DKM*_*gin 2 python ssh google-cloud-platform jupyter-notebook google-colaboratory
我正在尝试将 Google colab 上的 jupyter notebook 连接到 GCP EC2 实例上的运行时。我按照这个 colab doc 说明链接
采取的步骤:
在我的本地设置 Jupyter 服务器
pip install jupyter_http_over_ws && jupyter serverextension enable --py jupyter_http_over_ws
jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0
Run Code Online (Sandbox Code Playgroud)
在 GCP 上创建并启动 EC2 实例
SSH 到 EC2 实例并使用以下方法转发本地端口:
gcloud beta compute ssh --zone "europe-west2-c" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
Run Code Online (Sandbox Code Playgroud)
尝试转发端口的错误消息:
bind [127.0.0.1]:8888: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8888
Could not request local forwarding.
Run Code Online (Sandbox Code Playgroud)
我还尝试将 ec2 实例直接连接到 colab,但我无法连接。对于最后一步,我假设将 Jupyter url 复制到 colab 本地运行时。我怎样才能解决这个问题?
我想到了。
脚步:
启动实例
连接到实例并将远程实例上的端口转发到本地机器
gcloud beta compute ssh --zone "<zone>" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
Run Code Online (Sandbox Code Playgroud)
如果您尚未在远程实例上安装 jupyter notebook 和 jupyter_http_over_ws,请安装它。
然后启用jupyter_http_over_ws:
jupyter serverextension enable --py jupyter_http_over_ws
Run Code Online (Sandbox Code Playgroud)
在远程实例上启动 Jupyter 服务器
jupyter notebook \
--NotebookApp.allow_origin='https://colab.research.google.com' \
--port=8888 \
--NotebookApp.port_retries=0
Run Code Online (Sandbox Code Playgroud)
将服务器 url 复制到 colab