【问题标题】:Connect Google colab to a runtime on a Google Compute Engine instance将 Google colab 连接到 Google Compute Engine 实例上的运行时
【发布时间】:2020-09-06 02:06:08
【问题描述】:

我正在尝试将 Google colab 上的 jupyter notebook 连接到 GCP EC2 实例上的运行时。我遵循了这个 colab 文档说明Link

采取的步骤:

  • 在我的本地设置 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
    
  • 在 GCP 上创建并启动 EC2 实例

  • SSH 进入 EC2 实例并使用以下方式转发本地端口:

    gcloud beta compute ssh --zone "europe-west2-c" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
    

尝试转发端口的错误消息:

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.

我也尝试将 ec2 实例直接连接到 colab,但我无法做到。对于最后一步,我想将 Jupyter url 复制到 colab 本地运行时。我该如何解决这个问题?

【问题讨论】:

  • 如果你转发到本地主机上的不同端口怎么办?
  • 在关闭 jupyter 服务器后通过 SSH 连接到不同端口或同一端口上的实例有效。但我想要做的是将流量从 colab 转发到 jupyter 服务器到 ec2 实例。 @IgorRivin

标签: python ssh google-cloud-platform jupyter-notebook google-colaboratory


【解决方案1】:

我想通了。

步骤:

  • 启动实例

  • 连接到实例并将远程实例上的端口转发到本地机器

    gcloud beta compute ssh --zone "<zone>" "<ec2-instance-name>" --project "<project-name>" -- -L 8888:localhost:8888
    
  • 如果你没有安装 jupyter notebook 和 jupyter_http_over_ws 远程实例已经存在。

  • 然后启用jupyter_http_over_ws:

    jupyter serverextension enable --py jupyter_http_over_ws
    
  • 在远程实例上启动 Jupyter 服务器

    jupyter notebook \
     --NotebookApp.allow_origin='https://colab.research.google.com' \
     --port=8888 \
     --NotebookApp.port_retries=0
    
  • 复制服务器 url 到 colab

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 2017-01-23
    • 2018-08-15
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多