我有一个配置了DRBD资源的高可用性集群。
有没有办法在资源出现故障时接收通知,例如发送电子邮件?
我正在使用Web (GUI)高可用性pacemaker界面,但我没有找到这样做的方法。
发布于 2017-05-04 23:18:49
有几种方法可以实现这一点。
最好的方法可能是在Pacemaker中配置通知。Pacemaker内置支持SNMP、SMTP和自定义通知代理。起搏器文档是一个很好的研究起点:http://clusterlabs.org/doc/en-US/Pacemaker/1.1-plugin/html/Pacemaker_Explained/ch07.html
但是,作为示例,如果您想要编写自己的通知代理,您可以在群集可以访问的地方创建一个脚本,如/usr/local/bin/notification-script-example.sh,如下所示:
#!/bin/bash
### list of variables passed from Pacemaker to all alert agents:
# CRM_notify_recipient the configure recipient
# CRM_notify_node name of affected node
# CRM_notify_desc details about event
# CRM_notify_task requested fencing/resource opertion (fencing and resource notify only)
# CRM_notify_rc return code from operation (fencing and resource notify only)
# CRM_notify_rsc name of the affected resource (resource notify only)
# CRM_notify_target_rc expected return code of an operation (resource notify only)
# CRM_notify_status numerical code used by Pacemaker to represent operation result (resource notify only)
### some variables won't get values; set NA if not populated:
CRM_notify_recipient="${CRM_notify_recipient:-NA}"
CRM_notify_node="${CRM_notify_node:-NA}"
CRM_notify_desc="${CRM_notify_desc:-NA}"
CRM_notify_task="${CRM_notify_task:-NA}"
CRM_notify_rc="${CRM_notify_rc:-NA}"
CRM_notify_rsc="${CRM_notify_rsc:-NA}"
CRM_notify_target_rc="${CRM_notify_target_rc:-NA}"
CRM_notify_status="${CRM_notify_status:-NA}"
### do something with these values
logger "PCMK-NOTIFY: recipient: $CRM_notify_recipient"
logger "PCMK-NOTIFY: affected node: $CRM_notify_node"
logger "PCMK-NOTIFY: event details: $CRM_notify_desc"
logger "PCMK-NOTIFY: requested op: $CRM_notify_task"
logger "PCMK-NOTIFY: op ret code: $CRM_notify_rc"
logger "PCMK-NOTIFY: affected res: $CRM_notify_rsc"
logger "PCMK-NOTIFY: expected rc: $CRM_notify_target_rc"
logger "PCMK-NOTIFY: pcmk result: $CRM_notify_status"
### exit
exit 0然后,使用ClusterMon资源代理将pacemaker中的通知代理配置为原语,然后克隆它,以便它在所有节点上运行(在crmsh语法中):
primitive cluster-notifications ocf:pacemaker:ClusterMon \
params user=root update=30 extra_options="--watch-fencing \
-E /usr/local/bin/notification-agent-example.sh"
clone cl-cluster-notifications cluster-notifications对于您的脚本,听起来像是要发送一封电子邮件,因此您只需要更改脚本的### do something with these values部分,以通过电子邮件发送所有内容,而不是简单地记录日志。
在Pacemaker中获取事件通知的另一种方法是使用ocf:heartbeat:MailTo资源代理在集群中创建MailTo原语。它将在群集中的任何时候启动或停止时发送一封电子邮件,因此您通常会希望命令它在群集中的所有其他内容之前启动;这将确保它在发生迁移/故障切换时最后启动并首先停止。
如果您只对DRBD通知感兴趣,您可以通过在/etc/drbd.d/global_common.conf的handler{}部分中启用DRBD附带的一些处理程序脚本来使用它们,或者您可以将以下内容添加到您关心的资源配置中:
handlers {
split-brain "/usr/lib/drbd/notify-split-brain.sh admin@acme.com";
out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh admin@acme.com";
}显然,有许多方法可以给众所周知的猫剥皮,但我希望这些信息能有所帮助!
https://stackoverflow.com/questions/43752572
复制相似问题