【1.6】JupyterHub——让Jupyter支持多用户

支持多用户的jupyter

一、安装

1.下载并安装Anaconda3

wget -c https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
bash Anaconda3-5.2.0-Linux-x86_64.sh

安装提示:

Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /root/.bashrc ? [yes|no]
[no] >>> /data/user/sam/.bashrc

修改环境变量

vim /etc/profile

# Anaconda 3
#export PATH=/data/software/anaconda3/bin:$PATH  #因为现在默认的是anaconda2里面的python2
alias activate3="source /data/software/anaconda3/bin/activate root"
alias deactivate3="source /data/software/anaconda3/bin/deactivate"

source /etc/profile

2.下载安装 jupyterhub

source /data/software/anaconda3/bin/activate root  #启动conda环境,如无提示,后续的操作,都需要在该环境下完成

conda install -c conda-forge jupyterhub

3、创建配置文件

jupyterhub --generate-config
提示:此时的工作路径是/data/software
Writing default config to: jupyterhub_config.py

4、修改配置文件

取消注释,根据注释提示,填写相关信息

c.JupyterHub.ip = 'IP地址'
c.Spawner.ip = '127.0.0.1'
c.JupyterHub.port = 6364
c.PAMAuthenticator.encoding = 'utf8'
c.LocalAuthenticator.create_system_users = True
c.Authenticator.whitelist = {'user1', 'user1', 'user3'}
c.Authenticator.admin_users = {'user1'}
c.LocalAuthenticator.group_whitelist = {'group1'}
c.JupyterHub.statsd_prefix = 'jupyterhub'

组白名单好像会让用户白名单失效?

5、启动JupyterHub

nohup jupyterhub --no-ssl > jupyterhub.log &

(在配置文件目录下执行此命令?)

8、测试访问

用IP+端口测试访问

9、用户管理

用户白名单的用户会自动添加,但无密码,需要修改密码才能登录;

adduser等

二、讨论

2.1.同时支持Python2和python3

Notebook的右上角点new 只看到 python 3 kernel,需要同时支持Python2和python3

查看目前的conda环境中的kernels

[root@pydev pydev]# jupyter-kernelspec list 
Available kernels: 
  python3    /data/software/anaconda3/share/jupyter/kernels/python3

查看是否安装了python2

python2 -m pip --version

然后,在该conda环境下通过Python2关联ipykernel

python2 -m pip install --upgrade ipykernel 
python2 -m pip install ipykernel
python2 -m ipykernel install --user

source activate anaconda2   ##这个是启动py2的conda环境
ipython kernel install

查看该环境下的kernels

jupyter-kernelspec list
Available kernels:
  python2    /root/.local/share/jupyter/kernels/python2
  python3    /data/software/anaconda3/share/jupyter/kernels/python3

重启,打开jupyterhub,就能看到py2和py3的切换了

参考资料:

个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn

Sam avatar
About Sam
专注生物信息 专注转化医学