使用 Anaconda Enterprise 4 镜像 Anaconda 存储库

注意:本文档适用于 Anaconda Repository 2.26 及更新版本。对于 2.23 到 2.25 的版本,请参阅2.23 文档。对于 2.23 之前的版本,请参阅2.20 文档

开始之前

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

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

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

注意:该anaconda-mirror工具已被弃用,不会再更新。

镜像所有包

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

$ 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

该工具将 Anaconda 存储库默认通道中的所有包镜像到anaconda用户帐户中。它利用anaconda-client包公开的功能将远程包导入现有站点。

  1. 使用以下anaconda命令将 Anaconda 存储库的 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将所有默认频道的内容镜像到站点的anaconda帐户中myrepo

  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/mirror. PREFIX是 Repository 的安装位置,默认为 ~anaconda-server/repo/etc/anaconda-server/mirror.

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

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

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

离线镜像

脱机镜像是通过使用cas-sync和 来完成的cas-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

完成后,会在目录中为每个平台创建一个 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目录中。
  • 命名的 anaconda 站点mysite已正确配置,并且用户已使用该anaconda命令登录到该站点。
  • 在“mysite”站点中存在一个“anaconda”帐户,登录用户可以访问它。

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

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

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

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

它与命令一起使用,或与配置文件(如命令)一起使用 。anaconda-mirror syncanaconda-custom.yamlanaconda-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导出的镜像存档。

挂载 U 盘,然后运行:

anaconda-mirror import $USB/mirror.tar

此命令将本地 Anaconda 存储库的内容镜像到用户名“anaconda”下的存储库安装。

过滤

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

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

anaconda-mirror clean --dry-run

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

anaconda-mirror clean

镜像附加通道

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

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

同样,对于在线系统,通道指向 Anaconda Cloud。平台是可选的,并将镜像的 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
    

    注意:替换<TOKEN>为 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 以在此处而不是在默认的 Anaconda 存储库中搜索包。您可以通过编辑~/.condarc文件来添加适当的频道来做到这一点:

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

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

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

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