在多个服务器上扩展 cronjobs

发布于 2024-11-16 10:47:50 字数 531 浏览 3 评论 0原文

现在,我们有一台带有 cronjob 选项卡的服务器,可以发送每日电子邮件。我们想扩展该服务器。该应用程序是部署在亚马逊云中centos服务器上的标准zend框架应用程序。

我们已经处理了负载平衡、内容管理和管理部署。然而,cronjob 对我们来说仍然是一个问题,因为我们需要确保某些作业只执行一次。

例如,每日电子邮件 cronjob 只能由单个服务器执行一次。我正在寻找最好的方法来授权只有一台服务器只执行一次。

我正在考虑两种解决方案,但我想知道其他人是否也遇到同样的问题。

  1. 将其中一台服务器设置为“主服务器”,仅发送每日电子邮件。如果服务器出现故障,这将是一个问题,并且通常我们不希望有一个“特殊”服务器。这也意味着我们需要跟踪哪个服务器是主服务器。
  2. 有一个要执行的计划任务队列。每个服务器打开该队列并查看需要执行哪些任务。 “抓取”任务的第一个服务器将执行该任务并将其标记为已完成。我正在寻找亚马逊简单排队服务作为队列的解决方案。

这两种解决方案都有优点和缺点,我想知道是否有人想到了其他可以帮助我们的解决方案。

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.

  1. 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.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬色的秋千 2024-11-23 10:47:50

当您需要扩展 cron 作业时,最好使用作业管理器,例如 Gearman

When you need to scale out cron jobs, you are better off using a job manager like Gearman

萌面超妹 2024-11-23 10:47:50

Beanstalkd 也可能是您的一个选择。

Beanstalkd could also be an option for you.

杀手六號 2024-11-23 10:47:50

我也有同样的问题。我所做的非常简单。

  1. 我在 AWS 上启动了最便宜的 EC2 实例。
  2. 我仅在此服务器上创建了 cronjob。
  3. cron 作业仅运行仅向我的端点/api(即 api.mydomain.com)发出简单请求的作业。
  4. 在我的 api 上,我只有一条路由来监视这些特殊请求,它将运行我想要的作业。所以基本上,我所做的不是使用 cronjob 运行任务,而是通过 http 请求运行任务。

我希望这是有道理的!现在,无论您拥有多少台服务器,它都可以扩展!另外,你的 cronjob 服务器的唯一功能就是运行简单的作业来发送请求,仅此而已。

I had the same problem. What I did was dead simple.

  1. I spun up the cheapest EC2 instance on AWS.
  2. I created the cronjob(s) only on this server.
  3. The cron job just run jobs that only makes a simple request to my endpoint / api (i.e. api.mydomain.com).
  4. On my api, i just have a route watching for these special request that will run the job I want. So basically, all I'm doing instead of running the task using a cronjob, im running the task via a http request.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文