supervisor +jupyter-notebook 本地部署

1、安装 supervisor

sudo apt install supervisor

 

2、创建新的Python环境并安装jupyter

virtualenv jupyter-notebook-env                         #创建新的Python环境

source xxxx/jupyter-notebook-en/bin/activate    #根据实际情况补全路径

pip install jupyter              #安装jupyter

 

3、创建启动 jupyter-notebook 的shell脚本 run-jupyter-notebook.sh ,内容如下:

#!/bin/bash
source xxxx/jupyter-notebook-env/bin/activate
jupyter notebook --ip 0.0.0.0 --port 8888 --no-browser
deactivate

给脚本设置执行权限

chmod +x run-jupyter-notebook.sh 

注:source  后跟随刚安装的环境的绝对路径或脚本的相对路径

 

4、增加 supervisor  的配置文件

cd  /etc/supervisor/conf.d             #切换到配置文件目录

touch jupyter-notebook.conf        #创建jupyter-notebook的配置文件

在配置文件中加入以下配置,根据个人情况配置文件路径:

[program:jupyter-notebook]
directory= directory-path
command=/bin/bash -E -c shell-path/run-jupyter-notebook.sh
autostart=true
autorestart=true
stopsignal=INT
stopasgroup=true
killasgroup=true
user=root

注:directory: 等号后的路径为启动 jupyter-notebook 后的工程目录的绝对路径

  command:  -c 后为 run-jupyter-notebook.sh 的绝对路径

5、重启 supervisor  

sudo systemctl restart supervisor.service 

 

6、浏览器访问 jupyter-notebook 的地址 127.0.0.1:8888

 

posted @ 2021-01-28 21:17  飞奔的猪猪  阅读(452)  评论(0)    收藏  举报