文章目录

0 现存问题

不知道jupyterhub的账号和密码,无法登陆,还望大佬指点。

1 安装npm

指令如下:

$ cd  /usr/local/node/   没有目录就自己创建一个

$ wget https://npm.taobao.org/mirrors/node/v12.21.0/node-v12.21.0-linux-x64.tar.gz

$ tar -zxvf node-v12.21.0-linux-x64.tar.gz

$ rm -rf node-v12.21.0-linux-x64.tar.gz


$ ln -s /usr/local/node/node-v12.21.0-linux-x64/bin/npm /usr/local/bin/npm

$ ln -s /usr/local/node/node-v12.21.0-linux-x64/bin/node /usr/local/bin/node

$ npm -v

$ npm install -g configurable-http-proxy

2 安装Anaconda

JupyterHub是基于Python的,所以我们需要安装一下Python的相关环境。Anaconda是一个非常成熟的Python包管理工具。这里是用下载好的Anaconda直接安装。

$ bash Anaconda3-2020.07-Linux-x86_64.sh

3 安装Jupyterhub

$ pip3 install jupyterhub notebook -i https://pypi.douban.com/simple/
$ jupyterhub -h

4 修改配置文件

4.1 生成密码

生成密码:

$ jupyter notebook password

$ ipython
$ from notebook.auth import passwd
$ p = passwd()
$ print(p)

生成的密码例如下面的内容,把password后的密码复制到c.NotebookApp.password后面:

(base) [root@kfk-32 jupyterhub]# cat /root/.jupyter/jupyter_notebook_config.json
{
"NotebookApp": {
"password": "argon2:$argon2id$v=19$m=10240,t=10,p=8$toCrDkFT9Lywptk/Jbat4A$HWCn+wAfIoeGJUO2KLueKg"
}

4.2 修改配置

生成配置文件:

$ mekdir -vp /etc/jupyterhub
$ jupyterhub --generate-config -f /etc/jupyterhub/jupyterhub_config.py
$ cd /etc/jupyterhub/
$ vi jupyterhub_config.py

修改配置文件为:

修改地方:

  • c.JupyterHub.ip/c.JupyterHub.port:JupyterHub的地址和端口
  • c.JupyterHub.proxy_cmd:之前npm安装configurable-http-proxy代理的地方
  • c.Authenticator.whitelist:白名单
  • c.Authenticator.admin_users:管理用户
  • c.LocalAuthenticator.group_whitelist:白名单分组
  • c.NotebookApp.password:密码
c.NotebookApp.open_browser = True
c.JupyterHub.ip = '10.20.3.32'
c.JupyterHub.port = 12344
c.Spawner.ip = '127.0.0.1'
c.PAMAuthenticator.encoding = 'utf-8'
c.LocalAuthenticator.create_system_users = True
c.Authenticator.whitelist = {'root'}
c.Authenticator.admin_users = {'root'}
c.LocalAuthenticator.group_whitelist = {'group1'}
c.JupyterHub.statsd_prefix = 'jupyterhub'
c.Spawner.notebook_dir = '/bigData/study/'
c.Spawner.env_keep.append('LD_LIBRARY_PATH')
c.NotebookApp.password = "argon2:$argon2id$v=19$m=10240,t=10,p=8$1nnzpvmX7Y8rzw/vNVvE0Q$cmR5IBYxHFlqrBv+rAUkWw"
c.JupyterHub.proxy_cmd = ['/usr/local/node/node-v12.21.0-linux-x64/bin/configurable-http-proxy',]

如果需要使用root登录,需要修改配置
修改源码jupyterhub安装目录​​​/site-packages/jupyterhub/spawner.py​​​【我本机的在​​/root/anaconda3/lib/python3.8/site-packages/jupyterhub​​​】,找到如下代码块做修改,​​if self.disable_user_config:​​​后面添加​​args.append('--allow-root')​​,实现root访问与登陆。

5 启动JupyterHub

$ jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl

$ nohup jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl > /dev/null 2>&1 &
/root/anaconda3/lib/python3.8/site-packages/jupyterhub

jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl

nohup jupyterhub --config=/etc/jupyterhub/jupyterhub_config.py --no-ssl > /dev/null 2>&1 &