访问远程服务器Jupyter Notebook的方法
平时办公有两台机器,一台笔记本,开会沟通时使用;一个是台式工作站,用于日常开发。现在的需求是从笔记本上访问台式工作站上的jupyter notebook。
默认情况下,notebook server运行在127.0.0.1:8888,只能从本机通过http://127.0.0.1:8888访问。但是notebook server自身提供了远程访问的能力。
配置远程访问的步骤如下:
1、生成默认配置文件
jupyter notebook --generate-config
该命令生成名称为jupyter_notebook_config.py的文件,在不同系统上默认路径如下:
Windows: C:\Users\USERNAME\.jupyter\jupyter_notebook_config.py OS X: /Users/USERNAME/.jupyter/jupyter_notebook_config.py Linux: /home/USERNAME/.jupyter/jupyter_notebook_config.py
2、生成访问密码
在终端输入ipython,并使用notebook.auth.security.passwd()生成密码。
In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'sha1:xxxxxxxxxxxxxxxxx'
3、修改jupyter_notebook_config.py文件
c.NotebookApp.ip='*' c.NotebookApp.password = 'sha1:xxxxxxxxxxxxxxxxx' c.NotebookApp.open_browser = False c.NotebookApp.port =8888 #可自行指定一个端口, 访问时使用该端口
上述字段在jupyter_notebook_config.py都有,只是被注释掉了。手动去掉这些注释,然后修改对应的字段值。这里c.NotebookApp.password = ‘sha1:xxxxxxxxxxxxxxxxx’中的sha1:xxxxxxxxxxxxxxxxx是步骤2)中生成的密码。
4、在服务器上启动notebook server
jupyter notebook
5、在笔记本启动jupyter notebook
在笔记本浏览器上访问http://ip:8888/(ip是服务器的ip),然后就可以像访问本地文件一样直接使用了。
参考材料
https://www.jianshu.com/p/8fc3cd032d3c
https://jupyter-notebook.readthedocs.io/en/latest/public_server.html#notebook-server-security
除非注明,否则均为[半杯茶的小酒杯]原创文章,转载必须以链接形式标明本文链接