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 {
}
common {
}
/etc/drbd.d/mysql.res :
resource mysql {
}
初始化资源:drbdadm create-md mysql
如果报错:Found ext3 filesystem which uses
则: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
keepalive 2
deadtime 30
warntime 10
initdead 30
ucast eth0 172.16.33.195 (SLAVE地址)
auto_failback off
node
node
ping 172.16.33.254 (PING网管)
respawn hacluster /usr/lib64/heartbeat/ipfail
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
主机名
将此脚本放在/etc/ha.d/resource.d 并且命名为:drbddisk
#!/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) |