#!/bin/bash
#FileName: DRBD-Heartbeat.sh


DRBD_PKG="wget http://down.vqiu.cn/package/tarball/drbd/drbd-8.4.3.tar.gz"
PREFIX="/usr/local/drbd"
DRBD_DIR="drbd-8.4.3"

export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/loca/bin:/usr/local/sbin"

yum -y install gcc kernel-devel kernel-headers flex wget
cd /usr/local/src
wget -c ${DRBD_PKG};tar zxvf ${DRBD_PKG##*/};cd ${DRBD_DIR}
./configure --prefix=${PREFIX} --with-km
make KDIR= /usr/src/kernels/$(uname -r)
make install
mkdir -p /usr/local/drbd/var/run/drbd
cp ${PREFIX}/etc/rc.d/init.d/drbd /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/
chkconfig --add drbd;chkconfig drbd on

cd ${PREFIX}/etc;mkdir backup;mv drbd.conf

cat > drbd.conf<<EOF
global { usage-count no; }
    common { syncer { rate 33M; } }
    resource r0 {
    protocol C; 
    net {
        cram-hmac-alg sha1;
        shared-secret "MySQL_HA";
        }

    on mysql-m1 {
        device    /dev/drbd0;
        disk      /dev/sdb1;
        address   10.0.17.150:7898;
        meta-disk  internal;
                }
    on mysql-m2 {
        device    /dev/drbd0;
        disk      /dev/sdb1;
        address   10.0.17.151:7898;
        meta-disk  internal;
                }
                }
EOF
mknod /dev/drbd0 b 147 0
drbdadm create-md r0
drbdadm create-md all
drbdadm -- --overwrite-data-of-peer primary all

