Sun Cluster Geographic Edition 系统管理指南

第 9 章 自定义切换和接管操作

本章介绍了如何创建一个在保护组角色从辅助变为主时运行的脚本。本章包含以下各节:

创建角色更改操作脚本

您可以对 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

配置保护组在发生切换或接管时运行脚本

创建了脚本以后,您必须对保护组进行配置以在发生切换或接管时运行该脚本。一旦发生切换或接管,系统会在即将成为新主群集的群集上运行该脚本。

Procedure如何配置保护组在发生切换或接管时运行脚本

  1. 登录到一个群集节点。

    要完成此过程,必须为您指定 Geo Management RBAC 权限配置文件。有关 RBAC 的更多信息,请参见Sun Cluster Geographic Edition 软件和 RBAC

  2. 配置保护组的 RoleChange_ActionCmdRoleChange_ActionArgs 属性。


    # geopg set-prop -p RoleChange_ActionCmd=fullyqualifiedscript -p RoleChange_ActionArgs=scriptarguments
    
    -p propertysetting

    指定保护组的属性。

    使用 RoleChange_ActionCmd 属性指定命令的路径。该路径必须对可容纳保护组的所有伙伴群集上的所有节点均有效。

    使用 RoleChange_ActionArgs 属性运行操作命令时,定义希望附加至命令行的参数。

    有关可设置的属性的更多信息,请参见附录 A,标准 Sun Cluster Geographic Edition 属性

    protectiongroupname

    指定保护组的名称。


示例 9–2 配置保护组在发生群集切换或接管时运行一条命令

本示例将一个保护组配置为运行名为 newDNS 的自定义命令。


# geopg set-prop -p RoleChange_ActionCmd=/usr/bin/newDNS \
-p RoleChange_ActionArgs=domain=companyx.com,ip=1.2.3.4 avspg