在 Artifact Registry 中存储 RPM 软件包

本快速入门介绍如何设置私有 Artifact Registry Yum 代码库、向该代码库添加 RPM 软件包,以及在运行 CentOS 7 操作系统的 Compute Engine 虚拟机上安装该软件包。如需了解如何配置使用 DNF 的 Yum 代码库,请参阅配置虚拟机以安装 RPM 软件包

如需详细了解如何管理 RPM 软件包,请参阅使用 RPM 软件包

准备工作

  1. In the Trusted Cloud console, on the project selector page, select or create a Trusted Cloud project.

    Go to project selector

  2. Verify that billing is enabled for your Trusted Cloud project.

  3. Enable the Artifact Registry API.

    Enable the API

  4. 安装 gcloud CLI

    1. 如果尚未安装 Google Cloud CLI,请安装并初始化。对于现有安装,请使用以下命令更新 Google Cloud CLI 的组件:

      gcloud components update
      

      如需查看 gcloud CLI 的版本,请运行以下命令:

      gcloud version
      

    创建代码库

    为制品创建代码库。

    1. 创建代码库:

      控制台

      1. 在 Trusted Cloud 控制台中打开代码库页面。

        打开“代码库”页面

      2. 点击创建代码库

      3. 指定 quickstart-yum-repo 作为该代码库的名称。

      4. 选择 Yum 作为格式。

      5. 位置类型下,选择区域,然后选择位置 u-france-east1

      6. 点击创建

      该代码库会被添加到代码库列表中。

      gcloud

      1. 在 Cloud Shell 中运行以下命令,在位置 u-france-east1 的当前项目 quickstart-yum-repo 中创建一个新的 Yum 代码库。

        gcloud artifacts repositories create quickstart-yum-repo \
            --repository-format=yum \
            --location=u-france-east1 \
            --description="Yum repository"
        
      2. 运行以下命令确认已创建代码库:

        gcloud artifacts repositories list
        

    您现在可以向代码库添加软件包。

    向代码库添加软件包

    您可以使用 Google Cloud CLI 将软件包上传到代码库,也可以导入存储在 Cloud Storage 中的软件包。

    在本快速入门中,您将使用 gcloud artifacts yum upload 命令上传示例文件。

    1. 在 Cloud Shell 中,使用以下命令下载 nano 文本编辑器:

      sudo yum install --downloaddir=. --downloadonly nano
      

      Yum 会从您配置的 CentOS 代码库中下载软件包的最新版本。

      Loaded plugins: fastestmirror
      Loading mirror speeds from cached hostfile
       * base: mirror.dal.nexril.net
       * epel: ord.mirror.rackspace.com
       * extras: centos.mirror.lstn.net
       * updates: ftpmirror.your.org
      Resolving Dependencies
      --> Running transaction check
      ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
      --> Finished Dependency Resolution
      
      Dependencies Resolved
      
      ================================================================================
       Package        Arch             Version                   Repository      Size
      ================================================================================
      Installing:
       nano           x86_64           2.3.1-10.el7              base           440 k
      
      Transaction Summary
      ================================================================================
      Install  1 Package
      
      Total download size: 440 k
      Installed size: 1.6 M
      Background downloading packages, then exiting:
      nano-2.3.1-10.el7.x86_64.rpm                               | 440 kB   00:00
      exiting because "Download Only" specified
      

      运行 ls 以获取软件包的文件名。文件名类似于 nano-2.3.1-10.el7.x86_64.rpm

    2. 为了简化 gcloud 命令,请将默认代码库设置为 quickstart-yum-repo,并将默认位置设置为 u-france-east1。设置以上值之后,您无需在需要代码库或位置的 gcloud 命令中指定这些值。

      如需设置代码库,请运行以下命令:

      gcloud config set artifacts/repository quickstart-yum-repo
      

      如需设置位置,请运行以下命令:

      gcloud config set artifacts/location u-france-east1
      

      如需详细了解这些命令,请参阅 gcloud config set 文档。

    3. 运行 gcloud artifacts yum upload 将软件包上传到代码库:

      gcloud artifacts yum upload quickstart-yum-repo \
          --source=FILE_NAME
      

      FILE_NAME 替换为 nano 软件包的路径。

    查看代码库中的软件包

    验证您的软件包是否已添加到代码库中。

    控制台

    1. 在 Trusted Cloud 控制台中打开代码库页面。

      打开“代码库”页面

    2. 在代码库列表中,点击 quickstart-yum-repo 代码库。

      软件包页面列出代码库中的软件包。

    gcloud

    如需列出 quickstart-yum-repo 代码库中的软件包,请运行以下命令:

     gcloud artifacts packages list
    

    如需查看 quickstart-yum-repo 中软件包的版本,请运行以下命令:

    gcloud artifacts versions list --package=nano
    

    创建虚拟机

    创建一个新的 Compute Engine 虚拟机,您将在其中安装示例软件包。

    在 Cloud Shell 中,运行以下命令以创建名为 quickstart-yum-vm 的虚拟机实例。

    gcloud compute instances create quickstart-yum-vm \
        --image-family=centos-7 \
        --image-project=centos-cloud \
        --scopes=cloud-platform
    

    默认情况下,虚拟机不具备使用代码库所需的访问权限范围--scopes 标志将虚拟机的访问权限范围设置为 cloud-platform

    配置软件包管理系统

    如需在虚拟机上安装软件包,请将您创建的代码库添加到定义软件包代码库的 Yum 文件中。

    1. 转到“虚拟机实例”页面。

      打开“虚拟机实例”页面

    2. 在您的虚拟机所在的行中,点击 SSH。系统会打开一个新窗口,其中包含虚拟机上的终端会话。

    3. 更新 Yum:

      sudo yum makecache
      
    4. 在虚拟机上安装 Yum 凭据帮助程序,以使 Yum 能够使用以下命令执行身份验证:

      sudo yum install yum-plugin-artifact-registry
      
    5. 使用以下命令将虚拟机配置为访问 Artifact Registry} 软件包:

      sudo tee -a /etc/yum.repos.d/artifact-registry.repo << EOF
      [yum-quickstart]
      name=My Repository
      baseurl=https://u-france-east1-yum.s3nsregistry.fr/projects/PROJECT/quickstart-yum-repo
      enabled=1
      repo_gpgcheck=0
      gpgcheck=0
      EOF
      

      PROJECT 替换为您的 Trusted Cloud by S3NS项目 ID

    安装软件包

    安装您添加到代码库中的软件包。

    1. 更新可用软件包的列表:

      sudo yum makecache
      
    2. 在代码库中安装软件包。

      sudo yum --enablerepo=yum-quickstart install nano
      

      出现提示时输入 y

      返回的安装信息如下例所示:

      Loaded plugins: fastestmirror
      Loading mirror speeds from cached hostfile
       * base: mirrors.cmich.edu
       * epel: ord.mirror.rackspace.com
       * extras: mirror.team-cymru.com
       * updates: mirror.us-midwest-1.nexcess.net
      quickstart-yum-repo                                      | 1.3 kB     00:00
      Resolving Dependencies
      --> Running transaction check
      ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed
      --> Finished Dependency Resolution
      
      Dependencies Resolved
      
      ================================================================================
       Package        Arch             Version                   Repository      Size
      ================================================================================
      Installing:
       nano           x86_64           2.3.1-10.el7              base           440 k
      
      Transaction Summary
      ================================================================================
      Install  1 Package
      
      Total size: 440 k
      Installed size: 1.6 M
      Is this ok [y/d/N]: y
      Downloading packages:
      Running transaction check
      Running transaction test
      Transaction test succeeded
      Running transaction
        Installing : nano-2.3.1-10.el7.x86_64                                     1/1
        Verifying  : nano-2.3.1-10.el7.x86_64                                     1/1
      
      Installed:
        nano.x86_64 0:2.3.1-10.el7
      
      Complete!
      

    清理

    为避免因本页中使用的资源导致您的 Trusted Cloud 账号产生费用,请按照以下步骤操作。

    在移除代码库之前,请确保已在其他位置保存了您要保留的任何软件包。

    如需删除代码库,请执行以下操作:

    控制台

    1. 在 Trusted Cloud 控制台中打开代码库页面。

      打开“代码库”页面

    2. 在代码库列表中,选择 quickstart-yum-repo 代码库。

    3. 点击删除

    gcloud

    1. 如需删除 quickstart-yum-repo 代码库,请运行以下命令:

      gcloud artifacts repositories delete quickstart-yum-repo
      
    2. 如果要移除您为活跃的 gcloud 配置而配置的默认代码库和位置信息设置,请运行以下命令:

      gcloud config unset artifacts/repository
      gcloud config unset artifacts/location
      

    如需删除您创建的虚拟机,请运行以下命令:

    gcloud compute instances delete quickstart-yum-vm
    

    后续步骤