Heartbeat+drbd+mysql的高可用部署
Heartbeat+drbd+mysql的高可用
1.规划
VIP:192.168.1.30
myhost1:
内网IP:192.168.1.11
heartbeat心跳IP:192.168.74.11
drbd传输IP:192.168.223.11
myhost2:
内网IP:192.168.1.12
heartbeat心跳IP:192.168.74.12
drbd传输IP:192.168.223.12
2.安装heartbeat
yum install heartbeat -y
如果rpm包安装需要安装如下包:
libnet-1.1.6-7.el5.x86_64.rpm
libtool-ltdl
openhpi-libs
heartbeat-stonith
heartbeat-pils
3.在/etc/ha.d目录下的配置文件:
cp /usr/share/doc/heartbeat-2.1.4/ha.cf ./
cp /usr/share/doc/heartbeat-2.1.4/authkeys ./
cp /usr/share/doc/heartbeat-2.1.4/haresources ./
chmod 600 /etc/ha.d/authkeys
配置ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
ucast eth2 192.168.74.12
auto_failback on
node myhost1
node myhost2
crm no
authkey
auth 1
1 sha1 63d40e84c4748d6a7b8ec3581a374a3c
haresource
myhost1 IPaddr::192.168.1.30/24/eth0 drbddisk::mdata Filesystem::/dev/drbd0::/dbdata::ext3 rsdata
#每段的具体执行命令说明:
#/etc/ha.d/resource.d/IPaddr 192.168.1.30/24/eth0 stop/start
#/etc/ha.d/resource.d/drbddisk mdata stop/start
#/etc/ha.d/resource.d/Filesystem /dev/drbd0 /dbdata ext3 stop/start
#/etc/init.d/rsdata stop/start
4.禁用开机自启动:
chkconfig heartbeat off
5.安装drbd(redhat 5.8环境)
wget wget http://oss.linbit.com/drbd/8.4/drbd-8.4.6.tar.gz
tar -zxvf drbd-8.4.6.tar.gz
cd drbd-8.4.6
make
make install
wget http://oss.linbit.com/drbd/drbd-utils-8.9.2.tar.gz
tar -zxvf drbd-utils-8.9.2
cd drbd-utils-8.9.2
./configure --prefix=/usr/local/drbd-utils-8.9.2 --sysconfdir=/etc --with-xen
make && make install
如果是centos 6版本的系统,可以执行如下命令:
yum install drbd83 kmod-drbd83 -y
6.格式化分区:
mkfs.ext3 /dev/sdb1
tune2fs -c -1 /dev/sdb1
meta分区不能格式化,生产环境中一般分配1G-2G空间;
7.配置drbd
modprobe drbd
lsmod |grep drbd
mknod /dev/drbd0 b 147 0
#配置开机加载:
echo "modprobe drbd >/dev/null 2>&1" >>/etc/sysconfig/modules/drbd.modules
chmod 755 /etc/sysconfig/modules/drbd.modules
mkdir -p /usr/local/drbd-utils-8.9.2/var/run/drbd
#调整配置文件
[root@myhost1 ~]# cat /etc/drbd.conf
global {
# minor-count 64;
# dialog-refresh 5; # 5 seconds
# disable-ip-verification;
usage-count no;
}
common {
protocol C;
disk {
on-io-error detach;
no-disk-flushes;
no-md-flushes;
}
net {
sndbuf-size 512k;
# timeout 60; # 6 seconds (unit = 0.1 seconds)
# connect-int 10; # 10 seconds (unit = 1 second)
# ping-int 10; # 10 seconds (unit = 1 second)
# ping-timeout 5; # 500 ms (unit = 0.1 seconds)
max-buffers 8000;
unplug-watermark 1024;
max-epoch-size 8000;
# ko-count 4;
# allow-two-primaries;
cram-hmac-alg "sha1";
shared-secret "hdhwXes23sYEhart8t";
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
# data-integrity-alg "md5";
# no-tcp-cork;
}
syncer {
rate 630M;
al-extents 517;
}
}
resource mdata {
on myhost1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.223.11:7788;
meta-disk /dev/sdb2 [0];
}
on myhost2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.223.12:7788;
meta-disk /dev/sdb2 [0];
}
}
#两个节点同时执行
drbdadm create-md mdata
#两个节点执行
drbdadm up all
#仅主节点执行
drbdadm -- --overwrite-data-of-peer primary mdata
#仅主节点执行
drbdadm primary all
ps aux|grep drbd
mount /dev/drbd0 /dbdata
cat /proc/drbd
8.heartbeat启动顺序:
1.启动VIP
/etc/ha.d/resource.d/IPaddr 192.168.1.30/24/eth0 start
2.配置drbd资源
/etc/ha.d/resource.d/drbddisk mdata start
3.挂载drbd分区
/etc/ha.d/resource/drbddisk /dev/drbd0 /dbdata ext3 start
4.启动mysql:
/etc/ha.d/resource/rsdata start
5.查看drbd的信息:
cat /proc/drbd
6.验证是否正常的检查点:
VIP,角色,分区挂载
9.主备切换
/usr/lib64/heartbeat/hb_standby
/usr/lib64/heartbeat/hb_takeover
本文出自 “webseven” 博客,请务必保留此出处http://webseven.blog.51cto.com/4388012/1651795
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。