【问题标题】:CodeDeploy Error : Fail to remove instance from LoadbalancerCodeDeploy 错误:无法从负载均衡器中删除实例
【发布时间】:2020-05-07 16:40:44
【问题描述】:

我在 AWS 控制台中遇到以下代码部署错误

LifecycleEvent - ApplicationStop
Script - scripts/deregister_from_elb.sh
[stderr]Running AWS CLI with region: us-east-1
[stderr]Started deregister_from_elb.sh at 2020-01-21 10:53:43
[stderr]Checking that user set at least one load balancer
[stderr]Checking validity of load balancer named 'lb'
[stderr]Checking health of 'i-xxxxxxxxxxxxxxxx' as known by ELB 'lb'
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Deregistering i-xxxxxxxxxxxxxxxx from lb
[stderr]Waiting for instance to de-register from its load balancers
[stderr]Checking 2 times, every 70 seconds, for instance i-xxxxxxxxxxxxxxxx to be in state OutOfService
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Instance is currently in state: InService
[stderr]Checking status of instance 'i-xxxxxxxxxxxxxxxx' in load balancer 'lb'
[stderr]Instance is currently in state: InService
[stderr]Instance failed to reach state, OutOfService within 140 seconds
[stderr][FATAL] Failed waiting for i-xxxxxxxxxxxxxxxx to leave lb

在检查 EC2 实例中的代码部署代理日志文件时,它的显示

ERROR [codedeploy-agent(14347)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: scripts/deregister_from_elb.sh failed with exit code 1 -
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:183:in `execute_script'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:129:in `block (2 levels) in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:117:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:117:in `block in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:208:in `create_script_log_file_if_needed'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:115:in `execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:158:in `block (3 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:146:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:146:in `block (2 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:68:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:114:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:96:in `acknowledge_and_process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:75:in `block in perform'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `call'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/opt/codedeploy-agent/vendor/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'
/opt/codedeploy-agent/vendor/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `call'
/opt/codedeploy-agent/vendor/gems/logging-1.8.2/lib/logging/diagnostic_context.rb:323:in `block in create_with_logging_context'
2020-01-21 10:54:56 WARN  [codedeploy-agent(14347)]:
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2020-01-21 10:54:56 WARN  [codedeploy-agent(14347)]: 
InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Calling PutHostCommandComplete: "Code Error" 
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1597_deb.
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: Version file found in /opt/codedeploy-agent/.version with agent version OFFICIAL_1.0-1.1597_deb.
2020-01-21 10:54:56 INFO  [codedeploy-agent(14347)]: [Aws::CodeDeployCommand::Client 200 0.186875 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"Script at specified location: scripts/deregister_from_elb.sh failed with exit code 1\",\"log\":\"\"}"},host_command_identifier:"1YmxpYzAwMS9hcm46YXdzOnNkczp1cy1lYXN0LTE6MTMxMjE0OTI1MjQ1OmRlcGxveW1lbnQvZC1LVjgyTVRPNTIiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6MTMxMjE0OT1MjQ1Omluc3RhbmNlL2ktMDFhMGFiMjlhMWM2NjEwNjJ8MXwwIiwiY29tbWFuZE5hbWUiOiJBcHBsaWNhdGlvblN0b3AiLRleCI6MX0=") 

我通过删除 /opt/codedeploy-agent/deployment-root 文件夹中的所有内容并重新启动 code-deploy 代理服务暂时解决了这个问题。但是这个问题会在一段时间后重复出现。有谁知道它为什么会发生?

【问题讨论】:

  • 脚本 scripts/deregister_from_elb.sh 正在退出,错误代码 5 表示访问被拒绝。我会检查那个脚本并尝试看看它到底在做什么。
  • 那是你的剧本吗?
  • 脚本因访问被拒绝错误而失败。您需要检查代码执行情况,尤其是文件操作。将 -xev 标志添加到 !#/usr/bin/bash 行,然后重试。这将产生详细的日志记录,并应向您显示错误所在。

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


【解决方案1】:

脚本scripts/deregister_from_elb.sh 因访问被拒绝错误而失败。您需要检查代码执行情况,尤其是文件操作。将 -xev 标志添加到 !#/usr/bin/bash 行(使其读取为 !#/usr/bin/bash -xev,然后重试。这将产生详细的脚本错误日志记录,并应显示错误所在。

【讨论】:

    【解决方案2】:

    我假设你正在使用这个脚本:

    最好的办法是在执行此脚本期间查看 CloudTrail 事件,以查看任何失败的 ELB 调用(特别是“DeregisterInstancesFromLoadBalancer”和“DescribeInstanceHealth”调用)。 AWS CodeDeploy 控制台为您提供生命周期脚本运行的准确时间。似乎 ELB 无法彻底注销 EC2 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多