drbd + mysql 高可用集群
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了drbd + mysql 高可用集群,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5794字,纯文字阅读大概需要9分钟。
内容图文
![drbd + mysql 高可用集群](/upload/InfoBanner/zyjiaocheng/493/4c92cd253bb242a6ba914a34cb95e547.jpg)
在上两篇中,我分别写到了 drbd 和 corosync、pacemaker、crm 的配置和使用,在本节中,我讲这两种东西结合起来,做出 drbd + mysql 高可用集群。
一、实验环境
系统版本:centos7
实验机器:
node1:192.168.163.172
node2:192.168.163.173
软件源:阿里云
二、实验过程
drbd 的配置和 corosync 的配置就不再说明,直接开始
首先增加drbd资源
crm(live)#configure crm(live)configure#primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op start timeout=240 op stop timeout=100 op monitor role=Master interval=20 timeout=30 op monitor role=Slave interval=30 timeout=30 crm(live)configure#ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2clone-node-max=1 notify=true crm(live)configure#verify crm(live)configure#show crm(live)configure# show node 1: node1 node 2: node2 primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op start timeout=240 interval=0 op stop timeout=100 interval=0 op monitor role=Master interval=20 timeout=30 op monitor role=Slave interval=30 timeout=30 ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true property cib-bootstrap-options: have-watchdog=false dc-version=1.1.16-12.el7_4.4-94ff4df cluster-infrastructure=corosync cluster-name=mycluster stonith-enabled=false
增加文件系统资源
crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/data fstype=xfs op start timeout=60 op stop timeout=60
给文件系统类型和drbd做亲缘性绑定
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
做顺序约束,当drbd起来之后才对文件系统进行绑定
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start
接下来增加一下mysql资源,并作亲缘性绑定
crm(live)configure#primitive mysqld systemd:mariadb crm(live)configure# colocation mysqld_with_mystoreinf: mysqld mystore
作顺序约束,先挂载文件系统,然后在启动msyqld资源
crm(live)configure#order mysqld_after_mystore mandatory: mystore mysqld
增加VIP资源,作虚拟IP调度
crm(live)#configure crm(live)configure#primitive myvip ocf:heartbeat:IPaddr params ip="192.168.113.120" opmonitor interval=20 timeout=20 on-fail=restart crm(live)configure# colocation vip_with_ms_mysqldrbd inf:ms_mysqldrbd:Master myvip
检查并提交
crm(live)configure#verify crm(live)configure#commit
查看状态
crm(live)# status Stack: corosync Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum Last updated: Wed Oct 25 08:38:22 2017 Last change: Wed Oct 25 08:38:14 2017 by root via crm_attribute on node2 2 nodes configured 5 resources configured Online: [ node1 node2 ] Full list of resources: Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node1 ] Slaves: [ node2 ] mystore(ocf::heartbeat:Filesystem):Started node1 mysqld(systemd:mariadb):Started node1 myvip(ocf::heartbeat:IPaddr):Started node1
三、测试
先访问数据库,并新建一个用户,供远程访问使用
MariaDB[(none)]> GRANT ALL ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456‘; QueryOK, 0 rows affected (0.00 sec)
使用VIP访问数据库
[root@node1 ~]# mysql -uroot -p123456 -h 192.168.163.100
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. MariaDB [(none)]> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | #mysql50#lost+found | | mysql | | mysqld | | performance_schema | | xhk | | xhk777 | +---------------------+ 7 rows in set (0.06 sec)
接下来,将node停掉,服务自行转到node2
crm(live)# node standby
crm(live)# status Stack: corosync Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum Last updated: Wed Oct 25 08:43:46 2017 Last change: Wed Oct 25 08:43:41 2017 by root via crm_attribute on node1 2 nodes configured 5 resources configured Node node1: standby Online: [ node2 ] Full list of resources: Master/Slave Set: ms_mysqldrbd [mysqldrbd] Slaves: [ node2 ] Stopped: [ node1 ] mystore (ocf::heartbeat:Filesystem): Stopped mysqld (systemd:mariadb): Stopped
crm(live)# status Stack: corosync Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum Last updated: Wed Oct 25 08:43:46 2017 Last change: Wed Oct 25 08:43:41 2017 by root via crm_attribute on node1 2 nodes configured 5 resources configured Node node1: standby Online: [ node2 ] Full list of resources: Master/Slave Set: ms_mysqldrbd [mysqldrbd] Slaves: [ node2 ] Stopped: [ node1 ] mystore(ocf::heartbeat:Filesystem):Stopped mysqld(systemd:mariadb):Stopped myvip(ocf::heartbeat:IPaddr):Started node2
继续使用VIP访问数据库
[root@node1 ~]# mysql -uroot -p123456 -h 192.168.163.100 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. MariaDB [(none)]> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | #mysql50#lost+found | | mysql | | mysqld | | performance_schema | | xhk | | xhk777 | +---------------------+ 7 rows in set (0.06 sec)
本文出自 “xhk777” 博客,请务必保留此出处http://xhk777.blog.51cto.com/13405744/1976169
drbd + mysql 高可用集群
标签:drbd mariadb corosync pacemaker
本文系统来源:http://xhk777.blog.51cto.com/13405744/1976169
内容总结
以上是互联网集市为您收集整理的drbd + mysql 高可用集群全部内容,希望文章能够帮你解决drbd + mysql 高可用集群所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。