开发工具-004-搭建jupyter远程服务
1、安装jupyter conda create -n jupyter python=3.10 pip install jupyter
2、配置jupyter 设置密码,生成秘钥文件:
jupyter notebook password Enter password: Verify password: [NotebookPasswordApp] Wrote hashed password to /your_home/.jupyter/jupyter_notebook_config.json
查看秘钥:
$ cat ~/.jupyter/jupyter_notebook_config.json { "NotebookApp" : { "nbserver_extensions" : { "jupyter_nbextensions_configurator" : true }, "password" : "argon2:$argon2id$v =19$m =10240,t=10,p=8$ADrvxc7AsirraAJFXTnNsg$I7KwbhJ +FXGRBW/lv3dfYw" } }
生成默认的Jupyter配置文件,用于启动服务。
jupyter notebook --generate-config
修复配置文件选项:
c.NotebookApp.allow_password_change = False c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$ADrvxc7AsirraAJFXTnNsg$I7KwbhJ+FXGRBW/lv3dfYw' c.KernelManager.ip = '192.168.3.10' c.NotebookApp.port = 8888 c.NotebookApp.allow_remote_access = True
3、安装插件 pip install jupyter_contrib_nbextensions jupyter contrib nbextensions install --user pip install jupyter_nbextensions_configurator jupyter nbextensions_configurator enable --user
4、部署成systemd服务 在miniconda目录新建一个脚本,封装jupyter启动命令:
$ cat run_jupyter.sh rootDir=$(cd $(dirname $0 ); pwd ) source ${rootDir} /bin/activate jupyterjupyter notebook /path/to/your_notebook_dir/
新建systemd服务配置文件
[Unit] Description=jupyter daemon [Service] ExecStart=/usr/bin/bash /home/<user>/miniconda3/run_jupyter.sh [Install] WantedBy=default.target
启动systemd
systemctl enable --user jupyter systemctl start --user jupyter systemctl status --user jupyter
参考 [1] 通过 conda 安装 jupyterlab 并配置为 systemd 服务