如何使用CloudFormation在Redhat中安装aws-cfn-bootstrap / cfn-init软件包? [英] How to install aws-cfn-bootstrap/cfn-init package in Redhat using CloudFormation?

查看:196
本文介绍了如何使用CloudFormation在Redhat中安装aws-cfn-bootstrap / cfn-init软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CloudFormation模板启动实例。实例已启动,但UserData节未完全执行,因为在Redhat 7 AMI中未安装 cfn-init / aws-cfn-bootstrap 软件包。我尝试手动安装 aws-cfn-bootstrap 软件包,但由于与python版本冲突而无法安装。

I am trying to launch a instance with CloudFormation Template. Instance was started but the UserData section was not executed completely because cfn-init/aws-cfn-bootstrap package was not installed in Redhat 7 AMI. I tried installing aws-cfn-bootstrap package manually but could not install due to the conflicts with python version.

这是CloudFormation模板的UserData部分

Here is the UserData section of CloudFormation Template

"UserData": {
                "Fn::Base64": {
                    "Fn::Join": [
                        "\n",
                        [
                            "#!/bin/bash",
                            "set -x",
                            "",
                            "INSTANCE_ID=`/opt/aws/bin/ec2-metadata --instance-id | cut -f2 -d' '`",
                            "REGION=`/opt/aws/bin/ec2-metadata --availability-zone| cut -f2 -d' ' | sed '$s/.$//'`",
                            {
                                "Fn::Join": [
                                    "",
                                    [
                                        "AID='",
                                        {
                                            "Fn::GetAtt": [
                                                "eip",
                                                "AllocationId"
                                            ]
                                        },
                                        "'"
                                    ]
                                ]
                            },
                            "aws ec2 associate-address --region $REGION --instance-id $INSTANCE_ID --allocation-id $AID"
                        ]
                    ]
                }
            }

cloud-init.log

cloud-init.log

Nov 12 03:55:27 localhost cloud-init: Cloud-init v. 0.7.6 running 'modules:config' at Thu, 12 Nov 2015 08:55:27 +0000. Up 19.01 seconds. 
Nov 12 03:55:28 localhost cloud-init: Cloud-init v. 0.7.6 running 'modules:final' at Thu, 12 Nov 2015 08:55:27 +0000. Up 19.67 seconds. 
Nov 12 03:55:28 localhost cloud-init: ++ /opt/aws/bin/ec2-metadata --instance-id 
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 4: /opt/aws/bin/ec2-metadata: No such file or directory 
Nov 12 03:55:28 localhost cloud-init: ++ cut -f2 '-d ' 
Nov 12 03:55:28 localhost cloud-init: + INSTANCE_ID= 
Nov 12 03:55:28 localhost cloud-init: ++ cut -f2 '-d ' 
Nov 12 03:55:28 localhost cloud-init: ++ sed '$s/.$//' 
Nov 12 03:55:28 localhost cloud-init: ++ /opt/aws/bin/ec2-metadata --availability-zone 
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 5: /opt/aws/bin/ec2-metadata: No such file or directory 
Nov 12 03:55:28 localhost cloud-init: + REGION= 
Nov 12 03:55:28 localhost cloud-init: + AID=eipalloc-XXXXXX 
Nov 12 03:55:28 localhost cloud-init: + aws ec2 associate-address --region --instance-id --allocation-id eipalloc-XXXXXX 
Nov 12 03:55:28 localhost cloud-init: /var/lib/cloud/instance/scripts/part-001: line 7: aws: command not found 
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,078 - util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [127] 
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,089 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts) 
Nov 12 03:55:28 localhost cloud-init: 2015-11-12 03:55:28,089 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/pyt
hon2.7/site-packages/cloudinit/config/cc_scripts_user.pyc'>) failed 


推荐答案

这是对我有用的东西,我没有完全相信这一点,因为我在一个aws论坛上找到了它,但是现在我找不到源链接...无论如何我不得不对其进行一些修改可以在redhat 6上为我工作,因此希望对其他人也有帮助。

Here's what worked for me, i'm not taking full credit for this as I found it on one of the aws forums but now i can't find the source link...anyway i had to modify it a bit to work for me on redhat 6 so hopefully it helps someone else as well.

这是模板中的Userdata部分,用于安装cfn-init脚本:

This is the Userdata section in the template to install the cfn-init scripts:

"UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
      "#!/bin/bash -xe\n",

      "### This is redhat 6. It supports cloud-init but Cfn packages need to be installed unlike AWS Linux. And they are installed in a different location\n",
      "# First enable EPEL\n",
      "rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm", "\n",
      "# Now install Python Setuptools(easy_install) and Pip", "\n",
      "yum -y install python-pip", "\n",
      "# Now install cfn scripts", "\n",
      "/usr/bin/easy_install --script-dir /opt/aws/bin https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz", "\n",
      "# Now fix the cfn-hup script and copy to init.d location as AWS does not do it for you", "\n",
      "cp -f `pip show aws-cfn-bootstrap 2> /dev/null | egrep  \"^Location\" | awk -F \":\" ' { print $2 }'`/init/redhat/cfn-hup /etc/init.d/", "\n",
      "chmod 755 /etc/init.d/cfn-hup", "\n",
      "chkconfig --add cfn-hup", "\n",

      "/opt/aws/bin/cfn-init -v ",
      " --stack ", { "Ref" : "AWS::StackId" },
      " --resource AppServer ",
      " --configsets Install ",
      " --region ", { "Ref" : "AWS::Region" }, "\n"
    ]]}}

这篇关于如何使用CloudFormation在Redhat中安装aws-cfn-bootstrap / cfn-init软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