db1:192.168.44.151
db2:192.168.44.152
创建一个新的sdb
pvcreate /dev/sdb1
vgcreate vgdb /dev/sdb1
lvcreate -L +1000M -n /dev/vgdb/lvdb
lvcreate -L +256M -n /dev/vgdb/lvmeta
lvdisplay | more
yum -y install drbd82 kmod-drbd82
vim /etc/drbd.conf
global {
usage-count yes;
}
common {
syncer { rate 10M; }
}
resource r0 {
protocol C;
handlers {
pri-on-incon-degr "echo 0 > /proc/sysrq-trigger ; halt -f";
pri-lost-after-sb "echo 0 > /proc/sysrq-trigger ; halt -f";
local-io-error "echo 0 > /proc/sysrq-trigger ; halt -f";
outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater -t 5";
}
startup{
}
disk {
on-io-error detach;
}
net {
after-sb-Opri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect
}
syncer {
rate 10M;
al-extents 257;
}
on db1.hbn.local {
device /dev/drbd0;
disk /dev/vgdb/lvdb;
address 192.168.44.151:7788; #本机ip地址
meta-disk /dev/vgdb/lvmeta[1];
}
on db2.hbn.local {
device /dev/drbd0;
disk /dev/vgdb/lvdb;
address 192.168.44.152:7788; #另外一台机器的ip地址
meta-disk /dev/vgdb/lvmeta[1];
}
}
scp /etc/drbd.conf root@192.168.44.152:/etc/
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_ignore = 2
net.ipv4.conf.eth0.arp_announce = 2
sysctl -p
scp /etc/sysctl.conf root@192.168.44.152:/etc/
@db1,db2
modprobe drbd
echo "modprobe drbd" >> /etc/rc.local
drbdadm create-md r0
groupadd haclient
chgrp haclient /sbin/drbdsetup
chmod o-x /sbin/drbdsetup
chmod u+x /sbin/drbdsetup
chgrp haclient /sbin/drbdmeta
chmod o-x /sbin/drbdmeta
chmod u+x /sbin/drbdmeta
drbdadm attach r0
drbdadm syncer r0
drbdadm connect r0
drbdadm -- --overwrite-data-of-peer primary r0 #on db1
drbdadm up all
drbdadm -- primary all #on db1
watch cat /proc/drbd
mkfs.ext3 /dev/drbd0
mkdir /data
mount /dev/drbd0 /data
yum -y install mysql-server
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
[mysql]
socket=/data/mysql/mysql.sock
[client]
socket=/data/msyql/mysql.sock
cd /data
mkdir mysql
chown mysql:mysql mysql/
yum -y install heartbeat heartbeat-pils heartbeat-stonith heartbeat-devel #安装epel源
vim /etc/ha.d/ha.cf
logfacility local0
keepalive 2
#deadtime 30 # USE THIS!!
deadtime 10
#we use two heartbeat links,eth2 and serial 0
bcast eth0
#serial /dev/ttyS0
baud 19200
auto_failback off
node db1.hbn.local
node db2.hbn.local
scp /etc/ha.d/ha.cf root@db2:/etc/
@192.168.44.151
vim /etc/ha.d/haresources
db1.hbn.local IPaddr::192.168.44.150/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext3 mysqld
@192.168.44.152
vim /etc/ha.d/haresources
db1.hbn.local IPaddr::192.168.44.150/24/eth0 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext3 mysqld
vim /etc/ha.d/authkeys
auth 3
3 md5 hbn
scp /etc/ha.d/authkeys db2:/etc/ha.d
chmod 600 /etc/ha.d/authkeys
chkconfig --level 235 heartbeat on
chkconfig --level 35 mysqld off
/etc/init.d/heartbeat start
/etc/init.d/drbd status