无法打开给定的 URL 来访问在 GCP VM 中运行的 Jupiter 笔记本

问题描述 投票:0回答:1

我在 python GCP VM 中运行 ML 模型,结果(可视化)存储在 jupyter 笔记本中。因此,我将 jupyter 笔记本安装到 ubuntu 虚拟机,并使用

jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser
命令从相关位置运行 jupyter。它给出了这个输出


  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|
                       
Read the migration plan to Notebook 7 to learn about the new features and the actions to take if you are using extensions.

https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html

Please note that updating to Notebook 7 might break some of your extensions.

[I 14:16:46.732 NotebookApp] Registered dataproc_jupyter_plugin server extension
jupyter_http_over_ws extension initialized. Listening on /http_over_websocket
[W 14:16:47.328 NotebookApp] Loading JupyterLab as a classic notebook (v6) extension.
[C 14:16:47.328 NotebookApp] You must use Jupyter Server v1 to load JupyterLab as notebook extension. You have v2.12.5 installed.
    You can fix this by executing:
        pip install -U "jupyter-server<2.0.0"
[I 14:16:47.406 NotebookApp] [Jupytext Server Extension] Deriving a JupytextContentsManager from LargeFileManager
[I 14:16:47.628 NotebookApp] [nb_conda] enabled
[C 14:16:47.676 NotebookApp] You must use Jupyter Server v1 to load nbdime as a classic notebook server extension. You have v2.12.5 installed.
    You can fix this by executing:
        pip install -U "jupyter-server<2.0.0"
[I 14:16:47.678 NotebookApp] Serving notebooks from local directory: current_terminal_location
[I 14:16:47.678 NotebookApp] Jupyter Notebook 6.5.6 is running at:
[I 14:16:47.678 NotebookApp] http://base_url:8888/?token=token_value
[I 14:16:47.678 NotebookApp]  or http://#.#.#.#:8888/?token=token_value
[I 14:16:47.678 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:16:47.681 NotebookApp] 
    
    To access the notebook, open this file in a browser:
        file:///path_to_jupyter_runtime/nbserver-684890-open.html
    Or copy and paste one of these URLs:
        http://base_url:8888/?token=token_value
     or http://#.#.#.#:8888/?token=token_value

无论如何,当我尝试访问给定的链接时:

http://base_url:8888/?token=token_value
     or http://#.#.#.#:8888/?token=token_value

jupytor 笔记本未加载,浏览器显示无法访问该页面

我做了两件事

  1. 我通过以下方式在 VPC 网络 > 防火墙规则中添加了防火墙策略:
  • 单击“创建防火墙规则”。
  • 设置以下内容:
  • 名称:Allow-Jupyter
  • 目标:网络中的所有实例
  • 源 IP 范围:0.0.0.0/0
  • 允许的协议和端口:tcp:8888
  • 点击“创建”。
  1. 在VM中我遵循了here中提到的内容 为我想要运行 jupyter 的端口添加防火墙规则(例如 8888)
    jupyter notebook --generate-config
    确保使用
     在位置 
    jupyter_notebook_config.py
     生成 
    /.jupyter/jupyter_notebook_config.py
  2. 文件

sudo vi /home/user_name/.jupyter/jupyter_notebook_config.py

在 vi 编辑器中添加了以下几行

c.NotebookApp.ip = '*'

c.NotebookApp.open_browser = False

c.NotebookApp.port = 8888

通过 esc + :wq 命令退出 vi 编辑器

然后运行相同的命令

jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser

没有什么新的,相同的结果 我错过了什么

google-cloud-platform jupyter-notebook virtual-machine port firewall
1个回答
0
投票

尝试访问 Jupyter Notebook 时,将 URL 中的 base_url 和 token_value 替换为实际值。 base_url应该是您虚拟机的外部IP,token_value是启动Jupyter笔记本时生成的令牌。

© www.soinside.com 2019 - 2024. All rights reserved.