テストしてて思ったけどistgtのNodeBaseは変えておかないと分からなくなるw。それっぽく変更
[Global] Comment "Global section" # node name (not include optional part) NodeBase "iqn.2010-10.200.68.168.192.istgt"
ucarp設定。hast-a側 bは省略
ucarp_enable="YES" ucarp_if="em0" ucarp_src="192.168.68.198" ucarp_addr="192.168.68.200" ucarp_upscript="/usr/local/bin/vip-up.sh" ucarp_downscript="/usr/local/bin/vip-down.sh"
/usr/local/bin/vip-up.sh
サンプルを元に。引数を追加した。
#!/bin/sh # $FreeBSD: src/share/examples/hast/vip-up.sh,v 1.1.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ set -m /usr/local/bin/ucarp_up.sh "$@" & set +m
/usr/local/bin/ucarp_up.sh
#!/bin/sh # # Copyright (c) 2010 The FreeBSD Foundation # All rights reserved. # # This software was developed by Pawel Jakub Dawidek under sponsorship from # the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: src/share/examples/hast/ucarp_up.sh,v 1.1.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ # Resource name as defined in /etc/hast.conf. resource="hasthd1" # Name of HAST provider as defined in /etc/hast.conf. device="/dev/hast/${resource}" export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # Change role to primary for our resource. out=`hastctl role primary "${resource}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to change to role to primary for resource ${resource}: ${out}." exit 1 fi # Wait few seconds for provider to appear. for i in `jot 50`; do [ -c "${device}" ] && break sleep 0.1 done if [ ! -c "${device}" ]; then logger -p local0.error -t hast "Device ${device} didn't appear." exit 1 fi logger -p local0.debug -t hast "Role for resource ${resource} changed to primary." ifconfig $1 $2 netmask 255.255.255.255 alias /usr/local/etc/rc.d/istgt onestart logger -p local0.info -t hast "Successfully switched to primary for resource ${resource}." exit 0
最初サンプルをそのままコピーしてやってたけどノードが切り替わるときに
Secondary process for resource hasthd1 is still running after 30 seconds.
と言われてしまってshellが死ぬのでうまく切り替わらない。
hastdがセカンダリで起動していると中断するような仕組みみたいなんだが、UPするときは(切り替わる)セカンダリ状態じゃないのかな??謎。
あと変更点は、ifconfigのaliasとistgtの起動部分。関係ないファイルシステムの処理とかは削った。
/usr/local/bin/ucarp_down.sh
#!/bin/sh # # Copyright (c) 2010 The FreeBSD Foundation # All rights reserved. # # This software was developed by Pawel Jakub Dawidek under sponsorship from # the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: src/share/examples/hast/ucarp_down.sh,v 1.1.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ # Resource name as defined in /etc/hast.conf. resource="hasthd1" export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # KIll UP script if it still runs in the background. sig="TERM" for i in `jot 30`; do pgid=`pgrep -f ucarp_up.sh | head -1` [ -n "${pgid}" ] || break kill -${sig} -- -${pgid} sig="KILL" sleep 1 done if [ -n "${pgid}" ]; then logger -p local0.error -t hast "UCARP UP process for resource ${resource} is still running after 30 seconds." exit 1 fi logger -p local0.debug -t hast "UCARP UP is not running." /usr/local/etc/rc.d/istgt stop ifconfig $1 $2 delete # Change role to secondary for our resource. out=`hastctl role secondary "${resource}" 2>&1` if [ $? -ne 0 ]; then logger -p local0.error -t hast "Unable to change to role to secondary for resource ${resource}: ${out}." exit 1 fi logger -p local0.debug -t hast "Role for resource ${resource} changed to secondary." logger -p local0.info -t hast "Successfully switched to secondary for resource ${resource}." exit 0
/usr/local/bin/vip-down.sh
#!/bin/sh # $FreeBSD: src/share/examples/hast/vip-down.sh,v 1.1.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $ /usr/local/bin/ucarp_down.sh "$@" exit 0
一応この状態で仮想IP(192.168.68.200)のistgtに接続して、hast-aを落としてみたり、切り替えたりして問題なさげな感じなのを確認。
あと、HDD壊れた時どうなんだろう?。切り替えはucarpがやってる(ホストが落ちたとき)のでなんかしないとだめなのかなぁ。