如何使用 systemd 运行 Jupyter Hub(单用户模式)以自动启动
注意:这仅允许单个(预配置的)用户登录 Jupyter lab!有关如何使用 systemd 以多用户模式部署 Jupyter Hub(允许任何 Unix 用户登录)的信息,请参见如何使用 systemd 运行 Jupyter Hub(多用户模式)!
以下脚本将以单用户模式安装 Jupyter Hub(即只有一个 Linux 用户可以使用 Web 界面登录 Jupyter Hub)。
先决条件
首先安装 Python 和 PIP,然后是 NodeJS,然后是 Jupyter Hub,然后是 configurable-http-proxy:
install_jupyterhub_prereq.sh
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs python3-pip
pip install -U jupyterhub
sudo npm i -g configurable-http-proxy安装 Jupyter Hub systemd 服务
以你希望能够登录的用户身份运行以下脚本!不要使用 sudo 运行脚本!
install_jupyterhub_service.sh
#!/bin/bash
# 此脚本安装并启用/启动 systemd 服务
export NAME=JupyterHub-$USER
export GROUP=$(id -gn $USER)
# 创建服务文件
sudo tee /etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
[Service]
Type=simple
ExecStart=/usr/bin/env jupyterhub
WorkingDirectory=$HOME
User=$USER
Group=$GROUP
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
# 启用并启动服务
systemctl enable --now ${NAME}此脚本将安装名为 JupyterHub-$USER(其中 $USER 是当前用户,例如 uli)的 systemd 服务并在启动时自动启动它。
运行多个服务
如果你运行多个服务,你可以为每个用户运行脚本并通过向 /usr/bin/env jupyter hub 命令添加 --port=7219 来为每个服务选择唯一端口,例如
jupyterhub_exec_example.txt
ExecStart=/usr/bin/env jupyterhub --port=7192或者,你可以以多用户模式运行单个系统级 Jupyter Hub,多个用户可以登录。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow