在 CentOS 8 上安装 cfn-bootstrap 实用程序的最佳方法

在 CentOS 8 上安装 cfn-bootstrap 实用程序的最佳方法

我正在 AWS 上研究基于 CentOS 8 的实例/启动配置,并希望使用 cfn-init 来管理一些设置/配置步骤。

但是,我发现提供的 RPM 无法部署,因为 Python2 和 Python3 的打包方式有很大不同,以至于 AWS 提供的 RPM 找不到它的依赖项。

我用来安装的命令是:yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm

这导致以下错误:

Error: 
 Problem: conflicting requests
  - nothing provides python >= 2.6 needed by aws-cfn-bootstrap-1.4-34.noarch
  - nothing provides python-setuptools needed by aws-cfn-bootstrap-1.4-34.noarch
  - nothing provides python-daemon needed by aws-cfn-bootstrap-1.4-34.noarch
  - nothing provides pystache needed by aws-cfn-bootstrap-1.4-34.noarch

我怀疑这是因为 CentOS <= 7 中的 python 现在是 CentOS8 中的 python2。

在这种情况下安装这些工具的最佳方法是什么?

答案1

因此,我最终决定解压 tarball 并通过 UserData 脚本执行安装。这是通过调整现有指南如何通过 CLI 执行此操作

这会导致脚本相当长,并且由于 AWS 工具在 Python3 上运行存在一些问题,因此下面的版本仅安装 Python2(对于我的用例,我只需要 Python,否则我会想办法解决这个问题)。

      "UserData" :  {"Fn::Base64" : {
        "Fn::Join" : ["", [
          "#!/bin/bash\n",
          "mkswap /dev/nvme1n1\n",
          "swapon /dev/nvme1n1\n",
          "yum -y update\n",
          "yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm\n",
          "yum -y install python2 python2-pip\n",
          "pip2 install pystache\n",
          "ln -s /usr/bin/python2 /usr/bin/python\n",
          "curl -O https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
          "tar xvf aws-cfn-bootstrap-latest.tar.gz\n",
          "cd aws-cfn-bootstrap-*/\n",
          "python setup.py build\n",
          "python setup.py install\n",
          "mkdir -p /opt/aws/bin\n",
          "ln -s /usr/init/redhat/cfn-hup /etc/init.d/cfn-hup\n",
          "chmod 775 /usr/init/redhat/cfn-hup\n",
          "ln -s /usr/bin/cfn-hup /opt/aws/bin/cfn-hup\n",
          "ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal\n",
          "ln -s /usr/bin/cfn-init /opt/aws/bin/cfn-init\n",
          "ln -s /usr/bin/cfn-get-metadata /opt/aws/bin/cfn-get-metadata\n",
          "ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal\n",
          "ln -s /usr/bin/cfn-send-cmd-event /opt/aws/bin/cfn-send-cmd-event\n",
          "ln -s /usr/bin/cfn-send-cmd-result /opt/aws/bin/cfn-send-cmd-result\n",
          "/opt/aws/bin/cfn-init -v",
            " --stack ", { "Ref" : "AWS::StackName" },
            " --resource VPNServerLaunchTemplate",
            " --region ", { "Ref" : "AWS::Region" }, 
            "\n"
        ]]
      }}
    }

编辑- 因此显然有一个兼容 Python3 的版本可以从https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-py3-latest.tar.gz。有关更多详细信息,请查看AWS 文档

相关内容