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
相关推荐
2501_924878739 分钟前
AdAgent 能力成熟度模型:从 L1 自动化到 L5 自主增长引擎
运维·自动化
寄存器漫游者11 分钟前
Linux 软件编程 命令、内核与 Shell
linux·运维·服务器
Kaede627 分钟前
服务器硬件防火墙和软件防火墙的区别
运维·服务器
qinyia34 分钟前
通过本地构建解决Cartographer编译中absl依赖缺失问题
linux·运维·服务器·mysql·ubuntu
郝亚军34 分钟前
ubuntu启一个udp server,由一个client访问
linux·ubuntu·udp
苦逼IT运维44 分钟前
从 0 到 1 理解 Kubernetes:一次“破坏式”学习实践(一)
linux·学习·docker·容器·kubernetes
萧曵 丶1 小时前
Docker 面试题
运维·docker·容器
七牛云行业应用1 小时前
3.5s降至0.4s!Claude Code生产级连接优化与Agent实战
运维·人工智能·大模型·aigc·claude
小草cys1 小时前
鲲鹏920服务器安装openEuler后无法联网,但物理网线已连接
运维·服务器·openeuler
Volunteer Technology1 小时前
FastDFS+Nginx
运维·nginx