环境搭建:jupyter notebook服务配置,服务后台运行,可远程密码登陆

背景

如果非要找出使用jupyter notebook的缺点,我认为就是每次启动的时候相对繁琐,我们启动本地安装的IDE,一个命令或者点击一下图标即可,但是如果启动jupyter notebook就需要进入命令行或终端,输入“jupyter notebook”进行打开,如果使用的是虚拟环境,首先还要激活虚拟环境,这无疑是非常繁琐的,而且启动后它会占用一个终端或命令行窗口,如果意外关闭则会终止jupyter notebook服务。其实,这也是有解决方法的,我们搭建一个持续化的jupyter notebook服务,让它一直在服务器后台运行,这样既不占用窗口,也不需要繁琐的打开步骤,我们只需要把对应的URL收藏,每次需要时能够秒级速度打开,下面就来介绍一下jupyter notebook的搭建步骤。

配置说明

1.1 生成配置文件

打开命令窗口,执行一下命令

(base) wss@iZuf60za0a748jc3c71epvZ:~$ jupyter notebook --generate-config

##查看生成的配置文件
(base) wss@iZuf60za0a748jc3c71epvZ:~$ vi ~/.jupyter/jupyter_notebook_config.py 

# Configuration file for jupyter-notebook.

##新增以下配置并保存
c.NotebookApp.ip='*' ##访问ip,一般为服务器公网或者私网ip
c.NotebookApp.password = u'(此处填写登录密码)'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8001 ##指定的访问配置端口

1.2 设置登录密码

(base) wss@iZuf60za0a748jc3c71epvZ:~$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from notebook.auth import passwd
>>> passwd()
Enter password: 
Verify password: 
'密文'

1.3 将密文密码写到配置文件

(base) wss@iZuf60za0a748jc3c71epvZ:~$ vi ~/.jupyter/jupyter_notebook_config.py 
##将上述生成的密文添加到
c.NotebookApp.password = u'(此处填写登录密码)'

1.4 后台挂起jupyter服务

##后台始终挂起进程,并且输出日志到jupyter.log
(base) wss@iZuf60za0a748jc3c71epvZ:~$ nohup jupyter notebook << jupyter.log &

然后就可以利用 ip:8001(指定的ip和端口)进行远程登录

1.5 查看后台运行,杀死进程,重新启动jupyter等操作

(base) wss@iZuf60za0a748jc3c71epvZ:~$ ps ux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
wss        300  0.0  1.0  41856 22332 pts/0    S+   02:37   0:00 python
wss        384  0.0  0.2  22500  5008 pts/1    S    02:49   0:00 bash
wss        422  0.0  0.1  37364  3292 pts/1    R+   02:56   0:00 ps ux
wss      18615  0.0  0.9  61196 20228 ?        Ss    2019  25:34 /home/wss/sites/shuangblog.com/env/bin/python3 /home/wss/sites/shuangblo
wss      18622  0.0  3.1 168792 65324 ?        S     2019   5:16 /home/wss/sites/shuangblog.com/env/bin/python3 /home/wss/sites/shuangblo
wss      18623  0.0  3.1 168316 64996 ?        S     2019   5:20 /home/wss/sites/shuangblog.com/env/bin/python3 /home/wss/sites/shuangblo
wss      30126  0.0  2.8 106548 58172 ?        S    Feb21   0:02 /opt/miniconda3/bin/python /home/wss/.local/bin/jupyter-notebook
wss      32691  0.0  0.2  22604  5308 pts/0    S    01:43   0:00 bash
(base) wss@iZuf60za0a748jc3c71epvZ:~$ ps -ef|grep jupyter
wss        424   384  0 02:57 pts/1    00:00:00 grep --color=auto jupyter
wss      30126     1  0 Feb21 ?        00:00:02 /opt/miniconda3/bin/python /home/wss/.local/bin/jupyter-notebook
(base) wss@iZuf60za0a748jc3c71epvZ:~$ kill -9 30126
(base) wss@iZuf60za0a748jc3c71epvZ:~$ ps -ef|grep jupyter
wss        428   384  0 02:58 pts/1    00:00:00 grep --color=auto jupyter

##重启进程
(base) wss@iZuf60za0a748jc3c71epvZ:~$ nohup jupyter notebook >>jupyter.log &
[1] 652
(base) wss@iZuf60za0a748jc3c71epvZ:~$ ps -ef|grep jupyter
wss        652   625  2 03:09 pts/1    00:00:00 /opt/miniconda3/bin/python /opt/miniconda3/bin/jupyter-notebook


具体远程登录的开发界面如下:
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

maligebilaowang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值