阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 16.04 LTS 配置 Jupyter notebook 为服务器

99次阅读
没有评论

共计 1702 个字符,预计需要花费 5 分钟才能阅读完成。

Linux 环境:Ubuntu 16.04 LTS 64bit

已经配置好 IPython 和 Jupyter (安装步骤可以参照:http://www.linuxidc.com/Linux/2017-03/142289.htm)

一、使用 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)

再输入密码即可。

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-03/142292.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计1702字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中