Ubuntu 16.04 LTS 配置 Jupyter notebook 為服務器


原材料:

Ubuntu 16.04 LTS 64bit

已經配置好 IPython 和 Jupyter (安裝步驟可以參照:http://www.cnblogs.com/McKean/p/6194977.html)

一、使用OpenSSL產生 *.key 和 *.pem 密鑰

cd ~/.jupyter 切換到.jupyter目錄

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem

成功的話,會在.jupyter目錄下面產生 mykey.key 和 mycert.pem 兩個文件

注意:這個OpenSSL是可選的,即使不適用OpenSSL也可以配置 jupyter使得局域網里面可以訪問的。

二、設置密鑰的sha1碼

可以在IPython里面輸入一下命令並按照提示輸入密碼,即可產生你需要密碼對應的sha1值。

In [1]: from notebook.auth import passwd

In [2]: passwd()
c:\python27\lib\getpass.py:92: GetPassWarning: Can not control echo on the termi
nal.
  return fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
Enter password: 12345678
Warning: Password input may be echoed.
Verify password: 12345678
Out[2]: 'sha1:c88810a822cf:2a10d54101bf6b326351c15f0c7b9fede372ef23'

  

三、產生並配置 jupyter_notebook_config.py 文件

使用 ls 命令查看.jupyter 目錄下面有沒有 jupyter_notebook_config.py 文件

如果沒有,則使用 jupyter notebook --generate-config 命令產生一個

默認jupyter_notebook_config.py的配置都使用#注釋掉,下面需要開啟所需要的命令。

這里password 一項要使用前面產生的sha1值## The full path to an SSL/TLS certificate file.c.NotebookApp.certfile = u'/home/peter/.jupyter/mycert.pem

## The IP address the notebook server will listen on.
c.NotebookApp.ip = '192.168.242.139'
 
#  The string should be of the form type:salt:hashed-password.
c.NotebookApp.password = u'sha1:96d749b4e109:17c2968d3bc899fcd41b87eb0853a42ceb48c521'
 
## The port the notebook server will listen on.
c.NotebookApp.port = 8888

c.NotebookApp.open_browser = False

  

配置Jupyter notebook的默認目錄

c.NotebookApp.notebook_dir = u'/home/peter/Git/MatlabMisc/Jupyter'

  

四、啟動Jupyter notebook

在~/.jupyter目錄下,輸入下面命令即可
sudo jupyter notebook --certfile=mycert.pem --keyfile mykey.key

然后在其他機器上,輸入 https://192.168.242.139:8888 (這里的ip是根據你自己的環境和在jupyter_notebook_config.py 文件配置的ip)

再輸入密碼即可

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM