在多个服务器上扩展 cronjobs
现在,我们有一台带有 cronjob 选项卡的服务器,可以发送每日电子邮件。我们想扩展该服务器。该应用程序是部署在亚马逊云中centos服务器上的标准zend框架应用程序。
我们已经处理了负载平衡、内容管理和管理部署。然而,cronjob 对我们来说仍然是一个问题,因为我们需要确保某些作业只执行一次。
例如,每日电子邮件 cronjob 只能由单个服务器执行一次。我正在寻找最好的方法来授权只有一台服务器只执行一次。
我正在考虑两种解决方案,但我想知道其他人是否也遇到同样的问题。
- 将其中一台服务器设置为“主服务器”,仅发送每日电子邮件。如果服务器出现故障,这将是一个问题,并且通常我们不希望有一个“特殊”服务器。这也意味着我们需要跟踪哪个服务器是主服务器。
- 有一个要执行的计划任务队列。每个服务器打开该队列并查看需要执行哪些任务。 “抓取”任务的第一个服务器将执行该任务并将其标记为已完成。我正在寻找亚马逊简单排队服务作为队列的解决方案。
这两种解决方案都有优点和缺点,我想知道是否有人想到了其他可以帮助我们的解决方案。
right now, we have a single server with a cronjob tab that sends out daily emails. We would like to scale that server. The application is standard zend framework application deployed on centos server in amazon cloud.
We already took care of the load balancing, content management and managing deployment. However, the cronjob is still an issue for us, as we need to grantee that some jobs are performed only once.
For example, the daily emails cronjob must only be executed once by a single server. I'm looking for the best method to grantee only one server will execute it only once.
I'm thinking about 2 solutions, but i was wondering if someone else had the same issue.
- Make one of the servers "master", who only sends out the daily emails. That will be an issue, if the server malfunction, and generally we don't want to have a "special" server. It would also means we will need to keep track which server is master.
- Have a queue of schedule tasks to be performed. Each server open that queue and sees which tasks needed to be performed. The first server who "grab" the task, will preform the task and mark it as done. I was looking at amazon simple queuing service as a solution for the queue.
Both these solutions have advantages and disadvantages, and i was wondering if someone thought about someone else that might help us here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您需要扩展 cron 作业时,最好使用作业管理器,例如 Gearman
When you need to scale out cron jobs, you are better off using a job manager like Gearman
Beanstalkd 也可能是您的一个选择。
Beanstalkd could also be an option for you.
我也有同样的问题。我所做的非常简单。
我希望这是有道理的!现在,无论您拥有多少台服务器,它都可以扩展!另外,你的 cronjob 服务器的唯一功能就是运行简单的作业来发送请求,仅此而已。
I had the same problem. What I did was dead simple.
I hope that makes sense! Now it doesn't matter how many servers you have, it will just scale! Also, your cronjob server's only function is to run dead simple jobs to send a request, nothing more.