jupyterhub_config配置文件内容

登录后默认看到的页面

#c.Spawner.default_url = '/tree/'

跳转路由

#c.JupyterHub.base_url = u'/jupyter/'

#c.JupyterHub.bind_url = 'http://127.0.0.1:8000/jupyter/'

允许跨域,模拟登陆生成cookie的时候会用到

#c.Spawner.args = '--NotebookApp.allow_origin=\*'

#c.JupyterHub.tornado_settings = {

'headers': {

'Access-Control-Allow-Origin': '*',

},

#}

设置每个用户的 book类型 和 工作目录(创建.ipynb文件自动保存的地方)

#c.Spawner.notebook_dir = '~'

#c.Spawner.notebook_dir = '/database/jupyterhub_data'

c.Spawner.default_url = '/lab'

c.Spawner.args = '--allow-root'

或者

c.Spawner.default_url = '/lab' # 使用jupyterlab 代替jupyter notebook

c.Spawner.notebook_dir = '~' # 将每个人的jupyter工作目录,设定为自己用户名文件夹下

或者

c.NotebookApp.base_url='/home/jupyterhub'

configurable_http_proxy 代理设置

c.ConfigurableHTTPProxy.should_start = True #允许hub启动代理 可以不写,默认的,为False 就需要自己去 启动configurable-http-proxy

c.ConfigurableHTTPProxy.api_url = 'http://localhost:8001' # proxy与hub与代理通讯,这应该是默认值不行也行

pip install pycurl

对外登录设置的ip

c.JupyterHub.ip = '0.0.0.0'

c.JupyterHub.port = 8000

c.ServerApp.port=9999

c.Spawner.ip = '0.0.0.0'

c.PAMAuthenticator.encoding = 'utf8'

c.ServerApp.allow_origin = '*' # 允许跨域

c.ServerApp.allow_remote_access = True # 允许远程访问,这项配置必须配置,即使是使用了反向代理。

c.ServerApp.allow_root = True # 允许root启动jupyter

c.ServerApp.open_browser = False # 是否启动之后自动在浏览器加载jupyter服务。因为在服务端,因此不自动加载。

#c.ServerApp.password = u'argon2:argon2idv=19m=10240,t=10,p=8vMxxxvXYdj400Lrdxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2cvQhuqx29xxx2C38XiA' # 将生成的经过哈希的密码放这里。要注意前面的u

#c.ServerApp.port = 8888 # 指定服务端要启动的端口

其他设置 cookie file and sqlite file,这个写着了,不写我没试有啥影响

#c.JupyterHub.cookie_secret_file = '/etc/jupyterhub/jupyterhub_cookie_secret'

#c.JupyterHub.db_url = '/etc/jupyterhub/jupyterhub.sqlite'

#c.JupyterHub.pid_file = '/etc/jupyterhub/jupyterhub.pid'

#300秒自动终止长时间未活动的会话

c.JupyterHub.load_spawners = False

c.Spawner.start_timeout = 300 # 例如,30秒后自动终止未启动的会话

用户名单设置,默认身份验证方式PAM与NUIX系统用户管理层一致,root用户可以添加用户test1,test2等等,非root用户,sudo useradd test1/test2 不起作用,目前我不知道sudo useradd 和 root下 useradd本质区别*(没有特意学

过linux,一切只靠用时百度)

c.Authenticator.allowed_users = 'jupyterhub1','jupyterhub2','jupyterhub3','jupyterhub4','jupyterhub'

#c.LocalAuthenticator.add_user_cmd = 'adduser', '-m', '-G', 'jupyterhub-users'

#此时添加白名单方法生效。但是此时还需要先为新用户设置密码,才能登录,所以还是建议在linux终端直接添加新用户

c.LocalAuthenticator.add_user_cmd ='adduser','-m','-G','jupyterhub-users'

设置管理员用户

c.Authenticator.admin_users = {'root','jupyteradmin'}

如果没有root权限,公司服务器,员工一般都没有,可以先设置下面两句进行测试,允许任何用户和密码登录,若想自己设置身份验证,也可以自己修改 PAMAuthenticator和SimpleLocalProcessSpawner这两个类,这两个类代码特简单

,代码放到文章下面

c.JupyterHub.authenticator_class = 'jupyterhub.auth.DummyAuthenticator'

c.JupyterHub.spawner_class = 'jupyterhub.spawner.SimpleLocalProcessSpawner'

c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'

如上面不好使,请 pip install jupyterhub-dummyauthenticator

