Sun Cluster Geographic Edition 系统管理指南

创建角色更改操作脚本

您可以对 Sun Cluster Geographic Edition 软件加以配置,使其在保护组中某个群集的角色从 secondary 变为 primary 时运行一条命令。这种角色更改可能是切换或接管操作的结果。

当新主群集启动保护组后,系统会在该群集发生切换或接管操作期间运行该操作命令。当数据复制角色从辅助变为主,且应用程序资源组尚未联机,系统会在新主群集上调用该脚本。如果数据复制角色更改失败,则不会调用该脚本。

该脚本的路径必须对可容纳保护组的所有伙伴群集上的所有节点均有效。

以下命令行即运行该脚本:


# custom-action-command-path -o primary -c clustername \
-s partnershipname protectiongroupname userarguments
customactioncommandpath

指定您已创建的操作命令的路径。

-o primary

指定群集担当的角色为 primary

-c clustername

指定新担当主群集角色的辅助群集的名称。

-s partnershipname

指定容纳保护组的伙伴关系的名称。

protectiongroupname

指定正在经历角色更改的保护组的名称。

userarguments

指定在 Sun Cluster Geographic Edition 提供的所有选项后传递的静态参数。

这种格式自由的字符串可根据需要由脚本进行解析。例如,您可以指定一列 key=value 对,如 name=sun.com,ip=10.1.2.3。您还可以指定选项序列,如 -n sun.com -a 10.1.2.3.4。上述参数的格式不受 Sun Cluster Geographic Edition 软件的限制。

角色更改操作脚本的退出状态是作为 geopg switchovergeopg takeover 命令结果的一部分加以报告的。如果成功启动该操作脚本,退出状态为零。非零的退出状态表明出现了错误或故障。退出状态的值不会影响角色更改操作的其他方面。无论操作脚本的退出状态如何,切换或接管操作均会继续使保护组中的应用程序资源组进入联机状态。

Sun Cluster Geographic Edition 软件会等待脚本返回,然后再处理诸如使应用程序资源组联机这样的操作。因此,在创建操作脚本时您必须预先知道运行脚本所需的时间,以便相应地设置保护组的超时时限。设置的超时时限应包含足够的时间来完成脚本,从而避免因切换或接管超时而导致应用程序资源组在新的主群集上脱机。


示例 9–1 用于更新 DNS 的切换操作脚本

本示例脚本使用 nsupdate 命令来重新配置主机名,以指向新的群集。有关 nsupdate 命令的更多信息,请参阅 nsupdate(1M) 手册页。

名称服务使尝试连接 companyX.com 的客户机指向保护组主群集 cluster-paris 的地址。当主群集未能响应时,管理员将执行使保护组切换到备用群集 cluster-newyork 的操作。


#!/bin/ksh
# sample script to update dns
# Assumes each cluster has an entry with name "lh-paris-1" in /etc/hosts
# but different value for the IP in each cluster
# for forward DNS (A) entry: will delete old entry for "lh-paris-1"
# and add one that is correct for "this cluster"
#
# For reverse (PTR) DNS entry, will just add one for this cluster. 
# Will NOT delete PTR record left over from old cluster. So
# eventually you will just have reverse lookup for the IP for both clusters
# doing reverse resolution to the same name (lh-paris-1.odyssey.com)
# This should be fine, as long as the forward resolution stays "correct"
#
# The blank line of input at the end of nsupdate is REQUIRED
#
# A short TTL is put on the new records (600 = 10 minutes)
# but you can't really control what kind of caching goes on on
# the client side


# get IP corresponding to name "lh-paris-1" on THIS Cluster
NEWIP=$(getent hosts lh-paris-1|cut -f1)

# this bit splits out the octets in order to add the reverse PTR entry
IFS=.
set $NEWIP
unset IFS

/usr/sbin/nsupdate <<ENDNSUPDATE
update delete ora-lh.odyssey.com A
update add ora-lh.odyssey.com 600 A $NEWIP
update add $4.$3.$2.$1.in-addr.arpa 600 PTR ora-lh.odyssey.com.

ENDNSUPDATE