使用 Anaconda Enterprise 4 Repository 镜像 Anaconda 仓库#

开始之前#

您需要已经安装并配置了 Repository 实例。 由于 Repository 的大小,请务必配置具有足够磁盘空间的文件存储位置。 如果需要,请参阅文件存储位置的要求

完整的 Anaconda 镜像大约需要 650 GB。

您还需要安装 cas-mirror,因为它是推荐的镜像工具。

注意:anaconda-mirror 工具已被弃用,并且不会再进行更新。

镜像所有包#

您可以使用 cas-sync-api-v4 命令镜像Anaconda 仓库的部分或全部内容

$ cas-sync-api-v4 --help
usage: cas-sync-api-v4 [-h] [-f FILENAME] [--config] [--version]
                       [-l LOG_LEVEL] [-v]

Updates an Anaconda repository instance

optional arguments:
  -h, --help            show this help message and exit
  -f FILENAME, --file FILENAME
                        Configuration file location (Defaults to:
                        /home/abarto/.cas-mirror or /etc/cas-mirror)
  --config, --show-config
                        Show running configuration and exit
  --version             Print version and exit
  -l LOG_LEVEL, --log-level LOG_LEVEL
                        Set the log level (CRITICAL, ERROR, WARNING, INFO,
                        DEBUG)Default: INFO.
  -v, --verbose         Shorthand for --log-level DEBUG

cas-sync-api-v4 命令利用 anaconda-client 包公开的功能将远程包导入到现有站点。 它将所有包从默认的 repo.anaconda.com 通道镜像到 anaconda 用户帐户。 这些默认通道是

  1. 使用 anaconda 命令将 Anaconda Enterprise 4 Repository 的 URL 与站点关联

    anaconda config --set sites.myrepo.url "http://your-anaconda-repo/"
    

    注意:将 your-anaconda-repo 替换为您的 Repository 安装的 URL。

  2. 创建一个配置文件 sync.yaml,告诉 cas-sync-api-v4 要使用的站点

    dest_site: myrepo
    
  3. 使用 --config 参数检查配置是否有效

    $ cas-sync-api-v4 -f sync.yaml --config
    path: /home/ec2-user/sync.yaml
    remote_url: https://repo.anaconda.com/
    mirror_dir: /opt/cas-mirror
    platforms: ['osx-32', 'osx-64', 'win-32', 'win-64', 'linux-32', 'linux-64', 'linux-armv6l', 'linux-armv7l', 'linux-ppc64le']
    fetch_installers: True
    repodata_source: False
    dir_names: ['archive']
    server_log_dir: None
    server_port: None
    dest_site: myrepo
    dest_channel: anaconda
    verify_checksum: False
    delta: False
    delta_dir: None
    log_dir: None
    log_level: 20
    python_versions: []
    pkg_list: []
    license_blacklist: []
    blacklist: []
    whitelist: []
    channels:
        - https://repo.anaconda.com/pkgs/main/
        - https://repo.anaconda.com/pkgs/free/
        - https://repo.anaconda.com/pkgs/pro/
    

    通过此配置,cas-sync-api-v4 将所有默认通道的内容镜像到 myrepo 站点的 anaconda 帐户中。

  4. 运行 cas-sync-api-v4

    cas-sync-api-v4 -f sync.yaml
    
  5. 打开浏览器并加载此 URL 以验证镜像

    http://your-anaconda-repo/anaconda/
    

    注意:将 your-anaconda-repo 替换为您的 Repository 安装的 URL。

镜像部分包#

或者,您可能不想镜像所有包。 要镜像整个仓库的子集,请指定要包含的平台,或使用白名单、黑名单或 license_blacklist 功能来控制镜像哪些包,方法是将默认配置文件 $PREFIX/etc/anaconda-server/mirror/anaconda.yaml 复制到 $PREFIX/etc/anaconda-server/mirror/anaconda-custom.yaml

