AWS Elastic Beanstalk-为什么要对命令使用leader_only? [英] AWS Elastic Beanstalk - why would I use leader_only for a command?

查看:99
本文介绍了AWS Elastic Beanstalk-为什么要对命令使用leader_only?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个django应用程序,我打算通过Elastic Beanstalk将其部署到AWS.我试图理解为什么我需要为要为我的应用程序运行的容器命令指定"leader_only".有关此操作的更多详细信息,请参见此处.

它说:

此外,您可以使用leader_only.选择一个实例作为 Auto Scaling组的领导者.如果设置了Leader_only值 设为true,该命令仅在标记为的实例上运行 领袖.

如果由于要扩展应用程序而有多个实例在运行,是否不使用"leader_only"仅在一个实例上运行命令,而不会影响其余实例?我可能会误解它的目的,但这似乎并不理想,因为领导者中的环境可能与其他实例不同,并且最终用户可能会根据碰巧连接到哪个实例而获得不同的结果.

解决方案

从技术角度来看,弹性beantalk是自动伸缩组,当您部署某些组件时,您需要假设您的命令可以同时在多个ec2实例上执行

leader_only选项的主要目标是确保仅在一个ec2实例上执行命令.这对于使用情况(例如执行数据库迁移脚本,创建数据库等)很有用,这些情况只应在一个ec2上执行一次.因此leader_only只是一个标记,表明某些命令将仅在此实例上执行.

但是,您需要牢记,创建环境时会设置一次Leader属性,以防在自动缩放组中没有任何Leader的情况下Leader死亡并被新实例替换./p>

I am writing a django app which I plan on deploying to AWS via Elastic Beanstalk. I am trying to understand why I would need to specify 'leader_only' for a container command I want to run for my app. More details about this can be found here.

It says:

Additionally, you can use leader_only. One instance is chosen to be the leader in an Auto Scaling group. If the leader_only value is set to true, the command runs only on the instance that is marked as the leader.

If I have several instances running my app because I want to scale it, wouldn't using 'leader_only' run the command on only one instance, and not affect the rest? I am probably misunderstanding the purpose of it, but that seems non-ideal because the environment in the leader may differ from the other instances, and the end user may get different results depending on which instance they happen to connect to.

解决方案

From a technical point of view, elastic beanstalk is autoscaling group and when you deploy something you need to assume that potentially your commands can be executed simultaneously on several ec2 instances.

Main goal of the leader_only option is to make sure that your commands will be executed on only one ec2 instance. It is useful for use cases such as execution of the db migration scripts, creation of db, etc., that should be executed just once on one ec2. So leader_only is just a marker that some commands will be executed on this instance only.

However, you need to keep in mind, the leader attribute is set once on creation of your environment and in case if leader died and was replaced by new instance possible situation when you don't have any leaders in autoscaling group.

这篇关于AWS Elastic Beanstalk-为什么要对命令使用leader_only?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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