2

p7zip在通过“用户数据”功能(使用)在 AWS 中启动基于 Amazon Linux 的 EC2 实例后,我尝试安装该软件包cloud-init

#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - p7zip

但是,由于p7zip在正常存储库中不可用并且需要启用 EPEL,因此它似乎没有正确获取包。

我的问题是:cloud-init在初始化 EC2 实例时,如何在获取包之前启用 EPEL?

4

3 回答 3

2

对于更新版本的 Amazon Linux,您需要将以下内容添加到 cloud-config 文件中:

yum_repos:
    epel_custom:
        name: Extra Packages for Enterprise Linux 6 - $basearch
        baseurl: http://download.fedoraproject.org/pub/epel/6/$basearch
        mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
        failovermethod: priority
        enabled: true
        gpgcheck: true
        gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 

是一个可以在启动时作为userdata使用的工作 cloud-config 文件的示例。

于 2017-05-09T15:13:46.083 回答
2
#cloud-config
# vim: syntax=yaml
#
# Add yum repository configuration to the system
#
# The following example adds the file /etc/yum.repos.d/epel_testing.repo
# which can then subsequently be used by yum for later operations.
yum_repos:
    # The name of the repository
    epel-testing:
        # Any repository configuration options
        # See: man yum.conf
        #
        # This one is required!
        baseurl: http://download.fedoraproject.org/pub/epel/testing/5/$basearch
        enabled: false
        failovermethod: priority
        gpgcheck: true
        gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
        name: Extra Packages for Enterprise Linux 5 - Testing
于 2016-10-07T07:33:11.527 回答
0

以下部分将使用 GPG 启用 EPEL。请注意,密钥是在初始引导时导入的。

#cloud-config
bootcmd:
  - [ cloud-init-per, once, gpg-key-epel, rpm, "--import", "https://archive.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7" ]
yum_repos:
  epel:
    name: EPEL
    mirrorlist: https://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=$basearch
    enabled: true
    gpgcheck: true
repo_update: true
repo_upgrade: all

来自https://github.com/trajano/terraform-docker-swarm-aws/blob/master/common.cloud-config

于 2019-03-21T03:08:29.217 回答