当前位置: > 数据库 > MySQL >

drbd+heartbeat+mysql

时间:2014-10-07 15:00来源:linux.it.net.cn 作者:it
yum -y install gcc make automake autoconf flex rpm-build kernel-devel
最好用独立的分区:sdb1 ,不要用sda.容易导致无法开机
 
安装DRBD:
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
DRBD版本:drbd-8.4.3.tar.gz
tar zxvf drbd-8.4.3.tar.gz
cd drbd-8.4.3
./configure
make-rpm
make km-rmp
cd ~/RPMS
rpm -ivh drbd-utils* drbd-km-2.6*
 
配置DRBD: /etc/drbd.d/global_common.conf 
global {
        usage-count yes;
        # minor-count dialog-refresh disable-ip-verification
}
 
common {
        handlers {
                # These are EXAMPLE handlers only.
                # They may have severe implications,
                # like hard resetting the node under certain circumstances.
                # Be careful when chosing your poison.
 
                 pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                 pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
                 local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
                # fence-peer "/usr/lib/drbd/crm-fence-peer.sh";
                # split-brain "/usr/lib/drbd/notify-split-brain.sh root";
                # out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";
                # before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";
                # after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;
        }
 
        startup {
                 wfc-timeout 30 ;
                 degr-wfc-timeout 30 ;
                 outdated-wfc-timeout 30 ;# wait-after-sb
        }
 
        options {
                # cpu-mask on-no-data-accessible
        }
 
        disk {
                # size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes
                on-io-error detach;
                fencing resource-and-stonith;
                resync-rate 15M;
                # disk-drain md-flushes resync-rate resync-after al-extents
                # c-plan-ahead c-delay-target c-fill-target c-max-rate
                # c-min-rate disk-timeout
        }
 
        net {
                # protocol timeout max-epoch-size max-buffers unplug-watermark
                # connect-int ping-int sndbuf-size rcvbuf-size ko-count
                # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
                # after-sb-1pri after-sb-2pri always-asbp rr-conflict
                # ping-timeout data-integrity-alg tcp-cork on-congestion
                # congestion-fill congestion-extents csums-alg verify-alg
                # use-rle
                protocol C;
                cram-hmac-alg sha1;
                shared-secret "mysql-ha" ;
        }
}
/etc/drbd.d/mysql.res :
resource mysql {
        on master {
                device  /dev/drbd0;
                disk    /dev/sdb1;
                address 172.16.33.225:8899;
                meta-disk       internal;
        }
        on slave {
                device  /dev/drbd0;
                disk    /dev/sda2;
                address 172.16.33.195:8899;
                meta-disk       internal;
        }
}
 
初始化资源:drbdadm create-md mysql
如果报错:Found ext3 filesystem which uses 
            Device size would be truncated, which
            would corrupt data and result in
            'access beyond end of device' errors.
            You need to either
           * use external meta data (recommended)
           * shrink that filesystem first
           * zero out the device (destroy the filesystem)
           Operation refused.
           Command 'drbdmeta
则:dd if=/dev/zero bs=1M count=1 of=/dev/sdb1; sync 
 
查看drbd状态:cat /proc/drbd 
service drbd start
将主机设置为primary:drbdadm primary mysql
将drbd0格式化为ext3:mkfs.ext3 /dev/drbd0
将/dev/drbd0挂载: mount /dev/drbd0 /opt
 
 
yum install heartbeat heartbeat-devel heartbeat-stonith heartbeat-pils
cp /usr/share/doc/heartbeat-3.0.4/ha.cf /etc/ha.d/ha.cf
cp /usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/haresources
cp /usr/share/doc/heartbeat-3.0.4/authkeys /etc/ha.d/authkeys
 
/etc/ha.d/ha.cf:
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 30
ucast eth0 172.16.33.195 (SLAVE地址)    slave上面的写MASTER的地址
auto_failback off
node    master
node    slave 
ping 172.16.33.254 (PING网管)
respawn hacluster /usr/lib64/heartbeat/ipfail  (路径是lib64 默认文件写的是lib)
respawn hacluster /usr/lib64/heartbeat/dopd
apiauth ipfail gid=haclient uid=hacluster
apiauth dopd gid=haclient uid=hacluster
 
/etc/ha.d/authkeys:
auth 1
1 sha1 Hi_leon
 
/etc/ha.d/haresources :
master drbddisk::mysql Filesystem::/dev/drbd0::/opt mysql IPaddr::172.16.33.199/24/eth1
主机名                 资源名                   挂载点                服务名                         VIP
 
将此脚本放在/etc/ha.d/resource.d 并且命名为:drbddisk      chmod 750
#!/bin/sh
DEFAULTFILE="/etc/default/drbd"
DRBDADM="/sbin/drbdadm"
 
if [ -f $DEFAULTFILE ]; then
. $DEFAULTFILE
fi
 
if [ "$#" -eq 2 ]; then
RES="$1"
CMD="$2"
else
RES="all"
CMD="$1"
fi
 
 
drbd_set_role_from_proc_drbd()
{
local out
if ! test -e /proc/drbd; then
ROLE="Unconfigured"
return
fi
 
dev=$( $DRBDADM sh-dev $RES )
minor=${dev#/dev/drbd}
if [[ $minor = *[!0-9]* ]] ; then
minor=$( $DRBDADM sh-minor $RES )
fi
if [[ -z $minor ]] || [[ $minor = *[!0-9]* ]] ; then
ROLE=Unknown
return
fi
 
if out=$(sed -ne "/^ *$minor: cs:/ { s/:/ /g; p; q; }" /proc/drbd); then
set -- $out
ROLE=${5%/**}
: ${ROLE:=Unconfigured} # if it does not show up
else
ROLE=Unknown
fi
}
 
case "$CMD" in
start)
try=6
while true; do
$DRBDADM primary $RES && break
let "--try" || exit 1 # LSB generic error
sleep 1
done
;;
stop)
try=3
while true; do
$DRBDADM secondary $RES && break
let --try || exit 1 # LSB generic error
sleep 1
done
;;
status)
if [ "$RES" = "all" ]; then
echo "A resource name is required for status inquiries."
exit 10
fi
ST=$( $DRBDADM role $RES )
ROLE=${ST%/**}
case $ROLE in
Primary|Secondary|Unconfigured)
;;
*)
drbd_set_role_from_proc_drbd
esac
case $ROLE in
Primary)
echo "running (Primary)"
exit 0 # LSB status "service is OK"
;;
Secondary|Unconfigured)
echo "stopped ($ROLE)"
exit 3 # LSB status "service is not running"
;;
*)
echo "cannot determine status, may be running ($ROLE)"
exit 4 # LSB status "service status is unknown"
;;
esac
;;
*)
echo "Usage: drbddisk [resource] {start|stop|status}"
exit 1
;;
esac
exit 0
 
 
将mysql数据文件放在/opt/mysqldata目录下(略)
用heartbeat 加载mysql启动: service heartbeat start

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容