【问题标题】:AWS code deploy + bitbucket = failed (Error code HEALTH_CONSTRAINTS)AWS 代码部署 + bitbucket = 失败(错误代码 HEALTH_CONSTRAINTS)
【发布时间】:2016-12-10 06:30:03
【问题描述】:

我已经根据这篇文章设置了一切

https://aws.amazon.com/tw/blogs/apn/announcing-atlassian-bitbucket-support-for-aws-codedeploy/

这是我的环境:

实例(亚马逊 linux 的免费套餐)
- 已安装 apache 2.4

安全组
- 只有 22(只有我的 ip 可以访问)和 80 端口被打开

Iptables 停止

2 个角色已设置
- 一个用于链接 S3 bitbucket (附加自定义政策)
- 一个角色是部署组 (附加 AWSCodeDeployRole 策略)

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "codedeploy.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

尝试部署的脚本
https://s3.amazonaws.com/aws-codedeploy-us-east-1/samples/latest/SampleApp_Linux.zip

权限 /var/www/* 由具有 755 权限的 ec2-user 拥有

代理 服务编码部署代理状态 = AWS CodeDeploy 代理作为 PID 7200 运行

线索: 每次部署都会上传我的 s3 存储桶中的一些 zip 文件。

错误代码:HEALTH_CONSTRAINTS

有人知道部署失败的原因是什么吗?

update1 使用 iam 配置文件重新启动实例后,可以部署应用程序。但它仍然失败,当我点击查看事件时,有如下日志:

Error CodeScriptFailed
Script Namescripts/install_dependencies
MessageScript at specified location: scripts/install_dependencies run as user root failed with exit code 1
Log TailLifecycleEvent - BeforeInstall
Script - scripts/install_dependencies
[stdout]Loaded plugins: priorities, update-motd, upgrade-helper
[stdout]Resolving Dependencies
[stdout]--> Running transaction check
[stdout]---> Package httpd.x86_64 0:2.2.31-1.8.amzn1 will be installed
[stdout]--> Processing Dependency: httpd-tools = 2.2.31-1.8.amzn1 for package: httpd-2.2.31-1.8.amzn1.x86_64
[stdout]--> Processing Dependency: apr-util-ldap for package: httpd-2.2.31-1.8.amzn1.x86_64
[stdout]--> Running transaction check
[stdout]---> Package apr-util-ldap.x86_64 0:1.4.1-4.17.amzn1 will be installed
[stdout]---> Package httpd-tools.x86_64 0:2.2.31-1.8.amzn1 will be installed
[stdout]--> Processing Conflict: httpd24-2.4.23-1.66.amzn1.x86_64 conflicts httpd < 2.4.23
[stdout]--> Processing Conflict: httpd24-tools-2.4.23-1.66.amzn1.x86_64 conflicts httpd-tools < 2.4.23
[stdout]--> Finished Dependency Resolution
[stderr]Error: httpd24-tools conflicts with httpd-tools-2.2.31-1.8.amzn1.x86_64
[stderr]Error: httpd24 conflicts with httpd-2.2.31-1.8.amzn1.x86_64
[stdout] You could try using --skip-broken to work around the problem
[stdout] You could try running: rpm -Va --nofiles --nodigest

大家有什么问题吗?

【问题讨论】:

    标签: amazon-web-services aws-code-deploy


    【解决方案1】:

    这取决于您的部署配置,但基本上 1 次或多次部署失败。

    HEALTH_CONSTRAINTS:部署失败的实例太多 在指定的实例运行状况限制内成功部署

    http://docs.aws.amazon.com/codedeploy/latest/APIReference/API_ErrorInformation.html

    检查您的deployment configuration settings。部署的整体失败/成功基于这些设置。试试CodeDeployDefault.AllAtOnce,然后根据需要拨入。

    另外,请仔细检查AWS CodeDeploy Instance Health 设置,尤其是minimum-healthy-hosts

    【讨论】:

      【解决方案2】:

      错误代码 HEALTH_CONSTRAINTS 表示失败的实例多于预期,这由部署配置定义。

      关于部署失败原因的更多信息,在部署控制台https://region.console.aws.amazon.com/codedeploy/home?region=region#/deployments,您可以点击失败的部署ID,然后它将重定向到部署详细信息页面,其中包含指定部署中包含的所有实例,每行包含实例的生命周期事件。然后点击ViewEvents,如果有View Logs链接,就可以看到这个实例部署失败的原因了。

      如果控制台没有足够的信息来满足您的需求,那么可以在 less /var/log/aws/codedeploy-agent/codedeploy-agent.log 中找到实例上的日志。它包含最近部署的日志。

      【讨论】:

      • 我在日志中发现错误:InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Missing credentials - 请检查此实例是否使用 IAM 实例配置文件启动
      • 这样也行。您的部署都没有成功,因为您无权部署到它们……它们都失败了。
      • 如何授予此权限?我附加了 IAM 角色 ec2-s3-fullaccess 仍然失败
      • 将部署配置从 CodeDeployDefault.OneAtTime 更改为 CodeDeployDefault.AllAtOnce 现在可以正常工作了
      【解决方案3】:

      您要求在 appspec.yaml 文件中安装的依赖项之一与 httpd24-tools 服务之间似乎存在冲突。

      [stderr]Error: httpd24-tools conflicts with httpd-tools-2.2.31-1.8.amzn1.x86_64
      [stderr]Error: httpd24 conflicts with httpd-2.2.31-1.8.amzn1.x86_64
      [stdout] You could try using --skip-broken to work around the problem
      

      所以尝试解决依赖安装问题。您可以尝试在您的 ec2 上手动安装依赖项并找到此冲突的解决方案,当您解决它时,将解决方案带到您的 appspec.yaml 文件并通过代码部署安装依赖项。

      【讨论】:

        【解决方案4】:

        发生这种情况是因为 codeDeploy 通过点击实例来检查 ec2 实例的运行状况。在部署之前,您需要在实例上运行以下 bash 脚本并检查脚本是否有效。必须启动 httpd 服务。重启实例。

            #!/bin/bash
            sudo su
            yum update -y
            yum install httpd -y
            yum install ruby
            yum install aws-cli
            cd ~
            aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1
            chmod +x ./install
            ./install auto
            echo 'hello world' > /var/www/html/index.html
            hostname >> /var/www/html/index.html
            chkconfig httpd on
            service httpd start
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-07-10
          • 2017-01-01
          • 2018-12-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多