配置jupyter notebook本地与局域网访问
1. 本机运行
终端上输入命令:
jupyter notebook
输出:
------------------------------------------------------------------------------------------------
[I 04:05:09.197 NotebookApp] Writing notebook server cookie secret to /home/userroot/.local/share/jupyter/runtime/notebook_cookie_secret
[I 04:05:09.505 NotebookApp] JupyterLab extension loaded from /home/userroot/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 04:05:09.505 NotebookApp] JupyterLab application directory is /home/userroot/anaconda3/share/jupyter/lab
[I 04:05:09.507 NotebookApp] Serving notebooks from local directory: /home/userroot
[I 04:05:09.508 NotebookApp] Jupyter Notebook 6.1.4 is running at:
[I 04:05:09.508 NotebookApp] http://localhost:8888/?token=da77aa247503b1dc2f2d48e624f9c5430b33cd5d3c4a3054
[I 04:05:09.508 NotebookApp] or http://127.0.0.1:8888/?token=da77aa247503b1dc2f2d48e624f9c5430b33cd5d3c4a3054
[I 04:05:09.508 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 04:05:09.515 NotebookApp] No web browser found: could not locate runnable browser.
[C 04:05:09.516 NotebookApp]
To access the notebook, open this file in a browser:
file:///home/userroot/.local/share/jupyter/runtime/nbserver-8495-open.html
Or copy and paste one of these URLs:
http://localhost:8888/?token=da77aa247503b1dc2f2d48e624f9c5430b33cd5d3c4a3054
or http://127.0.0.1:8888/?token=da77aa247503b1dc2f2d48e624f9c5430b33cd5d3c4a3054
------------------------------------------------------------------------------------------------
本机运行,根据上面提示的网址,输入到浏览器就行。
2. 配置 使用Jupyter notebook远程登录
1) 生成配置文件
输入如下命令:
jupyter notebook --generate-config
输出:
Writing default config to: /home/userroot/.jupyter/jupyter_notebook_config.py
2)生产密码
打开IPython
ipython
ython 3.8.5 (default, Sep 4 2020, 07:30:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
输入密码:和系统登录密码一样
In [3]: from notebook.auth import passwd
In [4]: passwd()
Enter password:
Verify password:
Out[4]: 'argon2:**********************************'****
牢记上面输出的秘钥,可以复制到文本中保存。
退出iPython.
3)修改默认配置文件
修改上一步生产的配置文件.
在终端中输入:
sudo vim /home/userroot/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = 0.0.0.0
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'argon2:********
c.NotebookApp.port = 9999
如果没有vim编辑器,请自行安装。
在vim中查找c.NotebookApp的各项内容,并取消注释后,设置IP和密码(上一步复制保存的密码),端口号,如上。
4)启动jupyter notebook
在终端中输入:
jupyter notebook /home/userroot/.jupyter/jupyter_notebook_config.py –allow-root
5)在远程客户机浏览器输入目标服务器的IP和端口号
192.168.50.33.9999
在页面中输入服务器登录密码,即可。
服务器上显示:
[I 04:35:36.045 NotebookApp] JupyterLab extension loaded from /home/userroot/anaconda3/lib/python3.8/site-packages/jupyterlab
[I 04:35:36.045 NotebookApp] JupyterLab application directory is /home/userroot/anaconda3/share/jupyter/lab
[I 04:35:36.047 NotebookApp] Serving notebooks from local directory: /home/userroot/.jupyter
[I 04:35:36.047 NotebookApp] Jupyter Notebook 6.1.4 is running at:
[I 04:35:36.047 NotebookApp] http://blq219:9999/
[I 04:35:36.047 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 04:35:36.055 NotebookApp] No web browser found: could not locate runnable browser.
[I 04:39:52.932 NotebookApp] 302 GET / (192.168.50.240) 1.62ms
[I 04:39:52.945 NotebookApp] 302 GET /tree? (192.168.50.240) 0.93ms
[I 04:40:16.567 NotebookApp] 302 POST /login?next=%2Ftree%3F (192.168.50.240) 41.18ms
显示登录成功。
6)查看当前运行的jupyter notebook
jupyter notebook list
Currently running servers:
http://0.0.0.0:9999/ :: /home/userroot/.jupyter
配置完成!Very happy!