使用两个Debian服务器,我需要为cron作业设置一个强大的故障转移环境,一次只能在一个服务器上调用该作业。
在/etc/cron.d中移动文件应该可以解决问题,但是是否有简单的HA解决方案来执行此类操作?如果可能的话,不要心跳;)
使用两个Debian服务器,我需要为cron作业设置一个强大的故障转移环境,一次只能在一个服务器上调用该作业。
在/etc/cron.d中移动文件应该可以解决问题,但是是否有简单的HA解决方案来执行此类操作?如果可能的话,不要心跳;)
Answers:
我认为心跳/起搏器将是最好的解决方案,因为它们可以为您照顾很多比赛条件,击剑等,以确保这项工作一次只能在一个主机上运行。可以自己设计一些东西,但可能无法解决这些软件包所做的所有情况,最终您将不得不替换大部分(如果不是全部)轮子。
如果您真的不太在意这些事情,并且想要一个简单的设置。我建议将服务器上的cron作业错开几分钟。然后,当作业在主服务器上启动时,它可能会以某种方式在作业所使用的任何共享资源上留下标记(您未指定此名称,所以我故意含糊)。如果是数据库,他们可以更新表中的字段,或者如果它位于共享文件系统上,则锁定文件。
当作业在第二台服务器上运行时,它可以检查标记的存在并中止标记的存在。
实际上,在这方面没有令人满意的解决方案。我们已经尝试了所有。脚本解决方案,具有心跳/起搏器的cron等。直到最近,唯一的解决方案是网格解决方案。自然,这不是我们想要看到的,因为网格解决方案对于该场景而言远不过是多余的。
这就是为什么我启动了CronBalancer项目的原因。除了分布式,负载平衡和HA(完成后)外,它的工作原理与普通cron服务器完全相同。目前,前2分已经完成(测试版),并且可以与标准crontab文件一起使用。
HA框架已经到位。剩下的就是确定故障转移和恢复操作所需的信号。
http://sourceforge.net/projects/cronbalancer/
卡盘
我一直在使用Nagios 事件处理程序作为简单的解决方案。
在NRPE服务器上:
command[check_crond]=/usr/lib64/nagios/plugins/check_procs -c 1: -C crond
command[autostart_crond]=sudo /etc/init.d/crond start
command[stop_crond]=sudo /etc/init.d/crond stop
不要忘记将nagios用户添加到sudoers组:
nagios  ALL=(ALL)   NOPASSWD:/usr/lib64/nagios/plugins/, /etc/init.d/crond
并禁用requiretty:
Defaults:nagios !requiretty
在Nagios服务器上:
services.cfg
define service{
    use                     generic-service
    host_name               cpc_3.145
    service_description     crond
    check_command           check_nrpe!check_crond
    event_handler           autostart_crond!cpc_2.93
    process_perf_data       0
    contact_groups          admin,admin-sms
}
命令
define command{
    command_name    autostart_crond
    command_line    $USER1$/eventhandlers/autostart_crond.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $ARG1$
}
autostart_crond.sh
#!/bin/bash
case "$1" in
    OK)
        /usr/local/nagios/libexec/check_nrpe -H $4 -c stop_crond
        ;;
    WARNING)
        ;;
    UNKNOWN)
        /usr/local/nagios/libexec/check_nrpe -H $4 -c autostart_crond
        ;;
    CRITICAL)
        /usr/local/nagios/libexec/check_nrpe -H $4 -c autostart_crond
        ;;
esac
exit 0
但是我改用Pacemaker和Corosync,因为它是确保资源一次仅在一个节点上运行的最佳解决方案。
这是我已完成的步骤:
验证crond 初始化脚本是否符合LSB。在我的CentOS上,我必须将退出状态从1更改为0(如果启动正在运行或停止已停止)以符合要求:
start() {
    echo -n $"Starting $prog: " 
    if [ -e /var/lock/subsys/crond ]; then
        if [ -e /var/run/crond.pid ] && [ -e /proc/`cat /var/run/crond.pid` ]; then
            echo -n $"cannot start crond: crond is already running.";
            failure $"cannot start crond: crond already running.";
            echo
            #return 1
            return 0
        fi
    fi
stop() {
    echo -n $"Stopping $prog: "
    if [ ! -e /var/lock/subsys/crond ]; then
        echo -n $"cannot stop crond: crond is not running."
        failure $"cannot stop crond: crond is not running."
        echo
        #return 1;
        return 0;
    fi然后可以使用以下命令将其添加到Pacemaker中:
# crm configure primitive Crond lsb:crond \
        op monitor interval="60s"
crm配置显示
node SVR022-293.localdomain
node SVR233NTC-3145.localdomain
primitive Crond lsb:crond \
        op monitor interval="60s"
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
crm状态
============
Last updated: Fri Jun  7 13:44:03 2013
Stack: openais
Current DC: SVR233NTC-3145.localdomain - partition with quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ SVR022-293.localdomain SVR233NTC-3145.localdomain ]
 Crond  (lsb:crond):    Started SVR233NTC-3145.localdomain
通过在3.145上停止Pacemaker和Corosync来测试故障转移:
[root@3145 corosync]# service pacemaker stop
Signaling Pacemaker Cluster Manager to terminate:          [  OK  ]
Waiting for cluster services to unload:......              [  OK  ]
[root@3145 corosync]# service corosync stop
Signaling Corosync Cluster Engine (corosync) to terminate: [  OK  ]
Waiting for corosync services to unload:.                  [  OK  ]
然后在2.93上检查群集状态:
============
Last updated: Fri Jun  7 13:47:31 2013
Stack: openais
Current DC: SVR022-293.localdomain - partition WITHOUT quorum
Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ SVR022-293.localdomain ]
OFFLINE: [ SVR233NTC-3145.localdomain ]
Crond   (lsb:crond):    Started SVR022-293.localdomain
对于这个特殊的问题,我更喜欢Rcron。您有一个状态文件,该文件仅显示“ active”或“ passive”,如果处于活动状态,则cron将在特定计算机上运行。如果状态文件设置为被动,则它将不会运行。就那么简单。
现在,您可以使用RedHat Cluster Suite或任何其他集群中间件来管理整个集群的状态文件,或者您可以手动在某个节点上将其设置为活动状态。