Jupyterub 产生
Jupyterub 产生得由 Jupyter 的局限性说起。Jupyter 是一款基于 python 的 web notebook 服务,目前有大多 python 数据挖掘与机器学习爱好者使用这款服务,其特性与 Ipytohn Notebook 差不多,准确说 Ipython Notebook 是一款提供增强型交互的功能的 shell,而 Jupyter 除了 Ipython 的功能,还加入了普通编辑器的通用功能,是一款带代码交互的动态文档 web 编辑器。然鹅,由于 Jupyter 只支持单用户的使用场景,作为一个可交互的 web 服务,只支持单用户模式实在让人难以理解。估计开发者也觉得这个问题太过鸡肋,于是 Jupyterhub 因有而生。
Jupyterhub 安装
1、修改 hosts
vi /etc/hosts
#增加以下内容
192.168.163.200 hadoop
2、安装 anconda
yum install -y bzip2
bash Anaconda3-5.3.0-Linux-x86_64.sh #注意,第一个 yes 后安装路径改在/opt 下,否则jupyterhub 多用户失败
vi /etc/profile
export PATH=/opt/anaconda3/bin:$PATH #添加环境变量
source /etc/profile
3、pip 配置国内源
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4、安装 nodejs 跟 npm
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_12.x | bash -
yum install -y nodejs
npm config set registry https://registry.npm.taobao.org
5、安装jupyterhub
pip install jupyterhub
pip install notebook
npm install -g configurable-http-proxy
Jupyterhub 配置
1、修改/etc/pam.d/login
vi /etc/pam.d/login
注释掉两行
#session required pam_loginuid.so
#session required pam_selinux.so open
2、配置jupyterhub
mkdir -p /etc/jupyterhub
cd /etc/jupyterhub
jupyterhub --generate-config
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mykey.key -out mycert.pem
修改 jupyterhub_config.py
vi jupyterhub_config.py
#修改或添加以下内容
c.JupyterHub.ip = '192.168.163.200' #修改为 jupyterhub 服务器 ip
c.JupyterHub.extra_log_file = '/var/log/jupyterhub.log'
c.PAMAuthenticator.open_sessions = False #新增
c.JupyterHub.ssl_cert = '/etc/jupyterhub/mycert.pem' #https 安全协议加证书位置,没有不加
c.JupyterHub.ssl_key = '/etc/jupyterhub/mykey.key' #https 安全协议加 key 位置,没有不加
3、jupyterhub 开机启动
yum install -y git
pip install git+https://github.com/jupyter/sudospawner
vi /lib/systemd/system/jupyterhub.service
#添加以下内容
[Unit]
Description=Jupyterhub
After=syslog.target network.target
[Service]
User=root
Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/opt/anaconda3/bin"
ExecStart=/opt/anaconda3/bin/jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
附:管理命令
systemctl daemon-reload
systemctl <start|stop|status> jupyterhub
systemctl enable jupyterhub #设置开机启动
参考资料
https://jupyterhub.readthedocs.io/en/stable/
https://github.com/jupyterhub/jupyterhub/wiki/Run-jupyterhub-as-a-system-service
https://zhuanlan.zhihu.com/p/57727463