23.1、mysql高可用业务需求:
23.2、mysql高可用架构图(单主热备模式):
23.6、部署drbd、heartbeat、mysql的主从同步:
1、部署heartbeat:参考"21、部署herartbeat"文档;
2、部署drbd:参考"22、部署drbd"文档;
3、heartbeat和drbd整合:参考"22.17、heartbeat和drbd整合"文档;
3、部署mysql同步:参考"14、mysql主从复制实战"、"3、mysql的多实例配置"文档;
23.7、配置细节说明:
停止主和从的heartbeat和drbd服务;
1、heartbeat:
(1)修改maste-db和slave-db的/etc/ha.d/haresource配置文件:
(2)master-db IPaddr::172.16.1.26/24/eth1 drbddisk::data Filesystem::/dev/drbd0::/master-db::ext4 mysql
2、drbd:
(1)启动master-db和slave-db上的drbd服务;
(2)使用'drbdadm primary data'将master-db端的drdb服务置主;
(3)手动挂载master-db端的'/dev/drbd0'设备到'/master-db/'目录上;
3、mysql:
(1)在master-db和slave-db相同的路径下安装mysql软件;
(2)master-db端在/master-db/目录下面初始化mysql并指定data目录为/master-db/,为mysql创建登录密码,启动mysql测试;
此时在master-db的操作都同步到了slave-db端的/dev/drbd0管理的/dev/sdb1系统分区下面;slave-db端只要保证有/master-db/目录即可;
[root@master-db ~]#tree /master-db/
/master-db/
├── 3306
│ ├── my.cnf
│ └── mysql
│ └── data
└── lost+found
2 directories, 3 files
(3)在master-db端和slave-db端将mysql脚本拷贝到/etc/ha.d/resource.d/目录下面,方便heartbeat管理mysql,要加执行的权限;
(4)为了方便测试在slave-db端安装端口为3307的mysql多实例进行测;
23.8、测试:
停止master-db和slave-db上的mysql、heartbeat、drbd服务;
1、启动顺序:
(1)master-db:
1)drbdadm up data
2)/etc/init.d/heartbeat start
(2)slave-db:
1)drbdadm up data
2)/etc/init.d/heartbeat start
3)/data/3307/mysql start
2、结果:
(1)master-db:
1)df -h
Filesystem Size Used Avail Use% Mounted on
/dev/drbd0 4.5G 1.4G 2.9G 33% /master-db
2)cat /proc/drbd
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:12 nr:0 dw:4 dr:817 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
3)ip addr
3: eth1:
link/ether 00:0c:29:5c:f0:d0 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.16/24 brd 172.16.1.255 scope global eth1
inet 172.16.1.26/24 brd 172.16.1.255 scope global secondary eth1
inet6 fe80::20c:29ff:fe5c:f0d0/64 scope link
valid_lft forever preferred_lft forever
4)ss -tunlp | grep 3306
tcp LISTEN 0 600 *:3306 *:* user
(2)slave-db:
1)ip addr、df -h、ss -tunlp | grep 3306无结果:
2)cat /proc/drbd
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:12 nr:0 dw:4 dr:817 al:1 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
3)查看3307主从同步结果:
show slave status\G;
3、master-db和slave-db进行切换:
(1)在master-db上执行'/usr/share/heartbeat/hb_standy'命令将资源交给slave-db端,
此时结果和上面的结果想法;此时会发现slave-db端的3307 mysql实例在show slave status\G;状态时
会出现正在尝试连接主端,等待60s就可以了,在等待的60s期间由于vip已经漂移到了salve-db端,磁盘
已经挂载(drbd此端为主,对端为从),mysql启动,所以用户还是可以往数据库中写数据的;
(2)在主端执行'/usr/share/heartbeat/hb_takeover local'master-db从slave-db接管回资源;
4、关闭顺序:
(1)slave-db:
/data/3307/mysql stop
/etc/init.d/heartbeat stop
drbdadm down data
(2)master-db:
/etc/init.d/heartbeat stop
drbdadm down data
手机扫一扫
移动阅读更方便
你可能感兴趣的文章