本页面介绍如何配置虚拟机以从 Artifact Registry Yum 代码库安装 RPM 软件包。Artifact Registry Yum 代码库支持 yum 和 dnf 客户端。
准备工作
如果目标 Yum 代码库不存在, 请创建新代码库。您可以创建私有代码库,也可以创建不需要身份验证的公共代码库。
准备虚拟机以访问 Yum 代码库
如需准备虚拟机以访问 Yum 代码库,请使用 yum 或 dnf 客户端工具:
私有代码库
选择您将用于授予访问权限的服务帐号。
准备虚拟机以访问代码库。
Compute Engine 虚拟机
向虚拟机分配
cloud-platformAPI 访问权限范围 。如需了解如何设置访问权限 范围,请参阅 更改实例的服务帐号和访问权限范围。使用以下命令更新软件包缓存:
sudo yum makecache使用以下命令在虚拟机上安装 Artifact Registry 插件:
sudo yum install FORMAT-plugin-artifact-registry替换以下内容:
- 将
FORMAT替换为以下项之一:- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
yum - 如果您的操作系统是 Enterprise Linux 8 或更高版本,请替换为
dnf
- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
- 将
其他虚拟机
使用以下命令安装 RPM 签名密钥:
sudo rpm --import https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg创建一个名为
/etc/yum.repos.d/artifact-registry-plugin.repo的文件,其中包含以下内容:[ar-plugin] name=Artifact Registry Plugin baseurl=https://packages.cloud.google.com/yum/repos/FORMAT-plugin-artifact-registry-DISTRO-stable enabled=1 gpgcheck=1
替换以下内容:
- 将
FORMAT替换为以下项之一:- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
yum - 如果您的操作系统是 Enterprise Linux 8 或更高版本,请替换为
dnf
- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
- 将
DISTRO替换为 Red Hat Enterprise Linux 主要版本,格式为elX,其中X是版本 号。有效的DISTRO值示例包括el7和el8。
- 将
使用以下命令更新 Yum:
sudo yum makecache使用以下命令在虚拟机上安装 Artifact Registry 插件:
yum install FORMAT-plugin-artifact-registry将
FORMAT替换为以下项之一:- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
yum - 如果您的操作系统是 Enterprise Linux 8 或更高版本,请替换为
dnf
- 如果您的操作系统是 Enterprise Linux 7 或更早版本,请替换为
在
artifact-registry.conf文件中找到#service_account_json = "/path/to/creds.json"行,然后取消该行的注释并添加服务帐号密钥的路径。- 对于 Enterprise Linux 7 或更早版本的操作系统,配置文件的路径为
/etc/yum/pluginconf.d/artifact-registry.conf。 - 对于 Enterprise Linux 8 或更高版本的操作系统,配置文件的路径为
/etc/dnf/plugins/artifact-registry.conf。
配置文件条目:
service_account_json = "PATH_TO_SERVICE_ACCOUNT_KEY"
将
PATH_TO_SERVICE_ACCOUNT_KEY替换为服务帐号密钥 JSON 文件的路径。- 对于 Enterprise Linux 7 或更早版本的操作系统,配置文件的路径为
公共代码库
配置虚拟机以访问标准 Yum 代码库
如需配置虚拟机以访问 Yum 代码库,请使用 yum 或 dnf 客户端工具:
运行
gcloud beta artifacts print-settings yum命令,生成虚拟机配置命令:gcloud beta artifacts print-settings yum \ --repository=REPOSITORY \ --location=LOCATION替换以下内容:
REPOSITORY是 Artifact Registry 代码库的名称。-
LOCATION是代码库的区域 位置。
输出类似于以下内容:
# To configure your package manager with this repository: # Update Yum: sudo yum makecache # Install the Yum credential helper: sudo yum install yum-plugin-artifact-registry # Configure your VM to access Artifact Registry packages using the following # command: sudo tee -a /etc/yum.repos.d/artifact-registry.repo << EOL [REPOSITORY] name=REPOSITORY baseurl=https://LOCATION-yum.s3nsregistry.fr/projects/PROJECT/REPOSITORY enabled=1 repo_gpgcheck=0 gpgcheck=0 EOL # Update Yum: sudo yum makecache
使用
print-settings命令输出中的tee命令,将yum客户端工具配置为从您的代码库提取软件包。例如,如需从项目
my-project中位置为u-france-east1的公共my-repo安装软件包,请使用以下命令:sudo tee -a /etc/yum.repos.d/artifact-registry.repo << EOL [my-repo] name=My Repository baseurl=https://u-france-east1-yum.s3nsregistry.fr/projects/my-project/my-repo enabled=1 repo_gpgcheck=0 gpgcheck=0 EOL
使用以下命令更新代码库来源:
sudo yum makecache
Yum 现在可以连接到代码库。
如果您创建其他 Yum 代码库,请在 /etc/yum.repos.d/ 中为每个代码库创建一个 .repo 文件
。重新运行 sudo yum update 以更新代码库来源。