怎样在服务器部署Jupyter Notebook

立下 Flag 要写本书,名字还没想好,大致的内容就是使用 Python 语言学算法之类的。由于工作的原因,不可能将代码啥的保存在一台电脑上,再加上截图风格要统一,所以决定,用 Jupyter 作为代码测试、运行环境。
我有自己的服务器,所以就把 Jupiter 部署在上面吧!记录下过程。

安装 Jupyter notebook

sudo pip3 install ipython
sudo pip3 install jupyter

创建 Jupyter notebook 工作目录

sudo mkdir jupyter_notebook

生成配置文件

jupyter-notebook --generate-config
OTP:Writing default config to: /home/ubuntu/.jupyter/jupyter_notebook_config.py

生成密码

Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'argon2:$argon2id$v=19$m=10240,t=10,p=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
>>> exit()

修改配置文件

vim .jupyter/jupyter_notebook_config.py

在jupyter_notebook_config.py中最下面添加一下配置

c.NotebookApp.ip='*' # *代表所有机器都可访问,或者输入服务ip
c.NotebookApp.password = u'sha1:......' # 把引号中的内容替换为刚刚生成的sha1开头的密码
c.NotebookApp.notebook_dir = u'/root/jupyter_/home/ubuntu/jupyter_notebook # 第一步创建的工作目录
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.allow_root = True
:wq 保存退出

修改密码并启动服务

由于上面生成的密码太长,所以修改一个简单的密码

jupyter notebook password

输入2次新密码

ubuntu@VM-0-3-ubuntu:~$ jupyter notebook password
Enter password: 
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /home/ubuntu/.jupyter/jupyter_notebook_config.json

为了使密码生效,防止jupyter notebook不允许以root方式启动,我们需要在首次访问需要加入参数

nohup jupyter-notebook --allow-root --config=/root/.jupyter/jupyter_notebook_config.py &

第二次启动就不用–config这个参数了

nohup jupyter-notebook --allow-root &

启动即可
登录页面
登录成功

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值