Sun Cluster Geographic Edition 系统管理指南

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

本章介绍如何创建当保护组角色由辅助变为主要时系统将会执行的脚本。本章包含以下主题:

创建角色更改操作脚本

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

该操作命令在角色发生变化(即从辅助变为主要)的群集上执行。命令参数提供了事件信息。该脚本在 Sun Cluster Geographic Edition 软件使资源组进入联机状态前执行。以下命令行即运行该脚本:


# custom-action-command-path -o primary -c cluster-name \ 
 -s partnership-name protection-group-name user-arguments
custom-action-command-path

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

-o primary

指定群集担当的角色为 primary

-c cluster-name

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

-s partnership-name

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

protection-group-name

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

user-arguments

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

在继续执行其他操作之前,您应该等待脚本返回结果。创建操作脚本时,请考虑运行脚本所需的时间。


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

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

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


#!/bin/ksh
# 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=fully-qualified-script -p RoleChange_ActionArgs=script-arguments
    
    -p property-setting

    设置该保护组的属性

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

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

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

    protection-group-name

    指定保护组的名称


示例 14–2 将保护组配置为在执行群集的切换或接管操作时执行命令

以下命令对保护组进行配置以执行名为 newDNS 的自定义命令:


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