当前位置: 首页 > news >正文

【DevOps】基于Nexus部署内网pypi代理镜像仓库操作手册

下面是使用 Nexus 配置 PyPI 代理和缓存的详细步骤。


Nexus 方案架构

我们将创建三种类型的仓库,并将它们组合成一个 Group 仓库,作为内网用户的唯一入口。

+----------------+      +--------------------------------------------------------+      +--------------------------+
|  内网机器 (无公网) |      |  Nexus Repository (内网)                               |      |  公网 |
|                |      |                                                        |      |                          |
| pip install    |----->| pypi-all-group (Group)                                  |      | Aliyun PyPI Mirror       |
| (index-url -> |      |   |                                                    |      | (mirrors.aliyun.com)     |
|  nexus group)  |      |   |--> pypi-internal-hosted (Hosted) [用于私有包]        |      |                          |
|                |<-----|   |--> pypi-aliyun-proxy (Proxy) [代理和缓存] ---------->|----->|                          |
+----------------+      +--------------------------------------------------------+      +--------------------------+

部署步骤(在 Nexus 管理界面操作)

1. 创建 PyPI Proxy 仓库

这是核心,用于代理阿里云 PyPI 镜像并缓存下载的包。

  1. 登录 Nexus 管理界面。
  2. 点击顶部菜单栏的齿轮图标 ⚙️(设置)。
  3. 在左侧菜单中选择 Repository -> Repositories
  4. 点击 Create repository 按钮。
  5. 选择 pypi (proxy)
  6. 配置仓库:
    • Name: pypi-proxy (给一个清晰的名字)
    • Remote storage: ``https://pypi.tuna.tsinghua.edu.cn`
  7. 点击页面底部的 Create repository
  8. 返回列表页,等待Status转换为“Online - Ready to Connect”
2. 创建 PyPI Hosted 仓库 (可选,未部署!)

这个仓库用于存放你们公司内部开发的私有 Python 包。即使现在没有,创建它也是一个好的实践。

  1. 再次点击 Create repository
  2. 选择 pypi (hosted)
  3. 配置仓库:
    • Name: pypi-internal-hosted
    • Storage: 选择一个 Blob Store。
  4. 点击 Create repository
3. 创建 PyPI Group 仓库 (统一入口)

这是内网开发者将要使用的统一地址。它会按顺序从其成员仓库中查找包。

  1. 再次点击 Create repository
  2. 选择 pypi (group)
  3. 配置仓库:
    • Name: pypi-all-group
    • Storage: 选择一个 Blob Store。
    • Group: 在左侧的 Available 列表中,将你刚刚创建的两个仓库(pypi-internal-hostedpypi-proxy移动到右侧的 Members 列表中
    • 重要: 调整顺序。将 pypi-internal-hosted 放在 pypi-proxy上面。这样 Nexus 会优先从你的私有仓库查找包,找不到时再去代理仓库查找。
  4. 点击 Create repository

现在,你的仓库列表里就有了这三个仓库,其中 pypi-all-group 就是我们需要的最终地址。

4. 配置内网机器的 pip.conf

修改内网机器的 ~/.pip/pip.conf 文件,将 index-url 指向 Nexus 的 Group 仓库。

mkdir ~/.pip
vim ~/.pip/pip.conf
[global]
index-url = http://10.2.0.100:8081/nexus/repository/pypi-proxy/simple[install]
trusted-host = 10.2.0.100
5. 测试和验证

第一次安装(从上游下载并缓存):
在内网机器上执行:

[root@10-2-0.2 ~]# pip install requests
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Looking in indexes: http://10.2.0.100:8081/nexus/repository/pypi-proxy/simple
Collecting requestsDownloading http://10.2.0.100:8081/nexus/repository/pypi-proxy/packages/requests/2.32.5/requests-2.32.5-py3-none-any.whl (64 kB)|████████████████████████████████| 64 kB 4.7 MB/s
Collecting charset_normalizer<4,>=2Downloading http://10.2.0.100:8081/nexus/repository/pypi-proxy/packages/charset-normalizer/3.4.4/charset_normalizer-3.4.4-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (153 kB)|████████████████████████████████| 153 kB 63.5 MB/s
Collecting urllib3<3,>=1.21.1Downloading http://10.2.0.100:8081/nexus/repository/pypi-proxy/packages/urllib3/2.5.0/urllib3-2.5.0-py3-none-any.whl (129 kB)|████████████████████████████████| 129 kB 59.3 MB/s
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3.9/site-packages (from requests) (3.2)
Collecting certifi>=2017.4.17Downloading http://10.2.0.100:8081/nexus/repository/pypi-proxy/packages/certifi/2025.10.5/certifi-2025.10.5-py3-none-any.whl (163 kB)|████████████████████████████████| 163 kB 82.4 MB/s
Installing collected packages: urllib3, charset-normalizer, certifi, requests
Successfully installed certifi-2025.10.5 charset-normalizer-3.4.4 requests-2.32.5 urllib3-2.5.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

此时,Nexus 的 pypi-aliyun-proxy 仓库会从阿里云下载 requests 包,并缓存到其 Blob Store 中。

验证缓存:
你可以登录 Nexus UI,进入 pypi-aliyun-proxy 仓库的页面,在 BrowseSearch 组件中搜索 requests,你就能看到它已经被成功缓存了。

第二次安装(从本地缓存加载):

pip uninstall -y requests
pip install requests

这次安装速度会非常快,因为 pip 直接从 Nexus 的缓存中获取文件,无需访问公网。

http://www.dtcms.com/a/494694.html

相关文章:

  • 微服务核心
  • 网站倒计时如何做自己的影视网站
  • 【DevOps】基于Nexus部署内网ubuntu 2204系统APT代理镜像仓库操作手册
  • 【开题答辩实录分享】以《开题报告 智能家居控制平台的构建》为例进行答辩实录分享
  • 建设论坛网站视频稿定设计官网入口
  • 利用R绘制箱线图
  • 【架构相关】tsconfig.json 与 tsconfig.node.json、tsconfig.app.json 的关系和作用
  • 烟台seo网站推广电商网站 手续
  • GLM-4.1V-Thinking vLLM部署调用
  • 从“生物进化”到算法优化:遗传算法的5个核心阶段
  • C++复习(1)
  • 云原生与分布式架构的完美融合:从理论到生产实践
  • 学习Python 03
  • Python中子类对父类方法的继承与改写
  • 深度学习之yolov3
  • 大型营销型网站建设网站做个seo要多少钱
  • 广州南建站时间dz网站建设教程
  • 【征文计划】Rokid 语音指令开发教程 【包含工程源码 和体验包APK】
  • 网站开发工程师需要什么证书网站风险解除
  • 回文串oj
  • Linux系统--信号(3--信号的保存、阻塞)
  • Linux内核架构浅谈44-Linux slab分配器:通用缓存与专用缓存的创建与使用
  • 无用知识研究:在trailing return type利用decltype,comma operator在对函数进行sfinae原创 [二]
  • APDU交互代码模拟
  • Linux性能分析系统和虚拟文件系统缓存初始化
  • 用python做网站和用php网站建设验收单意见怎么写
  • 德芙巧克力网站开发方案怎样宣传一个网站
  • 模式识别与机器学习课程笔记(4):线性判决函数
  • 无人机空中定位与一键返航原理详解
  • P12874 [蓝桥杯 2025 国 Python A] 巡逻||题解||图论