如何远程启动IPython笔记本?

3

按照以下说明(运行笔记本服务器通过SSH远程访问IPython Notebooks),我进行如下操作:

在远程服务器上:

1) 设置NotebookApp.password()

In [1]: from IPython.lib import passwd
In [2]: passwd()    
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

2) 创建个人档案

user@remote_host$ ipython profile create 

3) 编辑~/.ipython/profile_default/ipython_notebook_config.py

# Password to use for web authentication
c = get_config()
c.NotebookApp.password =
u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

4) 在8889端口启动笔记本

user@remote_host$ ipython notebook --no-browser --port=8889

笔记本电脑启动

[I 16:08:10.012 NotebookApp] 使用CDN的MathJax:https://cdn.mathjax.org/mathjax/latest/MathJax.js

[W 16:08:10.131 NotebookApp] 终端不可用(错误为无模块命名'terminado')

[I 16:08:10.132 NotebookApp] 从本地目录/cluster/home/user提供笔记本

[I 16:08:10.132 NotebookApp] 0个活动内核

[I 16:08:10.132 NotebookApp] IPython笔记本正在运行:http://localhost:8889/

[I 16:08:10.132 NotebookApp] 使用Control-C停止此服务器并关闭所有内核(两次跳过确认)。

在我的本地机器上

5) SSH隧道

 user@local$ ssh -N -f -L localhost:8888:127.0.0.1:8889 username@remote_host

在远程主机(/etc/hosts)中,您会找到以下内容

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

6) 最后,我尝试在浏览器上打开localhost:8888,但是出现了以下错误:

channel 2: open failed: connect failed: Connection refused

channel 2: open failed: connect failed: Connection refused

channel 2: open failed: connect failed: Connection refused

channel 2: open failed: connect failed: Connection refused

channel 2: open failed: connect failed: Connection refused

这些步骤在一个服务器上可行,但在另一个服务器上失败。

我试着联系管理员并告知以下信息:

我假设您使用了两个独立的SSH连接:一个用于运行ipython,一个用于端口转发。无法保证这两个连接都会登陆到相同的登录节点。如果这两个连接在不同的主机上,那么您将遇到确切的故障。因此,您应该在用于运行ipython的连接中设置端口转发。

如何在用于运行ipython的连接中设置端口转发?

我尝试使用我的IP地址,但它没有起作用。

$ ssh -N -f -L local_ip_address:8888:127.0.0.1:8889 user@remote_host
2个回答

5
最终问题的解决方法如下:
# Login to the server from your local workstation and in the same connection do the port forwarding.
user@local$ ssh -L 8888:localhost:8889 username@remote_host
user@remote_host$ ipython notebook --no-browser --port=8889

最后一行应该是:user@remote_host$ ipython notebook --no-browser --port=8888这样对我来说就可以了。 - DerekC


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接