Table of Contents

HEARTBEAT plus GMIRROR GGATE

Запуск и автозапуск ggated

[gateN:~] # ggated 

[gateN:~] # cat /etc/rc.local
ggated

Настройка heartbeat

[gateN:~] # cat /usr/local/etc/ha.d/haresources
gate2.corpX.un gmirror
[gateN:~] # cat /usr/local/etc/ha.d/resource.d/gmirror
#!/bin/sh

case $1 in
status)
	# status is not defined, let it be backup
        ps ax | grep -v grep | grep -q gated || ggated
        ;;
start)
	# stop backup service
	ps ax | grep -v grep | grep -q gated && killall -9 ggated
	# in some case start run twise
	kldstat | grep -q geom_mirror || (
		gmirror load
		sleep 5
		gmirror status | grep -q DEGRADED && \
			gmirror forget gm0 || \
			gmirror label -v gm0 /dev/ad1s1e
	        fsck -y -t ufs /dev/mirror/gm0
	        mount /dev/mirror/gm0 /opt
	)
        ;;
stop)
        kldstat | grep -q geom_mirror && (
		# this is master
		umount /opt
		gmirror status | grep -q ggate0 && gmirror deactivate gm0 ggate0
		gmirror deactivate gm0 ad1s1e
		gmirror unload
		ggatec list | grep -q ggate0 && ggatec destroy -u 0
		ps ax | grep -v grep | grep -q ggatec && killall -9 ggatec
	)
        ps ax | grep -v grep | grep -q gated || ggated
        ;;
esac

exit 0
[gateN:~] # chmod +x /usr/local/etc/ha.d/resource.d/gmirror
[gateN:~] # /usr/local/etc/rc.d/heartbeat start

Автоматизация подключения диска backup

[gateN:~] # mkdir /usr/local/etc/scripts/

[gateN:~] # cat /usr/local/etc/scripts/gmirror
#!/bin/sh

# check if node is master
/sbin/kldstat | grep -q geom_mirror || exit 0 

# chech if mirror is complete
/sbin/gmirror status | grep -q ggate0 && \
	/sbin/gmirror status | grep -q 'COMPLETE' && \
	exit 0

# check if backup node is not dead
/usr/local/bin/cl_status nodestatus gate1.corpX.un 2>/dev/null | grep -q dead && exit 0
/usr/local/bin/cl_status nodestatus gate2.corpX.un 2>/dev/null | grep -q dead && exit 0

# create ggate connect to slave node hdd
/sbin/ggatec list | grep -q ggate0 || (
	/sbin/ggatec create -t 10 -u 0 slave /dev/ad1s1e || exit 0
)

# connect slave hdd to mirror
/sbin/gmirror status | grep -vq ggate0 && /sbin/gmirror insert gm0 ggate0

# check is sync nodes in progress
/sbin/gmirror status | grep -q '%' && exit 0

# reconnect slave hdd to mirror
/sbin/gmirror status | grep -q 'DEGRADED' && (
        /sbin/gmirror forget gm0
        /sbin/gmirror insert gm0 ggate0
)
[gateN:~] # chmod +x /usr/local/etc/scripts/gmirror
[gateN:~] # crontab -l
* * * * * /usr/local/etc/scripts/gmirror

Восстановление backup сервера

  1. Подключаем новый hdd
  2. Загружаем однопользователский режим
  3. Создаем на диске раздел s1e
  4. Продолжаем загрузку