Jupyter notebook SSH 隧道错误“无法打开签名数据库”

Posted

技术标签:

【中文标题】Jupyter notebook SSH 隧道错误“无法打开签名数据库”【英文标题】:Jupyter notebook SSH Tunneling error "The signatures database cannot be opened" 【发布时间】:2019-08-10 06:27:52 【问题描述】:

我的大学有一台 Linux 机器,校园里运行着强大的 Jupyter。以下是我通过 Windows 笔记本电脑登录远程服务器并在服务器上运行 Jupyter notebook 的步骤,可以通过 ssh 隧道在本地浏览器上进行编辑,但它总是给我同样的错误:

    在远程服务器上安装 anaconda 和 Jupyter 创建我的环境并激活它

    对于 SSH 隧道,以下是我在 CMD 上连接到远程服务器的方式:

    Ssh –L 8000(on my laptop):localhost:8889(on remote server) <MyUserID>@<RemoteServerIP>
    

    之后它会询问我的密码,然后我进入远程服务器

    要激活 anaconda,我使用以下命令:

    source $HOME/anaconda3/bin/activate 
    

    进入anaconda后,激活我的环境:

    conda activate <env_name>
    

    进入环境后,启动jupyter notebook,我输入:

    jupyter notebook
    

    jupyter notebook --no-browser --port=8889 
    

    然后显示:

    [I 09:04:06.122 NotebookApp] Writing notebook server cookie secret to /run/user/148037468/jupyter/notebook_cookie_secret
    [I 09:04:06.881 NotebookApp] Serving notebooks from local directory: <directoryname>
    [I 09:04:06.881 NotebookApp] The Jupyter Notebook is running at:
    [I 09:04:06.881 NotebookApp] http://localhost:8889/
    [I 09:04:06.881 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [I 09:05:10.507 NotebookApp] 302 GET / (::1) 1.43ms
    

    然后在我的笔记本电脑上输入:

    localhost:8000
    

    它会将我重定向到登录页面,在该页面中我成功地在 jupyter notebook 中看到了我的目录,然后我点击了一个 .ipynb 文件

    在这一步之后,它永远不会加载笔记本并在笔记本上显示以下错误:

    无法建立到笔记本服务器的连接。笔记本电脑将继续尝试重新连接。检查您的网络连接或笔记本服务器配置。

它在终端上给出以下错误:

The signatures database cannot be opened; maybe it is corrupted or encrypted. You may need to rerun your notebooks to ensure that they are trusted to run javascript. The old signatures database has been renamed to <directory_name>.local/share/jupyter/nbsignatures.db.bak and a new one has been created.
[W 09:17:35.807 NotebookApp] Failed commiting signatures database to disk. 
You may need to move the database file to a non-networked file system, using config option `NotebookNotary.db_file`. Using in-memory signatures database for the remainder of this session.
[W 09:17:35.811 NotebookApp] Notebook plots1.ipynb is not trusted
[W 09:17:35.881 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20190319090406 (::1) 17.39ms referer=http://localhost:8000/notebooks/plots1.ipynb
[I 09:17:36.430 NotebookApp] Kernel started: 242b529a-5acd-4b5f-8a6d-356947ab30d2
[W 09:18:36.467 NotebookApp] Timeout waiting for kernel_info reply from 242b529a-5acd-4b5f-8a6d-356947ab30d2
/<directory_name>/anaconda3/envs/braingrid/lib/python3.6/site-packages/notebook/base/zmqhandlers.py:284: RuntimeWarning: coroutine 'WebSocketHandler.get' was never awaited
super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
[W 09:18:38.276 NotebookApp] Replacing stale connection: 242b529a-5acd-4b5f-8a6d-356947ab30d2:dd09ca5465ba404a886c71b3ca787d6b
[W 09:21:36.370 NotebookApp] Notebook plots1.ipynb is not trusted

[IPKernelApp] ERROR | Failed to open SQLite history /<directory_name>/.ipython/profile_default/history.sqlite (database is locked).
[IPKernelApp] ERROR | History file was moved to /<directory_name>/.ipython/profile_default/history-corrupt.sqlite and a new file created.

Jupyter notebook 不断显示:

"Connecting to terminal"

我不知道如何解决这个问题。我是 Linux 新手。 sudo 命令都不起作用,因为我不是管理员/ 或拥有这些权限

我的论文需要这个设置。

【问题讨论】:

您能否编辑帖子并确保它具有换行符、格式等以使其更具可读性 【参考方案1】:

这可能是问题所在:您的笔记本存储了签名 (https://jupyter-notebook.readthedocs.io/en/stable/security.html),它告诉浏览器在打开笔记本时是否信任任何 javascript 和 html。它将这些存储在 SQLite 数据库中。如果这个数据库文件在 NFS 上,似乎会出现锁定问题:

Locking sqlite file on NFS filesystem possible? https://github.com/ipython/ipython/issues/9003。

因此,可以将文件移动到服务器上的本地文件夹,并将NotebookNotary.db_file 指向那里。

【讨论】:

以上是关于Jupyter notebook SSH 隧道错误“无法打开签名数据库”的主要内容,如果未能解决你的问题,请参考以下文章

[ 隧道技术 ] 利用 Cpolar 远程 Jupyter Notebook(公网远程访问内网 Jupyter 服务器)

jupyter notebook开启局域网登录

使用 SSH 隧道通过 Bastion 访问在 EC2 上运行的 Jupyter 服务器

从 SSH 运行 Jupyter Notebook 到远程服务器节点

当我的 jupyter notebook 越来越大时,VScode ssh 连接中断

如何使用 ssh 和 Serveo.Net 访问公共 Internet 上的 Jupyter Notebook?