对于 Repository 2.27 或更新版本,示例 yaml 配置文件位于:$PREFIX/etc/anaconda-server/mirrorPREFIX 是 Repository 的安装位置,默认情况下是 ~anaconda-server/repo/etc/anaconda-server/mirror

此命令根据配置文件 anaconda-custom.yaml 中的设置镜像仓库

cas-sync-api-v4 -f anaconda-custom.yaml

有关更多信息,请参阅自定义镜像

离线镜像#

离线镜像通过同时使用 cas-synccas-sync-api-v4 完成。 首先,将所有包下载到具有 Internet 访问权限的主机上。

示例

要下载包,请创建一个名为 export.yaml 的配置文件

mirror_dir: /opt/mirror/export/
platforms:
  - linux-64
  - win-64
python_versions:
  - 2.7
  - 3.6
fetch_installers: false
pkg_list:
  - ca-certificates
  - certifi
  - libedit
  - libffi
  - libgcc-ng
  - libstdcxx-ng
  - ncurses
  - openssl
  - pip
  - python
  - readline
  - setuptools
  - sqlite
  - tk
  - wheel
  - xz
  - zlib

此示例仅下载默认通道的子集。

运行 cas-sync

cas-sync -f export.yaml

完成后,将在目录 /opt/mirror/export/pkgs 中为每个平台创建一个 conda 仓库。 现在,我们可以将目录 /opt/mirror/export/ 的内容移动到 air-gapped 环境。

要导入包,请创建一个名为 import.yaml 的配置文件

dest_site: mysite
dest_channel: anaconda
channels:
  - file:///opt/mirror/export/pkgs/
platforms:
  - linux-64
  - win-64
python_versions:
  - 2.7
  - 3.6

确保满足以下要求

  • 镜像到连接盒子的文件已放入 /opt/mirror/export 目录。

  • 名为 mysite 的 anaconda 站点已正确配置,并且用户已使用 anaconda 命令登录到该站点。

  • “mysite” 站点中存在“anaconda”帐户,并且登录用户有权访问该帐户。

在满足这些要求后,运行 cas-sync-api-v4

cas-sync-api-v4 -f import.yaml

使用已弃用的 anaconda-mirror 命令进行镜像#

anaconda-mirror 命令已弃用,但在某些安装中仍在使用。

它与命令 anaconda-mirror sync 一起使用,或者与配置文件(例如 anaconda-custom.yaml)以及命令 anaconda-mirror --config-file anaconda-custom sync 一起使用。

重置包#

使用 --reset 选项重置之前镜像的包

anaconda-mirror --config-file anaconda-custom sync --reset

这将重置仓库的“上次同步”时间,因此 anaconda-mirror 请求所有包,而不仅仅是自上次同步以来更改或添加的包。 在处理请求时,anaconda-mirror 仍会自动仅下载与仓库中当前文件不同的文件。

导出镜像#

要生成镜像归档

anaconda-mirror export mirror.tar

此命令根据配置的设置将包转储到文件 mirror.tar 中。

此镜像可用于 air gapped 环境。

导入镜像#

要在 air gapped 环境中镜像 Anaconda 仓库,请将 anaconda-mirror 指向导出的镜像归档。

挂载 USB 驱动器,然后运行

anaconda-mirror import $USB/mirror.tar

此命令将本地 Anaconda 仓库的内容镜像到您的 Anaconda Enterprise 4 Repository 安装中的“anaconda”用户名下。

筛选#

如果您想更新镜像上的过滤器(例如,排除其他许可证),再次运行 anaconda-mirror sync 会检索与此过滤器匹配的新包,但它不会删除不再与过滤器匹配的现有包。

要查看哪些包不再与您的过滤器匹配

anaconda-mirror clean --dry-run

要从镜像中删除这些包

anaconda-mirror clean

镜像其他通道#

如果从 air gap 归档文件镜像,则以下配置中的通道指向归档文件展开到的本地目录。

此外,如果下载了特定于平台的归档文件,则配置文件需要 platforms 部分。 以下各节中的示例假设 x64-repo-mirrors-\*.tar <airgap-archive-mirrors> 展开为 $MIRRORS_ARCHIVE

