公司动态
5 分钟快速上手 Jupyter Enterprise Gateway:安装并启动你的第一个远程内核
5 分钟快速上手 Jupyter Enterprise Gateway安装并启动你的第一个远程内核【免费下载链接】enterprise_gatewayA lightweight, multi-tenant, scalable and secure gateway that enables Jupyter Notebooks to share resources across distributed clusters such as Apache Spark, Kubernetes and others.项目地址: https://gitcode.com/gh_mirrors/en/enterprise_gatewayJupyter Enterprise GatewayJupyter 企业网关是一个轻量级、多租户、可扩展且安全的网关服务它让 Jupyter Notebook 能够把内核启动到 Apache SparkYARN、Kubernetes、Docker Swarm 等分布式集群上实现资源共享与隔离。本教程面向新手带你用 5 分钟完成 Jupyter Enterprise Gateway 安装、启动服务并连接 JupyterLab启动你的第一个远程内核。什么是 Jupyter Enterprise Gateway传统 Jupyter Notebook 的内核只能运行在本地机器上计算资源有限无法利用集群的大规模算力。Jupyter Enterprise Gateway 解决了这一痛点它是一个独立的网关服务位于用户与集群之间负责在内核启动时把内核派遣到集群的指定节点上运行。它的核心能力包括远程内核可在网关本地、集群指定节点、或资源管理器YARN/Kubernetes调度节点上启动内核多租户多个用户共享同一套集群资源互不干扰安全通信客户端到网关再到内核的加密通信链路持久会话内核会话不会因为连接断开而丢失开箱即用的内核PythonIPython、RIRkernel、ScalaApache ToreeJupyter Enterprise Gateway 部署架构一览理解架构是快速上手的第一步。下图展示了客户端、网关与集群节点的关系整个数据流为客户端JupyterLab/Notebook→ Enterprise Gateway 网关 → 集群 Worker Node 上的远程内核。网关是唯一的调度中枢它通过enterprise_gateway/services/processproxies/目录下的进程代理框架管理内核生命周期核心逻辑可以查看 remotemanager.py 与 processproxy.py。安装 Jupyter Enterprise Gateway 前需要准备什么Python 3.8建议直接安装 Anaconda它自带 Jupyter Notebook、IPython 内核及常用科学计算库pip 或 conda用于安装网关包独立的 Python 环境重要⚠️Enterprise Gateway 与jupyter_client 7.0不兼容请把它安装到与 Notebook/Lab 分离的专用环境避免版本冲突Jupyter Enterprise Gateway 一键安装方法使用 pip 安装官方推荐pip install --upgrade jupyter_enterprise_gateway使用 conda 安装conda install -c conda-forge jupyter_enterprise_gateway安装完成后验证版本jupyter enterprisegateway --version安装细节可参考 installing-eg.md。如果你希望从源码构建可以克隆仓库git clone https://gitcode.com/gh_mirrors/en/enterprise_gateway。快速启动 Enterprise Gateway 服务启动网关非常简单一条命令即可jupyter enterprisegateway --ip0.0.0.0 --port_retries0--ip0.0.0.0对外网开放服务--port_retries0端口被占用时立即报错保证单实例运行建议加--log-levelDEBUG查看详细日志并通过--MappingKernelManager.cull_interval等参数开启空闲内核回收。完整启动选项可以运行jupyter enterprisegateway --help-all查看也可以参考 launching-eg.md。主程序入口代码位于 enterprisegatewayapp.py。连接 JupyterLab 到远程网关网关启动后让 JupyterLab 把内核管理委托给它。命令行方式jupyter lab --gateway-urlhttp://EG_HOST_IP:EG_PORT也可以写入jupyter_server_config.py配置文件c.GatewayClient.url http://EG_HOST_IP:EG_PORT集群环境下内核启动可能较慢建议同时调大超时--GatewayClient.connect_timeout60 --GatewayClient.request_timeout60。详细配置见 connecting-to-eg.md。启动你的第一个远程内核连接成功后在 JupyterLab 中点击新建按钮你会看到 Enterprise Gateway 提供的多种内核规格kernelspecPython 3本地/分布式R 与 ScalaApache ToreeSpark Python / R / ScalaYARN、Kubernetes、Conductor 集群版选择一个远程内核例如 Python 3 distributed点击启动即可。内核规格文件存放在 etc/kernelspecs/ 目录例如 python_distributed/kernel.json其中通过process_proxy配置了远程内核的启动方式。在 Notebook 中执行import socket; socket.gethostname()如果返回的是集群节点的主机名说明你的远程内核已经成功跑在集群上了让内核跑在集群上Spark YARN 与 Kubernetes 场景Enterprise Gateway 的真正价值在于对接资源管理集群。下面两张图展示了两种典型部署在 Spark YARN 场景下网关位于集群边缘节点通过 YARN 容器启动 Spark Driver 与 Executor内置多租户隔离与资源调度能力对应内核规格如 spark_python_yarn_cluster/kernel.json。在 Kubernetes 场景下网关与 JupyterHub 结合把内核封装为 Pod 运行支持 TensorFlow 等 GPU 镜像对应内核规格如 python_kubernetes/kernel.json。两种场景都基于可扩展的进程代理框架框架说明见 system-architecture.md。常见问题与排查技巧端口无法访问检查防火墙与--ip0.0.0.0参数确保网关监听在公网地址内核启动超时集群调度需要时间增大connect_timeout与request_timeout依赖冲突报错确认 Enterprise Gateway 安装在独立环境中未与jupyter_client 7.x混装远程节点缺内核Python/R 内核包需要在每个集群节点上安装更多排查经验见 troubleshooting.md。总结本文带你走完了 Jupyter Enterprise Gateway 安装、启动、连接与远程内核启动的全流程。只需 5 分钟你就能让 Jupyter Notebook 的计算能力扩展到整个集群。下一步不妨动手体验 Spark 与 Kubernetes 场景感受多租户与资源调度带来的效率提升【免费下载链接】enterprise_gatewayA lightweight, multi-tenant, scalable and secure gateway that enables Jupyter Notebooks to share resources across distributed clusters such as Apache Spark, Kubernetes and others.项目地址: https://gitcode.com/gh_mirrors/en/enterprise_gateway创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考