jupyterhub踩坑

由于时效问题,该文某些代码、技术可能已经过期,请注意!!!本文最后更新于:2 年前

安装Jupyterhub

使用 conda 安装,另外官网提供了pip安装方法,参考:https://jupyterhub.readthedocs.io/en/latest/quickstart.html#prerequisites

1
2
conda install -c conda-forge jupyterhub  # installs jupyterhub and proxy
conda install jupyterlab notebook # needed if running the notebook servers in the same environment

测试安装是否成功

1
2
jupyterhub -h
configurable-http-proxy -h
启动

使用sudo权限启动,这样可以多用户使用jupyter

1
2
jupyterhub --generate-config #生成配置文件
sudo jupyterhub

如果有坑,就需要对配置文件进行修改
我这里遇到的坑也是对conda升级造成的,即 conda update conda, 所以没啥事还是不要升级的好。

conda 版本回退
1
conda list --revisions

可以显示之前所有的安装版本,以及相应的时间,然后选择一个正常的版本进行回退(我这里选择第16个版本)

1
conda install --revision 16

参考:https://chowdera.com/2022/01/202201151540272854.html

各种坑

最开始一直遇到的问题是
Spawn failed:Server at xxxxxxxxx respond in 30 seconds
经过不断测试(一天过去了)
配置文件里添加了个参数,如下,倒是可以运行了,但是后来发现这个参数是给到root权限了,所以坚决去掉,不然太危险了。

1
c.Spawner.args = ['--allow-root']

后来在 https://github.com/jupyterhub/jupyterhub/issues/294 这里找到了答案
原来是用户家目录的 .jupyter 目录惹的祸, 删除或者改个名字就OK了。

1
rm -rf ~/.jupyter

当然了坑不止这一个,总之一言难尽,最后整体一个配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
c.PAMAuthenticator.encoding = 'utf8'
c.LocalAuthenticator.create_system_users = True
c.Authenticator.admin_users = {'dg'}
c.Authenticator.allowed_users = {'dg'}
c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
#c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'
#c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner'
c.LocalProcessSpawner.shell_cmd = ["bash", "-l", "-c"]
c.Spawner.notebook_dir = '/share/home/{username}'
c.LabBuildApp.minimize = False
c.LabBuildApp.dev_build = False

### 这几项应该没啥用 ###
#c.Spawner.cmd=['jupyterhub-singleuser']
#c.JupyterHub.admin_access = True
#c.PAMAuthenticator.open_sessions = False

参考:https://www.cnblogs.com/childheart/p/15570915.html

另外关于conda

切换不同的镜像站点时记得清除缓存

删除索引缓存、锁定文件、未使用过的包和tar包

1
conda clean -a

当从一个站点切换到另一个站点的时候记得运行一下上面这个命令,否则即使更新了~/.condarc,软件还是会从之前的站点下载。