本页面介绍了如何配置虚拟机以从 Artifact Registry Yum 代码库安装 RPM 软件包。Artifact Registry Yum 代码库支持 yum
和 dnf
客户端。
准备工作
如果目标 Yum 代码库不存在,请创建新代码库。您可以创建私有代码库或无需身份验证的公共代码库。
准备虚拟机以访问 Yum 代码库
如需准备虚拟机以访问 Yum 代码库,请使用 yum
或 dnf
客户端工具:
私有代码库
选择您将用于授予访问权限的服务账号。
向您的服务账号授予代码库访问权限。
准备虚拟机以访问代码库。
Compute Engine 虚拟机
为虚拟机分配
cloud-platform
API 访问权限范围。如需了解如何设置访问权限范围,请参阅更改实例的服务账号和访问权限范围。使用以下命令更新软件包缓存:
sudo yum makecache
使用以下命令在虚拟机上安装 Artifact Registry 插件:
sudo yum install FORMAT-plugin-artifact-registry
替换以下内容:
- 将
FORMAT
替换为以下项之一:yum
,如果您的操作系统是 Enterprise Linux 7 或更早版本dnf
(如果您的操作系统是 Enterprise Linux 8 或更高版本)
- 将
其他虚拟主机
使用以下命令安装 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
替换为以下项之一:yum
,如果您的操作系统是 Enterprise Linux 7 或更早版本dnf
(如果您的操作系统是 Enterprise Linux 8 或更高版本)
DISTRO
,其中elX
是 Red Hat Enterprise Linux 主要版本的格式,X
是版本号。有效的DISTRO
值示例包括el7
和el8
。
- 将
使用以下命令更新 Yum:
sudo yum makecache
使用以下命令在虚拟机上安装 Artifact Registry 插件:
yum install FORMAT-plugin-artifact-registry
将
FORMAT
替换为以下项之一:yum
,如果您的操作系统是 Enterprise Linux 7 或更早版本dnf
(如果您的操作系统是 Enterprise Linux 8 或更高版本)
在
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
以更新代码库来源。