使用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 Enterprise 4仓库的URL与一个站点关联,使用 anaconda 命令:

    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完成。首先将所有包下载到具有互联网访问权限的主机上。

示例:

要下载这些包,请创建一个名为 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

完成后,每个平台的conda仓库都会在目录/opt/mirror/export/pkgs中创建。我们现在可以将目录/opt/mirror/export/的内容带到隔离环境中。

要导入包,请创建一个名为 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中。

此镜像可以在隔离的网络环境中使用。

导入镜像#

要在隔离环境中镜像Anaconda仓库,请将anaconda-mirror指向导出的镜像存档。

挂载USB驱动器,然后运行:

anaconda-mirror import $USB/mirror.tar

此命令将本地Anaconda存储库的内容镜像到您的Anaconda Enterprise 4存储库安装中,用户名为“anaconda”。

过滤#

如果你想更新镜像上的过滤器——例如,排除额外的许可证——再次运行anaconda-mirror sync会检索符合此过滤器的新包,但不会删除不再符合过滤器的现有包。

查看哪些包不再符合您的筛选条件:

anaconda-mirror clean --dry-run

要从您的镜像中移除这些包:

anaconda-mirror clean

镜像附加频道#

如果从气隙存档进行镜像,以下配置中的通道指向存档扩展到的本地目录。

此外,如果下载了特定平台的存档,则配置文件需要平台部分。以下部分中的示例假设 x64-repo-mirrors-\*.tar 被扩展为 $MIRRORS_ARCHIVE

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

镜像R通道#

  1. 创建yaml配置文件。

    示例:以下是一个配置,用于从一个仅包含x64软件包的隔离存档中进行镜像:

    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软件包的隔离存档中进行镜像:

    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
    

    注意:将 替换为您应该随仓库许可证一起收到的 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软件包的隔离存档中进行镜像:

    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/

注意:将 替换为您的 Repository 安装的 URL。

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

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