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

相关推荐
web135085886351 小时前
Python大数据可视化:基于python的电影天堂数据可视化_django+hive
python·信息可视化·django
东方芷兰1 小时前
伯克利 CS61A 课堂笔记 11 —— Mutability
笔记·python
不会Hello World的小苗3 小时前
Java——列表(List)
java·python·list
m0_748235956 小时前
Python大数据可视化:基于Python的王者荣耀战队的数据分析系统设计与实现_flask+hadoop+spider
hadoop·python·flask
Dyan_csdn6 小时前
【Python项目】基于Python的Web漏洞挖掘系统
网络·python·安全·web安全
Minner-Scrapy6 小时前
DApp 开发入门指南
开发语言·python·web app
&小刘要学习&6 小时前
anaconda不显示jupyter了?
python·jupyter
奔跑吧邓邓子6 小时前
【Python爬虫(36)】深挖多进程爬虫性能优化:从通信到负载均衡
开发语言·爬虫·python·性能优化·负载均衡·多进程
学长学姐我该怎么办7 小时前
年前集训总结python
python