pip install jupyterhub-simplelocalprocessspawner

应该jupyterhub 安装时就自带了这两个类 就在jupyterhub安装目录下,auth.py和spawner.py文件里

#pip3 install jupyterhub-dummyauthenticator -i https://pypi.tuna.tsinghua.edu.cn/simple

#c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'

c.JupyterHub.statsd_prefix = 'jupyterhub'

#c.NotebookApp.notebook_dir = '/volume1/study/python/' #jupyter 自定义目录使用

#c.Spawner.notebook_dir = '/volume1/study/' #jupyterhub自定义目录

c.JupyterHub.statsd_prefix = 'jupyterhub'

#c.JupyterHub.ssl_cert = '/usr/syno/etc/certificate/_archive/xYa1nX/fullchain.pem'

#c.JupyterHub.ssl_key = '/usr/syno/etc/certificate/_archive/xYa1nX/privkey.pem'

设置用户一小时内无使用则关闭jupyterlab服务

c.JupyterHub.active_server_limit = 100 # 设置同时活跃的服务器上限

c.JupyterHub.concurrent_spawn_limit = 10 # 设置同时启动的最大用户数

#c.JupyterHub.idle_timeout = 3600 # 用户空闲超时时间,单位为秒,3600秒意味着30分钟

c.JupyterHub.init_spawners_timeout = 10

#c.JupyterHub.max_spawner_count = 100 # 设置最大用户数

c.JupyterHub.concurrent_spawn_limit = 100

设置允许的最大内存

c.Spawner.mem_limit = '1G'

为jupyterhub 添加额外服务,用于处理闲置用户进程。使用时不好使安装一下:pip install jupyterhub_idle_culler

额外服务 单用户jupyter进程关闭服务,默认3600s后kill,减少资源浪费

c.JupyterHub.services = [

{

'name': 'idle-culler',

'command': 'python3', '-m', 'jupyterhub_idle_culler', '--timeout=3600',

'admin':True # 1.5.0 需要服务管理员权限,去kill 部分闲置的进程notebook, 2.0版本已经改了,可以只赋给 idel-culler 部分特定权限,roles

}

]

c.JupyterHub.load_roles = [

{

"name": "list-and-cull", # name the role

"services": [

"idle-culler", # assign the service to this role

],

"scopes": [

declare what permissions the service should have

"list:users", # list users

"read:users:activity", # read user last-activity

"admin:servers", # start/stop servers

],

}

]

#import os

#from jupyterhub.auth import Authenticator

#from tornado.gen import coroutine

#from jwt.auth import JWT

#class JWTAuthenticator(Authenticator):

@coroutine

def authenticate(self, handler):

token = handler.request.headers.get('Authorization')

if not token:

raise web.HTTPError(403, 'Missing Authorization header')

使用你的密钥验证 JWT 令牌

payload = JWT.verify_token(token, 'your-secret-key')

username = payload'user_name'

return username

#c.JupyterHub.authenticator_class = JWTAuthenticator

相关推荐
小玮看世界1 小时前
[Python]从“脏”数据到优雅实现:一个IoT滑动窗口最大值问题的测试驱动优化实录
linux·前端·python
MC皮蛋侠客1 小时前
SQLAlchemy 系列(十一):从 1.x 到 2.x——渐进迁移与数据访问层治理
数据库·python
魔镜前的帅比2 小时前
(开源项目)x-claw (设计)
python·ai·rust·开源
谢尔登2 小时前
分享一些我常用的Skill
java·人工智能·python·actionscript
k4m7v2pz3 小时前
macOS 解压 40GB 分卷+中文密码固件镜像的五个深坑与解决方案
python·7-zip·aes加密·踩坑记录·r36s·多卷zip解压
小白学大数据3 小时前
Python 爬虫实战:抓取汽车之家二手车成交价格与里程数据
开发语言·爬虫·python·汽车
Jazz_z4 小时前
如何用Python将彩色PDF一键转为黑白(灰度)
java·python·pdf
SEO_juper4 小时前
2026年Schema自动注入实战:用Python批量给1000个页面加上JSON-LD,AI引用率实测提升38%
人工智能·python·json·seo·独立站
zzzll11114 小时前
HashMap、HashTable、ConcurrentHashMap 详细区别与深度解析
开发语言·python
程序员AI工坊4 小时前
Agent 开发:ReAct 循环与工具调用实战——从单次调用到自主 Agent
人工智能·后端·python·langchain·agent·react