写在前面
Jupyter lab是以前 Jupyter Notebook的升级版,功能更多,配置起来也和Jupyter Notebook很相似,但也有一些不同。在这里记录一下。
安装
conda 安装
1
| conda install -c conda-forge jupyterlab
|
pip 安装
配置
生成配置文件
1
| jupyter lab --generate-config
|
更改页面名字
1
| jupyter lab build --name="CruiseTian's Juypter Lab"
|
设置密码
修改配置文件
1 2 3 4 5 6 7 8 9 10 11 12
| vim ~/.jupyter/jupyter_lab_config.py 修改以下配置,并把开头的 '#' 注释去掉, 或者直接在底部添加 c.ServerApp.ip = '*' c.ServerApp.open_browser = False c.ServerApp.allow_root = True c.ServerApp.port = 8889 c.ServerApp.notebook_dir = u'/root/jupyter' c.ServerApp.password = u'sha1:xxxxx' c.ServerApp.allow_origin = '*' c.ServerApp.allow_remote_access = True c.ServerApp.local_hostnames = ['*'] c.ServerApp.ip = '*'
|
使用systemctl注册jupyter为服务
创建服务脚本
终端输入 vim /usr/lib/systemd/system/jupyterlab.service
,将以下内容复制进去
1 2 3 4 5 6 7 8 9 10 11 12
| [Unit] Description=Jupyter Lab After=network.target
[Service] Type=simple ExecStart=/root/miniconda3/bin/jupyter-lab --config=/root/.jupyter/jupyter_lab_config.py Restart=always RestartSec=10
[Install] WantedBy=multi-user.target
|
启动jupyter并设置开机自启
1 2 3 4 5 6
| systemctl daemon-reload
systemctl enable jupyterlab
systemctl start jupyterlab
|
nginx反代
先修改jupyter notebook的配置文件jupyter_lab_config.py。增加下面两行。
1
| c.ServerApp.base_url = '/lab/'
|
重启jupyter notebook
1
| systemctl restart jupyterlab
|
然后在nginx的配置文件中增加如下内容,重启nginx,即可用https://cruisetian.cn/lab访问jupyter lab了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| location /lab/ { proxy_pass http://127.0.0.1:8889; proxy_set_header Host $host; proxy_set_header X-Real-Scheme $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
proxy_read_timeout 120s; proxy_next_upstream error; }
location ~ /kernelspecs/ { proxy_pass http://127.0.0.1:8889; proxy_set_header Host $host; proxy_http_version 1.1; proxy_set_header Upgrade "websocket"; proxy_set_header Connection "Upgrade"; proxy_read_timeout 86400; }
|