配置 jupyter notebook遠程訪問
- 2019 年 12 月 5 日
- 筆記
默認情況下,安裝好 Jupyter之後,可以用 localhost:8888 即可。但是如果要需要遠程訪問,默認是不支援101.101.101.101:8888 這樣的訪問,需要額外配置。
設置 jupyter notebook 可遠程訪問的官方指南在這裡,在遠端伺服器上執行以下操作:
生成配置文件
默認情況下,配置文件 ~/.jupyter/jupyter_notebook_config.py
並不存在,需要自行創建。使用下列命令生成配置文件:
jupyter notebook --generate-config
執行成功後,會出現下面的資訊:
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
生成密碼
從jupyter notebook 5.0 版本開始,提供了一個命令來設置密碼:jupyter-notebook password
,生成的密碼存儲在 jupyter_notebook_config.json
。
(v3.5.3) [root@de jupyter]# jupyter-notebook password Enter password: Verify password: [NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json
運行jupyter
- 終端運行
jupyter-notebook --ip=0.0.0.0 --port 8000 --no-browser
- 後台運行
nohup jupyter-notebook --ip=0.0.0.0 --port 8000 --no-browser &
報錯解決
報錯:如果是以root用戶運行jupyter notebook的,會出現錯誤提示:
Running as root is not recommended. Use --allow-root to bypass.
解決:
vim /root/.jupyter/jupyter_notebook_config.py 85 #c.NotebookApp.allow_root = False 86 c.NotebookApp.allow_root = True