Linux上配置Jupyter Notebook遠程訪問(docker)
本身自己機器上安裝了太多東西,有點慢,本來也喜歡所有的東西搬到服務上,所以如果能安裝一個遠程的Jupyter 服務器,用起來就會很方便。
記錄下自己的安裝步驟
1. 安裝ipython, jupyter
pip install ipython
pip install jupyter
2. 生成配置文件
[root@50eb5057baac /]# jupyter notebook --generate-config
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
3. 生成密碼
root@50eb5057baac /]# ipython
Python 3.5.1 (default, Oct 21 2016, 21:37:19)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:43b95b731276:5d330ee6f6054613b3ab4cc59c5048ff7c70f549'
In [3]:
4. 修改默認配置文件
vi /root/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip=’*’ #設置訪問notebook的ip,*表示所有IP,這裏設置ip爲都可訪問
c.NotebookApp.password = u’sha1:5df252f58b7f:bf65d53125bb36c085162b3780377f66d73972d1’ #填寫剛剛生成的密文
c.NotebookApp.open_browser = False # 禁止notebook啓動時自動打開瀏覽器(在linux服務器一般都是ssh命令行訪問,沒有圖形界面的。所以,啓動也沒啥用)
c.NotebookApp.port =8889 #指定訪問的端口,默認是8888。
5.啓動jupyter notebook
[root@346086094cbe /]# jupyter notebook --allow-root
[W 17:17:04.106 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 17:17:04.111 NotebookApp] Serving notebooks from local directory: /
[I 17:17:04.112 NotebookApp] 0 active kernels
[I 17:17:04.112 NotebookApp] The Jupyter Notebook is running at:
[I 17:17:04.112 NotebookApp] http://[all ip addresses on your system]:8889/
[I 17:17:04.112 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
6. 在瀏覽器中查看
然後你就可以在瀏覽器裏敲入你的地址 http://yourip:8889/, 看到如下界面。
啓動Jupyter的開發窗口,點擊右上角的new 按鈕
7、注意阿里雲服務器的安全組配置
如果用的是阿里雲服務器,需要去安全組配置中開發8888端口,否則還是會打開不了瀏覽器
8、遠程連接docker容器中的jupyter notebook
如果是啓動linux中docker容器中的jupyter notebook,原理大致和上面步驟是一樣的,進入docker容器中,配置docker容器中的jupyter notebook,就和上面步驟一致,但是有一點不同的就是在啓動docker容器時候要指定一下端口:
docker run --name lin -p 10000:8888 -it [鏡像名稱]:[tag] /bin/bash
其中8888是jupyter notebook的默認端口,如果jupyter notebook配置中修改此端口,此處也響應改變,其中10000是docker映射到linux系統環境的端口,用一個空閒的端口即可。