Cron作业群集环境 [英] Cron Job Cluster environment

查看:159
本文介绍了Cron作业群集环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在集群环境中设置cron作业。
我有4 + 1集群环境,第一个服务器运行crontab脚本,如果它下来cron应该移动到另一个。

I need to know how we can setup cron jobs in cluster environment. I have 4+1 cluster environment , first server is running crontab scripts and in case it gets down cron should be shifted to another. How is it possible?

推荐答案

一个常见的资源是 rcron 。这个项目有一段时间没有更新,但仍然编译良好。它通过使用状态文件来确定它是否是活动服务器。然而,Rcron不更新状态文件本身;它依赖于像 Heartbeat 这样的服务来为您更新状态文件。它的工作原理是你在你的常规cron中用rcron预处理每个cron命令,即:

One common resource is rcron. This project hasn't been updated in a while, but still compiles fine. It works by using a state file to determine if it is the active server. Rcron doesn't update the state file itself, however; it relies on a service like Heartbeat to update the state file for you. It works by having you prepend each cron command in your regular cron with rcron, i.e.:

0 * * * * /bin/bash /usr/local/scripts/myscript.sh 2>/dev/null

p>

Would become

0 * * * * /usr/local/rcron /bin/bash /usr/local/scripts/myscript.sh 2>/dev/null

如您所见,您也可以自己的脚本执行这种功能:

As you can see, you could also just implement your own script that performs this kind of function:

0 * * * * /usr/local/scripts/active_or_not.sh && /bin/bash /usr/local/scripts/myscript.sh 2>/dev/null

脚本的内容如下:

#! /bin/bash
shouldIBeActive() {
    # See if this server is able to run all the crons correctly
    canRun || return 1
    # See if there is already another server set to active
    shouldRun || return 1 # Maybe even still using Hearbeat for a state file
}

if [ shouldIBeActive ]; then
    logger "Set to active server"
    exit 0
else
    logger "Not set to be active."
    exit 1
fi

如果您想避免更新此cron在多个服务器上,您可以使用NFS或DRBD或某物具有共享crontab,但其可靠性将突然变得依赖于此。

If you want to avoid having to updated this cron on multiple servers, you could use NFS or DRBD or something to have a shared crontab, although its reliability will suddenly become dependent on that.

这篇关于Cron作业群集环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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