# nexus **Repository Path**: ctllin/nexus ## Basic Information - **Project Name**: nexus - **Description**: pip npm conda maven 仓库配置 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-04 - **Last Updated**: 2026-09-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Nexus 私服搭建与使用文档(npm / conda / PyPI) 本机(`10.11.20.35`)已基于 **Nexus Repository Manager 3 (OSS) 3.37.3-02** 搭建完成三个语言的私有仓库服务: - **npm** —— 上游使用**淘宝源** `https://registry.npmmirror.com/` - **conda** —— 上游使用**清华源** `https://mirrors.tuna.tsinghua.edu.cn/anaconda/` - **PyPI(充当 devpi 角色)** —— 上游使用**清华源** `https://pypi.tuna.tsinghua.edu.cn/` > devpi 说明:Nexus 本身不支持 devpi 格式,因此采用 **Nexus 的 PyPI 仓库(proxy/group/hosted)** 充当 devpi 私服,功能等价:缓存 + 镜像清华 PyPI + 私有包上传。 --- ## 1. 服务基本信息 | 项目 | 值 | | --- | --- | | 管理界面 | http://nexus.com:18081/ | | 服务器 IP | 10.11.20.35 | | 账号 / 密码 | `admin` / `admin123` | | 服务安装目录 | `/home/software/nexus-3.37.3-02` | | 数据目录 | `/data/sonatype-work/nexus3` | | 端口 | `18081`(配置于 `etc/nexus-default.properties`) | ## 2. 仓库清单 ### 2.1 npm(上游:淘宝 npmmirror) | 仓库 | 类型 | 地址 | 用途 | | --- | --- | --- | --- | | `npmjs` | proxy | `http://nexus.com:18081/repository/npmjs/` | 镜像淘宝源 | | `npm-hosted` | hosted | `http://nexus.com:18081/repository/npm-hosted/` | 存放**私有** npm 包(发布) | | `npm-group` | group | `http://nexus.com:18081/repository/npm-group/` | 推荐统一入口(托管 + 淘宝镜像) | ### 2.2 conda(上游:清华 TUNA) | 仓库 | 类型 | 地址 | 用途 | | --- | --- | --- | --- | | `conda-main` | proxy | `http://nexus.com:18081/repository/conda-main/` | 清华 `pkgs/main`(对应 defaults) | | `conda-forge` | proxy | `http://nexus.com:18081/repository/conda-forge/` | 清华 `cloud/conda-forge` | | `conda-r` | proxy | `http://nexus.com:18081/repository/conda-r/` | 清华 `pkgs/r` | > 说明:Nexus 3.37 的 conda 格式不支持 group 仓库,因此客户端直接配置上面 3 个 channel 即可(conda 原生支持多 channel)。 ### 2.3 PyPI / devpi(上游:清华 TUNA) | 仓库 | 类型 | 地址 | 用途 | | --- | --- | --- | --- | | `pypi-proxy` | proxy | `http://nexus.com:18081/repository/pypi-proxy/simple/` | 镜像清华 PyPI | | `pypi-hosted` | hosted | `http://nexus.com:18081/repository/pypi-hosted/` | 存放**私有** Python 包(twine 上传) | | `pypi-group` | group | `http://nexus.com:18081/repository/pypi-group/simple/` | 推荐统一入口(托管 + 清华镜像) | --- ## 3. 客户端配置(使用私服) > 下面的示例文件均放在本目录:`npmrc.example`、`pip.conf.example`、`condarc.example`,可直接复制使用。 ### 3.1 npm —— 安装依赖走私服 在需要拉取依赖的机器上,编辑 `~/.npmrc`: ```ini registry=http://nexus.com:18081/repository/npm-group/ always-auth=true # 以下用于带认证访问(账号 admin / 密码 admin123) //nexus.com:18081/repository/npm-group/:username=admin //nexus.com:18081/repository/npm-group/:_password=YWRtaW4xMjM= ``` > `_password` 是密码 `admin123` 的 **base64**(`echo -n admin123 | base64`)。 也可以不写配置文件,临时指定: ```bash npm install --registry=http://admin:admin123@nexus.com:18081/repository/npm-group/ ``` #### 发布私有 npm 包 发布目标仓库是 `npm-hosted`(需要认证,Nexus npm 只认 Basic Auth,不支持 `_authToken`): ```ini registry=http://nexus.com:18081/repository/npm-hosted/ always-auth=true //nexus.com:18081/repository/npm-hosted/:username=admin //nexus.com:18081/repository/npm-hosted/:_password=YWRtaW4xMjM= ``` ```bash npm publish --registry http://nexus.com:18081/repository/npm-hosted/ ``` 发布后,团队其他成员通过 `npm-group` 即可安装到私有包(group 已包含 `npm-hosted`)。 ### 3.2 pip —— 安装 Python 包走私服(相当于用 devpi) 编辑 `/etc/pip.conf` 或 `~/.config/pip/pip.conf`: ```ini [global] index-url = http://admin:admin123@nexus.com:18081/repository/pypi-group/simple/ timeout = 120 retries = 3 [install] trusted-host = nexus.com ``` 也可以临时指定: ```bash pip install -i http://admin:admin123@nexus.com:18081/repository/pypi-group/simple/ --trusted-host nexus.com ``` #### 上传私有 Python 包 使用 `twine` 上传到 `pypi-hosted`: ```bash pip install twine build python -m build --wheel # 或在项目根目录 twine upload --repository-url http://nexus.com:18081/repository/pypi-hosted/ \ -u admin -p admin123 dist/* ``` 上传后,通过 `pypi-group` 即可安装私有包: ```bash pip install <私有包名> -i http://admin:admin123@nexus.com:18081/repository/pypi-group/simple/ --trusted-host nexus.com ``` ### 3.3 conda —— 配置 channel 走私服 编辑 `~/.condarc`(本机已配好,见 `condarc.example`): ```yaml channel_priority: flexible channels: - http://admin:admin123@nexus.com:18081/repository/conda-main/ - http://admin:admin123@nexus.com:18081/repository/conda-forge/ - http://admin:admin123@nexus.com:18081/repository/conda-r/ ``` 使用: ```bash conda search numpy # 从私服搜索 conda create -n myenv python=3.11 -y conda install -n myenv pandas ``` --- ## 4. 常用验证命令 ```bash # Nexus 状态 curl -s -u admin:admin123 http://nexus.com:18081/service/rest/v1/status # npm npm view react version --registry=http://admin:admin123@nexus.com:18081/repository/npm-group/ # pip pip index versions requests -i http://admin:admin123@nexus.com:18081/repository/pypi-group/simple/ --trusted-host nexus.com # conda conda search numpy --override-channels -c http://admin:admin123@nexus.com:18081/repository/conda-main/ ``` --- ## 5. 服务端运维 ### 5.1 启动 / 停止 / 重启 ```bash export INSTALL4J_JAVA_HOME=/home/software/jdk1.8.0_261 /home/software/nexus-3.37.3-02/bin/nexus start # 启动 /home/software/nexus-3.37.3-02/bin/nexus restart # 重启 /home/software/nexus-3.37.3-02/bin/nexus stop # 停止 ``` > 注意:系统 `java` 若不在 PATH 或版本不符,必须显式指定 `INSTALL4J_JAVA_HOME`。 ### 5.2 排查过的关键问题(重要) 1. **上游 HTTPS 全部报 `PKIX path building failed`(502)** - 原因:Nexus 使用的 JDK 8 自带 `cacerts` 被之前误改,只剩 1 个证书,导致无法信任淘宝/清华等公共 CA。 - 修复:用系统 CA 包重建了 `$JAVA_HOME/jre/lib/security/cacerts`(151 个证书),重启后恢复。 - 教训:**不要随意清空/精简 JVM 的 cacerts**;如需新增信任,用 `keytool -importcert` 追加。 2. **PyPI proxy 包页面全部 404** - 原因:`remoteUrl` 配成了 `https://pypi.tuna.tsinghua.edu.cn/simple/`,Nexus 拼接后变成 `/simple/simple/...`。 - 修复:`remoteUrl` 必须填 **PyPI 索引根地址** `https://pypi.tuna.tsinghua.edu.cn/`(不带 `/simple/`)。 3. **npm 发布(publish)报 401** - Nexus 的 npm 仓库只接受 Basic Auth 或 Bearer(API Token),`.npmrc` 里用 `username` + `_password`(base64)即可。 ### 5.3 SSL 证书导入(解决上游 HTTPS 502) 当 Nexus 访问上游 HTTPS 源报 `PKIX path building failed` 时,需要导入证书。脚本支持两种方式: **方式 1:本地 keytool 方式(Nexus 在本机)** 适用于可以直接访问 Nexus 服务器 JDK 的场景: ```bash ./nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --trust-cacerts npm,pypi,conda ``` 脚本会自动检测 JDK 的 cacerts 并使用 keytool 导入证书。导入后需要重启 Nexus。 **方式 2:Nexus API 方式(推荐,Nexus 在远程服务器)** 适用于无法直接访问 Nexus 服务器文件系统的场景(远程 Nexus): ```bash ./nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --trust-cacerts npm,pypi,conda --trust-api ``` 脚本会通过 Nexus 的 REST API (`/service/rest/v1/security/ssl/truststore`) 上传证书,立即生效,无需重启。 **API 方式的优势:** - 无需访问 Nexus 服务器的文件系统 - 证书立即生效,无需重启 Nexus - 支持远程导入 **注意事项:** - 需要 Nexus 3.x 支持 SSL 证书管理 API - 如果 API 调用失败,请使用本地 keytool 方式或通过 Nexus Web UI 手动导入 ### 5.4 独立 Blob Store 配置(推荐) Nexus 支持为每种语言配置独立的 blob store,便于存储管理和监控: ```bash # 默认配置:每种语言使用独立的 blobstore ./nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --configure npm,pypi,conda # 这将自动创建: # - npm-blob: 存储 npm 包 # - pypi-blob: 存储 PyPI 包 # - conda-blob: 存储 conda 包 # 自定义 blobstore 名称 ./nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 \ --npm-blobstore my-npm-storage \ --pypi-blobstore my-pypi-storage \ --conda-blobstore my-conda-storage \ --configure npm,pypi,conda # 所有语言使用同一个 blobstore(兼容旧配置) ./nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 \ --blobstore default \ --configure npm,pypi,conda ``` **优势:** - 独立监控每种语言的存储使用情况 - 可以为不同语言配置不同的存储路径或磁盘 - 便于按语言清理或迁移数据 - 可以设置独立的存储配额 **注意:** - 新创建的仓库会使用对应的 blobstore - 已存在的仓库不会自动迁移,需要手动在 Nexus UI 中修改 - blobstore 路径默认在 `/data/nexus-blobs/` ### 5.5 新增一个上游 proxy 仓库(示例) ```bash curl -s -u admin:admin123 -X POST http://nexus.com:18081/service/rest/v1/repositories/npm/proxy \ -H 'Content-Type: application/json' \ -d '{ "name": "my-npm-proxy", "online": true, "storage": {"blobStoreName": "default", "strictContentTypeValidation": false}, "proxy": {"remoteUrl": "https://registry.npmmirror.com/", "contentMaxAge": 1440, "metadataMaxAge": 1440}, "negativeCache": {"enabled": true, "timeToLive": 1440}, "httpClient": {"blocked": false, "autoBlock": true, "connection": {"retries": 3, "timeout": 60, "enableCircularRedirects": false, "enableCookies": false, "useTrustStore": true}} }' ``` --- ## 6. 安全说明 - 仓库浏览/拉取**需要认证**(匿名访问未开启),客户端配置里已内嵌 `admin:admin123`。 - 建议后续为不同团队创建独立账号并只授予对应仓库的 `nx-repository-view-*-browse/read` 权限,不要共用 admin。 - 服务位于内网 `10.11.20.35:18081`,请勿对公网开放。 ------------------------------------------------------------- nexus-3.37.3-02 fuser -k 18081/tcp rm -rf /data/sonatype-work/nexus3/* mkdir /data/sonatype-work/nexus3/tmp mkdir /data/sonatype-work/nexus3/log # jdk路径必须是nexus使用的jdk bash import_certs.sh /home/software/jdk1.8.0_261 https://registry.npmmirror.com https://pypi.tuna.tsinghua.edu.cn https://mirrors.tuna.tsinghua.edu.cn https://maven.aliyun.com https://pypi.org/simple /home/software/startNexus.sh # 先删除再重新配置 bash nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --confirm --delete npm,pypi,conda bash nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --configure npm,pypi,conda #api方式 bash nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --trust-cacerts npm,pypi,conda --trust-api #服务器执行 bash nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --trust-cacerts npm,pypi,conda bash nexus_repo_mgr.sh http://nexus.com:18081 admin admin123 --list npm,pypi,conda conda clean --all -y conda create -n python3.13 python -y # npm 清理缓存 npm cache clean --force # 查看缓存位置 npm config get cache # 验证缓存完整性 npm cache verify #不使用缓存 npm install vue --prefer-online # pip 清理缓存 pip cache purge # 查看缓存位置和大小 pip cache info # 列出缓存内容 pip cache list pip uninstall pymilvus -y pip install pymilvus --no-cache-dir