设为首页 收藏本站
查看: 743|回复: 0

[经验分享] drbd + mysql 高可用集群

[复制链接]

尚未签到

发表于 2017-10-26 09:07:16 | 显示全部楼层 |阅读模式
  在上两篇中,我分别写到了 drbd 和 corosync、pacemaker、crm 的配置和使用,在本节中,我讲这两种东西结合起来,做出 drbd + mysql 高可用集群。
一、实验环境

系统版本:centos7
实验机器:
    node1:192.168.163.172
    node2:192.168.163.173
软件源:阿里云


二、实验过程

drbd 的配置和 corosync 的配置就不再说明,直接开始
首先增加drbd资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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




增加文件系统资源
1
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做亲缘性绑定

1
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master





做顺序约束,当drbd起来之后才对文件系统进行绑定
1
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start




接下来增加一下mysql资源,并作亲缘性绑定
1
2
crm(live)configure#primitive mysqld systemd:mariadb
crm(live)configure# colocation mysqld_with_mystoreinf: mysqld mystore







作顺序约束,先挂载文件系统,然后在启动msyqld资源
1
crm(live)configure#order mysqld_after_mystore mandatory: mystore mysqld





增加VIP资源,作虚拟IP调度
1
2
3
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





检查并提交
1
2
crm(live)configure#verify
crm(live)configure#commit





查看状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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




三、测试

先访问数据库,并新建一个用户,供远程访问使用
1
2
MariaDB[(none)]> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';            
QueryOK, 0 rows affected (0.00 sec)





使用VIP访问数据库

[iyunv@node1 ~]# mysql -uroot -p123456 -h 192.168.163.100
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
1
crm(live)# node standby



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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访问数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[iyunv@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)





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-405923-1-1.html 上篇帖子: MySQL双主双活+Keepalived高可用方案关建配置点 下篇帖子: MySQL级联复制配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表