如題,搭了一個 spark 集羣,在 master 上安裝了 jupyter notebook. 隨後發現團隊有多個人想在 master 上用 jupyter 操作,又不方便大家用一個賬戶,於是就創建了多個賬戶.
方法很簡單:
jupyter notebook 命令有一個 --config <config_file_path> 的可選參數,默認使用當前目錄下的 jupyter_notebook_config.py,可填入 絕對路徑 指定配置文件。
只要給每個用戶寫一個配置文件(至少端口、工作目錄的配置要不同),然後分別運行 jupyter notebook --config jupyter_notebook_config_username.py 即可。
實例
文件目錄:
[root@master .jupyter]# ls
jupyter_notebook_config_hs.py jupyter_notebook_config.py jupyter_notebook_config.py.bak jupyter_notebook_config_zq.py migrated
其中 jupyter_notebook_config.py 是第一個用戶的配置文件,jupyter_notebook_config_hs.py 是用戶 hs 的配置文件,jupyter_notebook_config_zq.py 是用戶 zq 的配置文件。
文件內容示例:
jupyter_notebook_config.py
1 # Configuration file for jupyter-notebook.
2 c = get_config()
3 c.IPKernelApp.pylab = 'inline'
4 c.NotebookApp.ip = '*'
5 c.NotebookApp.open_browser = False
6 c.NotebookApp.password = 'sha1:61c764d76b49:01e5f2ec3d6d0ba262b472281d025d3c4e1fe565'
7 c.NotebookApp.port = 6789
8 c.NotebookApp.notebook_dir = '/home/me/ipython'
執行 jupyter notebook & 或 jupyter note book --config /root/.jupyter/jupyter_note_book_config.py & 啓動服務
客戶端在瀏覽器上 通過 <ip地址>:6789 訪問
jupyter_notebook_config_hs.py
1 # Configuration file for jupyter-notebook.
2 c = get_config()
3 c.IPKernelApp.pylab = 'inline'
4 c.NotebookApp.ip = '*'
5 c.NotebookApp.open_browser = False
6 c.NotebookApp.password = 'sha1:976bc4e3d0db:df5983c005e2d95c061426ba90c74086c57e76fd'
7 c.NotebookApp.port = 7777
8 c.NotebookApp.notebook_dir = '/home/hs/ipython'
執行 jupyter note book --config /root/.jupyter/jupyter_note_book_config_hs.py & 啓動服務
至此,該服務器就可以給多個端口、密碼不同的 jupyter notebook 用戶使用了