同样,对于在线系统,通道指向 Anaconda.org。 平台是可选的,并将镜像的 conda 包限制为指定的平台。

镜像 R 通道#

  1. 创建 yaml 配置文件。

    示例:以下是用于从仅包含 x64 包的 air gap 归档文件镜像的配置

    cat $PREFIX/etc/anaconda-server/mirror/r.yaml
    
    channels:
      - file://$MIRRORS_ARCHIVE/r/pkgs
    
    # The platforms should correspond to the platforms contained in
    # the archive. Omit if the archive contains conda packages for all platforms.
    platforms:
      - linux-64
      - osx-64
      - win-64
    

    示例:以下是用于在线系统的配置

    cat $PREFIX/etc/anaconda-server/mirror/r.yaml
    
    channels:
      - https://conda.anaconda.org/r
    
  2. 将包镜像到 r-channel

    anaconda-server-sync-conda --mirror-config \
        $PREFIX/etc/anaconda-server/mirror/r.yaml --account=r-channel
    

镜像 AEN 的 Wakari 通道#

  1. 创建 yaml 配置文件。

    示例:以下是用于从仅包含 x64 包的 air gap 归档文件镜像的配置

    cat $PREFIX/etc/anaconda-server/mirror/wakari.yaml
    
    channels:
      - file://$MIRRORS_ARCHIVE/wakari/pkgs
    
    # The platforms should correspond with the platforms contained in
    # the archive. Omit if the archive contains conda packages for all platforms.
    platforms:
      - linux-64
      - osx-64
      - win-64
    

    示例:以下是用于在线系统的配置

    cat $PREFIX/etc/anaconda-server/mirror/wakari.yaml
    
    channels:
      - https://conda.anaconda.org/t/<TOKEN>/anaconda-nb-extensions
      - https://conda.anaconda.org/wakari
    

    注意:将 <TOKEN> 替换为您应随 Repository 许可证一起收到的 anaconda-nb-extensions 通道的令牌。

  2. 将包镜像到 Wakari 通道

    anaconda-server-sync-conda --mirror-config \
        $PREFIX/etc/anaconda-server/mirror/wakari.yaml --account=wakari
    

镜像用于集群管理的 anaconda-adam 通道#

  1. 创建 yaml 配置文件。

    示例:以下是用于从仅包含 x64 包的 air gap 归档文件镜像的配置

    cat $PREFIX/etc/anaconda-server/mirror/anaconda-adam.yaml
    
    channels:
      - file://$MIRRORS_ARCHIVE/anaconda-adam/pkgs
    
    # The platforms should correspond with the platforms contained in
    # the archive. Omit if the archive contains conda packages for all
    # platforms.
    platforms:
          * linux-64
          * osx-64
          * win-64
    

    示例:以下是用于在线系统的配置

    cat $PREFIX/etc/anaconda-server/mirror/anaconda-adam.yaml
    
    channels:
      - https://conda.anaconda.org/anaconda-adam
    
  2. 将包镜像到 anaconda-adam 通道

    anaconda-server-sync-conda --mirror-config \
        $PREFIX/etc/anaconda-server/mirror/anaconda-adam.yaml --account=anaconda-adam
    

配置 conda#

创建镜像后,您仍然需要配置 conda 以在此处而不是在默认的 Anaconda 仓库中搜索包。 您可以通过编辑您的 ~/.condarc 文件以添加适当的通道来完成此操作

channels:
    - http://<anaconda.repo.ipaddress>:<port>/conda/anaconda/

注意:将 <anaconda.repo.ipaddress> 替换为您的 Repository 安装的 URL。

注意:可以在用户级别或通过管理 conda 文件进行此配置更改,以强制所有内部用户使用您的本地 Anaconda 镜像,而不是查询 Anaconda 仓库。

注意:用户可以从 http://<anaconda.repository.addr>/downloads 下载预配置为搜索您的 Repository 的 Anaconda 安装程序。 要了解如何生成这些安装程序,请参阅自定义安装程序