1.docker 安装jupyterhup
netstat -anlp|grep 8000
docker run -it -p 8000:8000 --name jupyterhub jupyterhub/jupyterhub bash
docker exec -it jupyterhub bash
#手动装jupyter家族
apt update
apt-get install npm nodejs python3 python3-pip git nano
python3 -m pip install jupyterhub notebook jupyterlab
npm install -g configurable-http-proxy
cd /home
git clone https://github.com/jupyterhub/nativeauthenticator.git
cd nativeauthenticator
pip3 install -e .
#生产配置文件
mkdir /etc/jupyterhub
cd /etc/jupyterhub
jupyterhub --generate-config -f jupyterhub_config.py
#编辑配置文件填写下面内容
nano jupyterhub_config.py
import pwd, subprocess
c.JupyterHub.authenticator_class = 'nativeauthenticator.NativeAuthenticator'
c.Authenticator.admin_users = {'admin'}
def pre_spawn_hook(spawner):
username = spawner.user.name
try:
pwd.getpwnam(username)
except KeyError:
subprocess.check_call(['useradd', '-ms', '/bin/bash', username])
c.Spawner.pre_spawn_hook = pre_spawn_hook
c.Spawner.default_url = '/lab'
#启动jupyter
jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
2.访问jupyterhup
http://192.168.0.106:8000/
先创建用户admin/admin
登录后访问http://192.168.0.106:8000/hub/authorize(在这里对其他用户授权才能登录)
所有的用户能显示在这里
附:
官方手册:https://tljh.jupyter.org/en/latest/install/index.html
官方配置:https://jupyterhub.readthedocs.io/en/stable/api/app.html
3.配置权限集成
import jwt
import json
from tornado import gen
from jupyterhub.auth import LocalAuthenticator
class MyAuthenticator(LocalAuthenticator):
@gen.coroutine
def authenticate(self, handler, data):
token = handler.get_cookie('token')
user = jwt.decode(token,'密钥',algorithms = ['HS256'])
userNo=user['userNo']
if userNo is not None:
return userNo
c.JupyterHub.authenticator_class = MyAuthenticator
c.Spawner.default_url = '/lab'
c.JupyterHub.base_url = '/jupyterhub'
c.LocalAuthenticator.create_system_users = True
c.LocalAuthenticator.auto_login = True
c.Authenticator.delete_invalid_users = True