Linux部署JupyterHub实现多用户使用Jupyterlab

一、安装docker

1、安装
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
  • 1.
2、配置
# 重启docker
systemctl restart docker 

# 设置docker为开机自启动
systemctl enable docker
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

二、拉取镜像并创建容器

1、拉取镜像
docker pull debian:latest
  • 1.
  • debian:latest 是 Debian 官方在 Docker Hub 上维护的镜像标签。
  • latest 默认指向 Debian 当前最新的稳定版(stable),例如 Debian 12(bookworm)或 Debian 11(bullseye),具体取决于 Debian 官方的更新策略。
  • 这个镜像是 最小化基础镜像(minimal base image),仅包含最基本的系统工具和库,适合作为构建其他镜像的基础。

举个例子:

截至今天(2025年8月16日),debian:latest 很可能指向 Debian 12 "bookworm",因为 Debian 12 是当前最新的稳定版(发布于2023年6月),除非 Debian 13 已经发布并成为新的 stable。

2、创建容器
docker run -itd --hostname=jupyterhub -v /etc/jupyterhub:/etc/jupyterhub --name=jupyterhub --restart=always -p 8000:8000 debian
  • 1.

  此处使用debian作为基本镜像进行搭建,也可以使用ubuntucentos等镜像,对外暴露端口号为8000,若有端口冲突,可改为其他端口,jupyterlab服务运行在容器的8000端口上。

3、进入容器

创建完成后进入容器,接下来的众多命令均在容器内执行:

docker exec -it jupyterhub /bin/bash
  • 1.

三、安装必要的包

1、更新软件源
apt-get update -y && apt-get upgrade -y && apt-get autoremove -y
  • 1.

服务器部署notebook+xedu+机器学习编程环境多用户登录_docker

 # 如果速速很慢,国外源的问题,可以尝试先修改源

# 1) 把官方源换成清华镜像(debian bookworm 为例)
sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
sed -i 's|http://security.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
  • 1.
  • 2.
  • 3.

# 1. 把 https 换成 http(临时)
sed -i 's|https://mirrors.tuna.tsinghua.edu.cn|http://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list

# 2. 更新索引并安装缺失的包
apt-get update -y
apt-get install -y ca-certificates openssl

# 3. 再把 http 换回 https(永久)
sed -i 's|http://mirrors.tuna.tsinghua.edu.cn|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list

# 4. 后续正常更新
apt-get update -y && apt-get upgrade -y && apt-get autoremove -y

服务器部署notebook+xedu+机器学习编程环境多用户登录_bash_02

2、安装软件
apt-get install vim procps wget -y
  • 1.

服务器部署notebook+xedu+机器学习编程环境多用户登录_docker_03

四、安装Miniconda3

1、获取下载地址

下载地址: Miniconda3清华镜像站下载

选择较新版本,复制链接,

服务器部署notebook+xedu+机器学习编程环境多用户登录_添加用户_04

  Miniconda3-py310_22.11.1-1-Linux-x86_64.sh

  https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_22.11.1-1-Linux-x86_64.sh

2、下载并安装
# 下载
## wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh
  • 1.
  • 2.
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
  • 1.
# 赋予可执行权限 
chmod +x ./Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
  • 1.
  • 2.
# 执行安装
  • 1.
./Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
  • 1.

服务器部署notebook+xedu+机器学习编程环境多用户登录_bash_05

 回车,空格到询问 yes 这里,输入 yes

服务器部署notebook+xedu+机器学习编程环境多用户登录_添加用户_06

修改路径

服务器部署notebook+xedu+机器学习编程环境多用户登录_docker_07

服务器部署notebook+xedu+机器学习编程环境多用户登录_bash_08

 执行安装后,有几点注意:
  •  刚执行的时候是服务条款,一路按Enter,然后要输入的时候输入yes即可;
  •  接下来会让确认路径,默认为~/miniconda3,不要装在root用户目录下,建议装在/opt/miniconda3目录下,装root目录下之后会出现很多问题;
  •  最后询问是否初始化,选择yes
  • 安装完成后可删除安装包,以节省硬盘空间
3、验证是否安装成功

安装完成后重启终端,然后再进去,再进入发现终端(base)开头,说明安装成功

验证一下

# 重新加载 shell 环境
source /root/.bashrc

# 看版本
conda --version
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

服务器部署notebook+xedu+机器学习编程环境多用户登录_添加用户_09

五、安装nodejs和npm

nodejsnpm可以使用apt-get包管理工具进行安装:

apt install nodejs npm -y
  • 1.

但版本可能不是很新,以下提供另一种安装方法:

1、下载

node.js中文官网: 下载 | Node.js 中文网 (nodejs.cn)

服务器部署notebook+xedu+机器学习编程环境多用户登录_docker_10

  https://npmmirror.com/mirrors/node/v22.18.0/node-v22.18.0-linux-x64.tar.xz

访问界面,选择Linux 二进制文件 (x64),右键复制链接

返回终端,下载: