heartbeat+DRBD+mysql+haproxy
heartbeat+DRBD+mysql主要实现mysql主的单点故障
haproxy实现mysql从的负载均衡
具体的架构图
Mysql集群主机的IP地址信息和用途
主机名 |
IP |
用途 |
dbm3 |
192.168.3.3 |
heartbeat+DRBD+Mysql主 |
dbm4 |
192.168.3.4 | heartbeat+DRBD+Mysql主备 |
dbs6 |
192.168.3.6 | slave(master_host=192.168.3.2) |
dbs7 |
192.168.3.7 | slave(master_host=192.168.3.2) |
dbs8 |
192.168.3.8 | slave(master_host=192.168.3.2) |
haproxy |
192.168.3.5 |
slave读IP |
1,设置hostname及解析
编辑/etc/hosts文件,添加如下内容
192.168.3.3 dbm3
192.168.3.4 dbm4
192.168.3.5 haproxy
192.168.3.6 dbs6
192.168.3.7 dbs7
192.168.3.8 dbs8
2,磁盘分区规划
根据具体需求规划空间大小
3,DRBD的部署
导入源:rpm -Uvh elrepo-release-6-6.el6.elrepo.noarch.rpm
通过yum安装DRBD
yum install drbd83-utils kmod-drbd83
4,检查DRBD是否安装成功:
modprobe -l | grep -i drbd
lsmod | grep -i drbd
安装成功之后,在/sbin目录下面有drbdadm,drbdmeta,drbdsetuo命令,以及/etc/init.d/drbd启动脚本
5,DRBD的配置
1.DRBD硬盘分区
2台服务器用做DRBD分区的硬盘空间的大小最好相同,使用fdisk 创建2个分区,例如sdb1和 sdb2.
2.drbd.conf配置文件
节点角色 |
主机名 |
IP地址 |
DRBD分区 |
primary节点 |
dbm3 |
192.168.3.3 |
/dev/sdb1 |
secondary节点 |
dbm4 |
192.168.3.4 | /dev/sdb1 |
下面是drbd.conf的配置:
global {
usage-count no;
#是否参加DRBD使用者统计,默认为yes
}
common {
protocol C;
#使用DRBD的第三种协议,表示收到远程主机的写入确认后认为写入完成
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 "pRrcAwF5Rtltz29Ml1";
after-sb-0pri disconnect;
after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;
# data-integrity-alg "md5";
# no-tcp-cork;
}
syncer {
rate 200M;
al-extents 517;
}
}
resource appdata {
on dbm3 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.3.3:7788;
meta-disk /dev/sdb2 [0];
}
on dbm4 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.3.4:7788;
meta-disk /dev/sdb2 [0];
}
}