ubuntu真机安装tljh jupyterhub支持跨域iframe

本文是我之前在安装和使用 jupyterhub 过程中的配置记录,仅作为思路参考。
#1 、操作系统

ubuntu18.04服务器版

http://mirrors.aliyun.com/ubuntu-releases/18.04/ubuntu-18.04.6-live-server-amd64.iso?spm=a2c6h.25603864.0.0.44745e15zs4NUw

#2、修改清华源

复制代码
sudo sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list & sudo apt update

#3、安装python

复制代码
apt-get install -y python-software-properties
apt-get install -y software-properties-common
add-apt-repository ppa:deadsnakes/ppa
apt-get update
apt-get -y install python3.6 python3.6-dev python3-pip python3.6-venv curl git

#4、修改python下载国内源

复制代码
mkdir ~/.pip & cd ~/.pip

vim pip.conf

[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com

#5、下载tljh安装包

复制代码
git clone https://github.com/jupyterhub/the-littlest-jupyterhub

 mv the-littlest-jupyterhub /opt

python3 /opt/the-littlest-jupyterhub/bootstrap/bootstrap.py  --admin admin

复制代码
python3 /opt/the-littlest-jupyterhub/bootstrap/bootstrap.py  --admin admin:密码

等待几分钟后 成功报错 都会有掉示 脚本只支持ubuntu的amd64位

arm64操作系统暂没有识配下载地址

#6、安装成功

复制代码
service jupyterhub start
service traefik start

#7、启动网址

复制代码
http:/ip

开放80端口

复制代码
sudo ufw allow 80

sudo ufw reload

#8、带日志启动

复制代码
service jupyterhub stop

/opt/tljh/hub/bin/python3 -m jupyterhub.app -f /opt/tljh/hub/lib/python3.6/site-packages/tljh/jupyterhub_config.py --upgrade-db

如果出来日志报错如图

运行报错:

CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team.x509。

解决方案:

复制代码
 /opt/tljh/hub/bin/pip uninstall cryptography

/opt/tljh/hub/bin/pip install -i https://mirror.baidu.com/pypi/simple --trusted-host mirror.baidu.com  cryptography==36.0.2

#9、Iframe不让新窗口打开修改方法

第一次查找

复制代码
find  /opt/tljh/user/ -name main.min.js

vim /root/one.sh 

内容如下所示 注意版本号

复制代码
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/nbclassic/static/tree/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/nbclassic/static/auth/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/nbclassic/static/notebook/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/nbclassic/static/terminal/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/nbclassic/static/edit/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/notebook/static/tree/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/notebook/static/auth/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/notebook/static/notebook/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/user/lib/python3.9/site-packages/notebook/static/terminal/js/main.min.js
sed -i 's/_blank/_self/' /opt/tljh/user/lib/python3.9/site-packages/notebook/static/edit/js/main.min.js

chmod +x /root/one.sh & /root/one.sh

第二次查找

复制代码
find  /opt/tljh/hub/ -name main.min.js

vim /root/two.sh 

sed -i 's/_blank/_self/'  /opt/tljh/hub/lib/python3.6/site-packages/notebook/static/tree/js/main.min.js
sed -i 's/_blank/_self/'  /opt/tljh/hub/lib/python3.6/site-packages/notebook/static/auth/js/main.min.js
sed -i 's/_blank/_self/' /opt/tljh/hub/lib/python3.6/site-packages/notebook/static/notebook/js/main.min.js
sed -i 's/_blank/_self/' /opt/tljh/hub/lib/python3.6/site-packages/notebook/static/terminal/js/main.min.js
sed -i 's/_blank/_self/' /opt/tljh/hub/lib/python3.6/site-packages/notebook/static/edit/js/main.min.js

chmod +x /root/two.sh & /root/two.sh

第三次修改 注意版本号

复制代码
vim /opt/tljh/user/lib/python3.9/site-packages/jupyterhub/handlers/base.py
vim /opt/tljh/hub/lib/python3.6/site-packages/jupyterhub/handlers/base.py
#按退出键:/frame-ancestors 修改下面的图
#上面两个shift+gg 最后一行注掉  # (r'/security/csp-report', CSPReportHandler),

修改如图所示

复制代码
vim /opt/tljh/hub/lib/python3.6/site-packages/jupyterhub/singleuser/mixins.py
vim /opt/tljh/user/lib/python3.9/site-packages/jupyterhub/singleuser/mixins.py

修改如图

#10、安装插件

复制代码
ln -s /opt/tljh/user/bin/pip3 /usr/local/bin/pip3
ln -s /opt/tljh/user/bin/pip3 /usr/local/bin/pip
ln -s /opt/tljh/user/bin/jupyter /usr/local/bin/jupyter

opt/tljh/user/bin/jupyter contrib nbextension install --sys-prefix
/opt/tljh/user/bin/pip  install jupyter_contrib_nbextensions

jupyter contrib nbextension install  --sys-prefix

#11、设置内存

复制代码
sudo tljh-config  set limits.memory '500M'
sudo tljh-config  set limits.cpu 1
sudo tljh-config   reload

#12、 开启启动

复制代码
sudo systemctl enable jupyterhub
sudo systemctl daemon-reload
sudo systemctl restart jupyterhub
sudo systemctl stop jupyterhub
sudo systemctl status jupyterhub

sudo systemctl enable traefik
sudo systemctl restart traefik
sudo systemctl status traefik

#14、参考文档

https://tljh.jupyter.org/en/latest/howto/index.html

https://github.com/jupyterhub/jupyterhub-idle-culler

https://tljh.jupyter.org/en/latest/topic/idle-culler.html

配置方法idle-culler

默认情况下,JupyterHub将每隔60秒ping用户笔记本服务器以检查其状态。每台空闲超过10分钟的服务器都将被淘汰。

复制代码
services.cull.every = 60
services.cull.timeout = 600

sudo tljh-config set services.cull.timeout <max-idle-sec-before-server-is-culled>
sudo tljh-config reload

sudo tljh-config set services.cull.every <number-of-sec-this-check-is-done>
sudo tljh-config reload
相关推荐
小码吃趴菜1 小时前
select/poll/epoll 核心区别
linux
Ghost Face...2 小时前
深入解析网卡驱动开发与移植
linux·驱动开发
小小ken2 小时前
ubuntu通过vmware workstation安装win10虚拟机简要步骤及排错
ubuntu·vmware·虚拟机
a41324472 小时前
在CentOS系统上挂载硬盘到ESXi虚拟机
linux·运维·centos
MMME~2 小时前
Linux下的软件管理
linux·运维·服务器
迷途之人不知返2 小时前
Linux操作系统的基本指令
linux·服务器
松涛和鸣2 小时前
DAY49 DS18B20 Single-Wire Digital Temperature Acquisition
linux·服务器·网络·数据库·html
BIBI20492 小时前
通过 Studio 3T 远程连接 CentOS 7 上的 MongoDB
linux·mongodb·centos·nosql·配置·问题解决·环境搭建
❀͜͡傀儡师2 小时前
docker部署BentoPDF应用
运维·docker·容器