-
在企业应用中,mysql+heartbeat+DRBD+LVS是一套成熟的集群解决方案,通过heart+DRBD实现mysql的主 节点写操作的高可用性,而通过mysql+LVS实现数据库的主从复制和mysql的读操作的负载均衡。整个方案在读写方面进行了分离,融合了写操作的高 可用和读操作的负载均衡,是一个完美又廉价的企业应用解决方案
目前流行的高可用解决方案:
mysql的复制功能是通过建立复制关系和两台和多台机器环境中,一台机器出现故障切换到另一台机器上保证一定程度的可用性
mysql的复制功能加一些集群软件
mysql+heartbeat+DRBD的复制功能
共享存储+mysql的复制功能
DRBD:(分布式块设备复制)是linux内核的存储层中的一个分布式存储系统,可利用DRBD在两台linux服务器之间共享块设备、文件系统 和数据。当地数据写入本地主节点的文件系统时,这些数据会通过网络发送到另一台主节点上,本地主节点和远程主节点数据通过TCP/IP协议保持同步,主节 点故障时,远程节点保存着相同的数据,可以接替主节点继续提供数据。两个节点之间使用heartbeat来检测对方是否存活
同步过程
1:在node1上写操作被提交,通过内核传给DRBD模块
2:DRBD发送写操作到node2
3:在node2上的DRBD发送写操作给本地磁盘
4:在node2上的DRBD向node1发确认信息,确认接收到写操作并发送给本地次哦按
5:在node1上的DRBD发送写操作给本地磁盘
6:node1内核回应写操作完成
配置之前的准备
1.设置hostname及解析
1.[root@drbd1 ~]# vim /etc/hosts2.192.168.253.129drbd13.192.168.253.140drbd2部署mysql的高可用高扩展集群
1.[root@drbd1 ~]# mke2fs -j /dev/sda2.[root@drbd1 ~]# mkdir /database3.[root@drbd1 ~]# mount /dev/sda /database/4.[root@drbd1 ~]# mount -a5.[root@drbd1 ~]# mount6.[root@drbd1 ~]# df -h | grep /database7./dev/sda20G173M19G1%/databaseDRBD的部署
1.[root@drbd1 ~]# uname -a2.<a href="http://www.it165.net/os/oslin/"target="_blank"class="keylink">Linux</a> drbd12.6.32-220.el6.x86_64#1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/<a href="http://www.it165.net/os/oslin/" target="_blank" class="keylink">Linux</a>通过yum安装drbd服务
默认centos6.x中并没有提供DRBD的源,这时要么采用源码编译方法,要么使用第三方的YUM源。这里使用了http://elrepo.org/tiki/tiki-index.php提供的源
1.rpm-Uvh http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm2.[root@drbd1 yum.repos.d]# rpm -qa | grep elrepo-release3.elrepo-release-6-5.el6.elrepo.noarch实际上就是往yum.repos.d里面添加一个源配置elrepo.repo
使用yum list查看,进行安装
1.[root@drbd1 yum.repos.d]# yum list all | grep drbd2.drbd83-utils.x86_648.3.16-1.el6.elrepo elrepo3.drbd84-utils.x86_648.4.4-2.el6.elrepo elrepo4.kmod-drbd83.x86_648.3.16-1.el6.elrepo elrepo5.kmod-drbd84.x86_648.4.4-1.el6.elrepo elrepo6.[root@drbd1 ]# yum --enablerepo=elrepo install drbd83-utils kmod-drbd83检查DRBD是都安装成功,若安装完成,让内核加载DRBD模块
复制样例配置文件为即将使用的配置文件
1.vim/usr/share/doc/drbd83-utils-8.3.16/drbd.conf.example配置DRBD
1.[root@drbd1 etc]# vim /etc/drbd.conf2.# You can find an example in /usr/share/doc/drbd.../drbd.conf.example3.include"drbd.d/global_common.conf";4.include"drbd.d/*.res";配置 vim /etc/drbd.d/global_common.conf
01.vim/etc/drbd.d/global_common.conf02.global{03.usage-count no;04.# minor-count dialog-refresh disable-ip-verification05.}06.common {07.protocol C;08.handlers {09.pri-on-incon-degr"/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";10.pri-lost-after-sb"/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";11.local-io-error"/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";12.# fence-peer "/usr/lib/drbd/crm-fence-peer.sh";13.# split-brain "/usr/lib/drbd/notify-split-brain.sh root";14.# out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root";15.# before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh -p 15 -- -c 16k";16.# after-resync-target /usr/lib/drbd/unsnapshot-resync-target-lvm.sh;17.}18.startup {19.#wfc-timeout 120;20.#degr-wfc-timeout 120;21.}22.disk {23.on-io-error detach;24.#fencing resource-only;25.}26.net {27.cram-hmac-alg"sha1";28.shared-secret"mydrbdlab";29.}30.syncer {31.rate1000M;32.}33.}配置/etc/drbd.d/web.res
01.[root@drbd2 etc]# vim /etc/drbd.d/web.res02.resource web {03.on drbd1 {04.device/dev/drbd0;05.disk/dev/sda;06.address192.168.253.129:7789;07.meta-disk internal;08.}09.on drbd2 {10.device/dev/drbd0;11.disk/dev/sda;12.address192.168.253.140:7789;13.meta-disk internal;14.}15.}启动DRBD
1.[root@drbd1 ~]# drbdadm create-md all2.Writing meta data...3.initializing activity log4.NOT initialized bitmap5.New drbd meta data block successfully created.启动DRBD时,可能出现以下错误
01.[root@drbd1 ~]# drbdadm create-md all02.md_offset2147483238403.al_offset2147479961604.bm_offset2147414425605.Found ext3 filesystem06.20971520kB data area apparently used07.20970844kB left usable by current configuration08.Device size would be truncated, which09.would corrupt dataandresultin10.'access beyond end of device'errors.11.You need to either12.*use external meta data (recommended)13.*shrink that filesystem first14.*zero out the device (destroy the filesystem)15.Operation refused.16.Command'drbdmeta 0 v08 /dev/sda internal create-md'terminated with exit code4017.drbdadm create-md web: exited with code40这事需要如下命令覆盖文件系统中的设备块信息
1.[root@drbd1 ~]# dd if=/dev/zero of=/dev/sda bs=1M count=1282.记录了128+0的读入3.记录了128+0的写出4.134217728字节(134MB)已复制,0.448662秒,299MB/秒再重新启动DRBD,可以通过dmesg命令查看DRBD的启动过程
浙公网安备 33010602011771号