Jupyterhub安装配置及心得
Jupyter简介
Jupyter是一款基于python的web notebook服务,目前有大多python数据挖掘与机器学习爱好者使用这款服务,其特性其实与Ipytohn Notebook差不多,准确说Ipython Notebook是一款提供增强型交互的功能的shell,而Jupyter除了Ipython的功能,还加入了普通编辑器的通用功能,是一款带代码交互的动态文档web编辑器。
Jupyterhub简介
由于Jupyter只支持单用户的使用场景,作为一个可交互的web服务,只支持单用户模式实在让人难以理解。估计开发者也觉得这个问题太过鸡肋,于是Jupyterhub因有而生。
安装Anaconda
JupyterHub是基于Python的,所以我们需要安装一下Python的相关环境。Anaconda是一个非常成熟的Python包管理工具,因此本文档选用该工具进行基础环境的安装,首先就是安装该工具。
下载安装
- 下载
- 这里我使用清华的镜像站点下载,速度很nice,50-60MB/s
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda2-2018.12-Linux-x86_64.sh
- 这里我使用清华的镜像站点下载,速度很nice,50-60MB/s
- 安装
bash Anaconda2-2018.12-Linux-x86_64.sh
根据提示安装即可,安装过程中会询问你是否将anaconda的路径加入到环境变量.bashrc中,默认是no,所以如果在安装的过程中手太快,一键到底了的话,可以通过手动添加的方式进行设置。
将anaconda3加入环境变量
vim ~/.bashrc
在bashrc文件的最后添加
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/opt/anaconda3/bin/conda' shell.bash hook 3> /dev/null)"
if [ $? -eq 0 ]; then\eval "$__conda_setup"
elseif [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then. "/opt/anaconda3/etc/profile.d/conda.sh"CONDA_CHANGEPS1=false conda activate baseelse\export PATH="/opt/anaconda3/bin:$PATH"fi
fi
unset __conda_setup
# <<< conda init <<<
保存并退出
然后
source ~/.bashrc
检测Anaconda是否安装成功:
conda list
如果提示conda: command not found,请参考是否将Anaconda3加入环境变量,并且更新生效。
Jupyterhub安装
- 可以使用清华的conda源加速
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda install -c conda-forge jupyterhub
- 如果感觉conda安装慢可以使用pip安装
- pip安装Jupyterhub:
$ pip3 install jupyterhub notebook -i https://pypi.douban.com/simple/
检测安装是否成功
jupyterhub -h
npm install -g configurable-http-proxy
configurable-http-proxy -h
生成配置文件
jupyterhub --generate-config -f /etc/jupyterhub/jupyterhub_config.py
修改配置
- 以下是我的配置
c.JupyterHub.ip = '192.168.2.4'
c.JupyterHub.port = 12443
c.Spawner.ip = '127.0.0.1'
c.PAMAuthenticator.encoding = 'utf8'
c.Authenticator.whitelist = {'root','admin', 'tv', 'aiker'} #默认不能使用root登录,需要修改配置
c.LocalAuthenticator.create_system_users = True
c.Authenticator.admin_users = {'root', 'admin'}
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'
- 如果需要使用root登录,需要修改配置
修改源码 $jupyterhub_安装目录/site-packages/jupyterhub/spawner.py,找到如下代码块做修改:
def get_args(self): """Return the arguments to be passed after self.cmd Doesn't expect shell expansion to happen. """ args = [] if self.ip: args.append('--ip="%s"' % self.ip) if self.port: args.append('--port=%i' % self.port) elif self.server.port: self.log.warning("Setting port from user.server is deprecated as of JupyterHub 0.7.") args.append('--port=%i' % self.server.port) if self.notebook_dir: notebook_dir = self.format_string(self.notebook_dir) args.append('--notebook-dir="%s"' % notebook_dir) if self.default_url: default_url = self.format_string(self.default_url) args.append('--NotebookApp.default_url="%s"' % default_url) if self.debug: args.append('--debug') if self.disable_user_config: args.append('--disable-user-config') args.append('--allow-root') ##添加此行代码,实现root访问与登陆 args.extend(self.args) return args
用户认证
Jupyterhub支持多种认证方式:PAM和LDAP,默认使用的是PAM,即与系统用户层使用同一认证管理,用户名与密码与系统配置的相同。
首先用py3安装一个插件:
$ pip3 install jupyterhub-dummyauthenticator -i https://pypi.douban.com/simple/
然后,如果遇到生成token问题,在配置文件中修改此配置:
c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
具体细节可以参考这个问题。
Kernel
Kernel可以理解为每个notebook运行的后台环境,Jupyterhub以及Jupyter虽然是基于python的application,但这并不意味着其notebook的功能只能为python环境使用,事实上Jupyter的强大就体现在此处,其可以支持任意环境的notebook,目前主流的数据科学环境基本都支持,R, SAS,SPARK等。
Anaconda Kernel安装
conda环境安装特别简单,首先确保anaconda环境已经集成了Ipython,默认是已经集成了。其次在用户级别下执行一下命令即可:
$ $your_anaconda_install_path/bin/ipython kernel install --user --name anaconda
执行完成后,便会在jupyterhub中看到名为anaconda的kernel,还是再重申下,这个命令需要在每个用户级别下local执行。new后便可使用anaconda环境中的所有python lib。
同时支持Python2和python3
Notebook的右上角点new 只看到 python 3 kernel,需要同时支持Python2和python3
查看目前的conda环境中的kernels
jupyter-kernelspec list
Available kernels:
python3 /root/.local/share/jupyter/kernels/python3
需要安装python2,python2下安装ipython,成功后执行
/opt/anaconda2/bin/ipython kernel install --user --name python2
查看该环境下的kernels
# jupyter-kernelspec list
Available kernels:python2 /root/.local/share/jupyter/kernels/python2python3 /root/.local/share/jupyter/kernels/python3
重启jupyterhub即可生效,web效果如下:
R Kernel安装
根据需要决定是否安装,不勉强
安装R Kernel之前需要安装r-irkernel,这步我们使用anaconda来安装:$ conda install -c r r-irkernel
安装完毕之后,运行R命令:
IRkernel::installspec()
执行完成后,便可在jupyterhub中看到名为R的kernel。
启动
jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl
- 后台启动:
nohup jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl > /dev/null 2>&1 &
注意事项:
- 如果已经有npm,需要注意npm版本>=6.0
- 注意jupyterhub-console和python模块prompt版本
- 一定注意配置环境变量
- 如果使用反向代理,注意可能引起ipykernel不能正确解析
安装主题
- 更改主题只对my server生效,不对control面板起作用
pip install jupyterthemes
jt -l #列出主题
jt -t monokai -T -N -altp -fs 13 -nfs 13 -tfs 13 -ofs 13 #应用monokai主题
执行完命令后刷新web即可。
为jupyterhub启用代理
目的是为了更方便和安全
这里使用nginx代理
server {listen 443 ssl http2;listen [::]:443 ssl http2;resolver 192.168.2.1 114.114.114.114;set $backend "https://jp.abcgogo.com:12443";server_name jp.abcgogo.com;ssl_certificate /usr/syno/etc/certificate/ReverseProxy/faea4d05-2458-4ffc-acfe-e4b48e5a04f9/fullchain.pem;ssl_certificate_key /usr/syno/etc/certificate/ReverseProxy/faea4d05-2458-4ffc-acfe-e4b48e5a04f9/privkey.pem;add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload" always;location / {proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_intercept_errors on;# WebSocket supportproxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_read_timeout 120s;proxy_next_upstream error;proxy_pass $backend;}}
jupyterhub使用了 websocket, 所以需要这样配置
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
如果nginx代理没有配置websocket,cell里面的内容会不能解析,红框里面显示等待。
可以根据情况参考配置:
nginx官网websocket说明
location / {proxy_pass http://jupyterhub IP:port;proxy_set_header Host $host;proxy_set_header X-Real-Scheme $scheme;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# WebSocket supportproxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_read_timeout 120s;proxy_next_upstream error;}
检查重启nginx配置:
nginx -t && nginx -s reload
做好dns解析就可以使用域名访问了。
转载于:https://blog.51cto.com/m51cto/2370679
Jupyterhub安装配置及心得相关推荐
- CENTOS6 安装配置 pptpd 心得
1.你所需要的软件 pppd ppp拨号服务器 pptpd 在pppd拨号的基础上增加pptpd的支持 2.确定你的内核是否支持mppe modprobe ppp-compress-18 ...
- GNS3 搭配 secureCRT 安装配置与使用心得
GNS3 搭配 secureCRT 安装配置与使用心得 首先要感谢那5个充满活力的法国小伙子,他们的作品让我们的使用变得更加方便. 先来介绍一下GNS3: 这是一个基于dynamips技术的服务平台. ...
- 富士胶片 激光一体机 ApeosPort 3410SD安装配置心得
您好,欢迎进来.这可能是全网最详细的ApeosPort 3410SD安装配置教程了.基本上可以说是原创.因为,网上这方面配置信息基本上就没有. 1. 问题引入 最近为了替换家里使用的老打印机DocuP ...
- jupyterhub安装与配置
pip方式安装jupyterhub 一.安装依赖: 1.sudo apt install -y npm nodejs 若步骤1成功,直接跳至步骤3 2.本步骤非必须,若步骤1失败,则需要先执行:sud ...
- Openpbs centos7集群安装配置心得
Openpbs centos7集群安装配置心得 写在前面 准备工作 1.安装虚拟机 2.创建虚拟机集群 SSH免密登陆 网络环境配置 ssh免密登陆 建立NFS共享目录 关闭各节点防火墙和Selinu ...
- jupyterHub安装,docker安装JupyterHub,JupyterLub,配置JupyterHub使用JupyterLab
参考官方配置: https://jupyterhub.readthedocs.io/en/stable/index.html docker下安装jupyterHub jupyterhub简介 部署步骤 ...
- 安装配置jupyterhub————附带详细步骤
文章目录 0 现存问题 1 安装npm 2 安装Anaconda 3 安装Jupyterhub 4 修改配置文件 4.1 生成密码 4.2 修改配置 5 启动JupyterHub 0 现存问题 不知道 ...
- JupyterHub -安装与配置-简介
目录 前言 安装jupyterhub 安装需求 安装JupyterHub 配置 启动Jupyterhub 前言 详见:JupyterHub - JupyterHub 2.3.0.dev documen ...
- mysql++pc客户端_Mysql超详细安装配置+客户端连接
下载 选择直接下载 解压 我将Mysql解压到:E:\devSofts\mysql-8.0.21-winx64\mysql-8.0.21-winx64地址,后面的内容和这相关,可以根据你的实际情况稍作 ...
最新文章
- 虚拟化--006 VCAC的sso配置成功
- 必读!TOP10生成对抗网络GAN论文(附链接)
- Mac下Unity5x的安装
- 汉字转拼音---PHP
- Fiddler抓取https证书问题
- 本地运行hadoop-Failed to locate the winutils binary in the hadoop binary path
- indesign入门教程,如何添加文字?
- Python全栈学习_day010作业
- C语言汇编-函数调用栈
- 【MFC开发(1)】MFC的介绍、与Qt的区别
- 织梦CMS插件-支持dedeCMS各大主题
- 设计模式学习——代理模式(proxy)
- 使用Linux命令cURL实现文件定时上传到ftp服务器的程序
- 计算机人工智能应用,计算机在人工智能中的应用研究
- 解决svmtrain已被删除问题
- 励志: 我们来看看那些优秀的人的眼界和思想
- gammatone 滤波器详解及其MATLAB代码实现
- 索尼美能达50微-版本区别及实拍测评(sony/minolta)50 f2.8 macro
- IP/TCP协议详解
- 别坐在金矿上捡垃圾:给管理者的10条建议
热门文章
- vuze java运行环境_Vuze(Azureus)毒蛙 配置与种子制作(图解)
- Linux内核中的container_of宏
- PCA降维实例[GridSearchCV求最优参]
- mysql内存表的使用_Mysql内存表的用处
- 【编译原理】正规式转换成NFA
- RuntimeWarning: Glyph 8722 missing from current font. font.set_text(s, 0.0, flags=flags)
- 0e开头MD5 python生成脚本 PHP哈希弱类型比较缺陷
- 百度超级链、联通链亮相百度Create大会,助力产业数字化变革
- [渝粤教育] 西南科技大学 程序设计语言(C) 在线考试复习资料
- mysql源码分析——聚簇索引