HA_Cluster: corosync+pacemaker+drbd+mysql
来源:SegmentFault
时间:2023-02-24 19:45:03 457浏览 收藏
来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《HA_Cluster: corosync+pacemaker+drbd+mysql》,介绍一下MySQL、HA、cluster、drbd,希望对大家的知识积累有所帮助,助力实战开发!
本文主要讲述HA_Cluster: corosync+pacemaker+drbd+mysql 的CRM资源配置, 各个软件的安装配置不再介绍
CRM配置DRBD资源:
1.基本配置:
crm(live)configure# property stonith-enabled=false #关闭stonith crm(live)configure# property no-quorum-policy=ignore #不具备法定票数时的行为: 忽略 crm(live)configure# rsc_defaults resource-stickiness=100 #默认资源粘性为100 crm(live)configure# verify crm(live)configure# commit
2.添加DRBD资源:
crm(live)configure# primitive drbd_data ocf:linbit:drbd params drbd_resource="data" op monitor role="Master" interval="50" timeout="30" op monitor role="Slave" interval interval-origin= interval= crm(live)configure# primitive drbd_data ocf:linbit:drbd params drbd_resource=data op monitor role=Master interval=50 timeout=30 op monitor role=Slave interval=60 timeout=30 op start timeout=240 op stop timeout=100 crm(live)configure# verify crm(live)configure# ms ms_drbd_data drbd_data meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true crm(live)configure# verify crm(live)configure# commit
PS: heartbeat 和 linbit 都提供了drbd 的 RA ,本人实验时发现使用 heartbeat 提供的 RA 会出现无法选举 Master 节点的情况, 此处建议使用 linbit 提供的RA
如有人知道为什么 heartbeat 的 RA 选不出 Master 节点, 愿闻其详
测试DRBD服务:
root@drbd1:~# crm status Last updated: Sun May 22 22:04:35 2016 Last change: Mon May 23 06:02:13 2016 via cibadmin on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 2 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd1 ] Slaves: [ drbd2 ] root@drbd1:~# crm node standby #离线drbd1 root@drbd1:~# crm status Last updated: Mon May 23 06:07:22 2016 Last change: Mon May 23 06:07:14 2016 via crm_attribute on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 2 Resources configured Node drbd1 (168495249): standby Online: [ drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd2 ] Stopped: [ drbd1 ] root@drbd1:~# crm node online #上线drbd1 root@drbd1:~# crm status Last updated: Mon May 23 06:09:11 2016 Last change: Mon May 23 06:09:09 2016 via crm_attribute on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 2 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd2 ] Slaves: [ drbd1 ] root@drbd2:~# crm node standby #离线drbd2 root@drbd2:~# crm node online #上线drbd2 root@drbd2:~# crm status Last updated: Sun May 22 22:11:47 2016 Last change: Mon May 23 06:11:18 2016 via crm_attribute on drbd2 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 2 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd1 ] Slaves: [ drbd2 ] -------------正常---------------
配置Filesystem资源:
crm(live)configure# primitive mount ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/var/lib/mysql fstype=ext3 op start timeout=60 op stop timeout=60 crm(live)configure# verify crm(live)configure# colocation mount_with_ms_drbd_data inf: mount ms_drbd_data:Master crm(live)configure# order mount_after_ms_drbd_data Mandatory: ms_drbd_data:promote mount:start crm(live)configure# verify crm(live)configure# commit
测试Filesystem资源:
root@drbd2:~# crm status Last updated: Mon May 23 20:28:19 2016 Last change: Mon May 23 20:27:37 2016 via crm_attribute on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 3 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd2 ] Slaves: [ drbd1 ] mount (ocf::heartbeat:Filesystem): Started drbd2 #现在drbd0挂载在drbd2上 root@drbd2:~# crm node standby root@drbd2:~# crm node online root@drbd2:~# crm status Last updated: Mon May 23 20:28:31 2016 Last change: Mon May 23 20:28:28 2016 via crm_attribute on drbd2 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 3 Resources configured Node drbd2 (168495262): standby Online: [ drbd1 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd1 ] Stopped: [ drbd2 ] mount (ocf::heartbeat:Filesystem): Started drbd1 #成功转移到drbd1
配置mysql(此处直接使用apt-get安装)资源:
crm(live)configure# primitive mysqld lsb:mysql crm(live)configure# primitive mysql_ip ocf:heartbeat:IPaddr params ip=10.11.8.200 cidr_netmask=23 crm(live)configure# verify crm(live)configure# colocation mysql_ip_with_mount inf: mysql_ip mount crm(live)configure# colocation mysqld_with_mount inf: mysqld mount crm(live)configure# order mysqld_after_mount Mandatory: mount mysqld crm(live)configure# verify crm(live)configure# commit
查看CRM配置:
node $id="168495249" drbd1 \ attributes standby="off" node $id="168495262" drbd2 \ attributes standby="off" primitive drbd_data ocf:linbit:drbd \ params drbd_resource="data" \ op monitor role="Master" interval="50" timeout="30" \ op monitor role="Slave" interval="60" timeout="30" \ op start timeout="240" interval="0" \ op stop timeout="100" interval="0" primitive mount ocf:heartbeat:Filesystem \ primitive mount ocf:heartbeat:Filesystem \ params device="/dev/drbd0" directory="/var/lib/mysql" fstype="ext3" \ op start timeout="60" interval="0" \ op stop timeout="60" interval="0" \ meta target-role="Started" primitive mysql_ip ocf:heartbeat:IPaddr \ params ip="10.11.8.200" cidr_netmask="23" primitive mysqld lsb:mysql ms ms_drbd_data drbd_data \ meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" target-role="Started" colocation mount_with_ms_drbd_data inf: mount ms_drbd_data:Master colocation mysql_ip_with_mount inf: mysql_ip mount colocation mysqld_with_mount inf: mysqld mount order mount_after_ms_drbd_data Mandatory: ms_drbd_data:promote mount:start order mysqld_after_mount Mandatory: mount mysqld property $id="cib-bootstrap-options" \ dc-version="1.1.10-42f2063" \ cluster-infrastructure="corosync" \ stonith-enabled="false" \ no-quorum-policy="ignore" \ last-lrm-refresh="1464019270" rsc_defaults $id="rsc-options" \ resource-stickiness="100"
修改mysql监听所有地址:
root@drbd1:~# vim /etc/mysql/my.cnf #bind-address = 127.0.0.1 #注释这一行
测试服务:
root@drbd1:~# crm status Last updated: Tue May 24 00:55:04 2016 Last change: Tue May 24 00:42:45 2016 via crmd on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 5 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd1 ] Slaves: [ drbd2 ] mount (ocf::heartbeat:Filesystem): Started drbd1 mysqld (lsb:mysql): Started drbd1 mysql_ip (ocf::heartbeat:IPaddr): Started drbd1
在drbd2上连接测试:
root@drbd2:~# mysql -h10.11.8.200 -ushiina -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 40 Server version: 5.6.30-0ubuntu0.14.04.1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | #mysql50#lost+found | | mysql | | performance_schema | +---------------------+ 4 rows in set (0.01 sec) mysql> create database ha_test; Query OK, 1 row affected (0.00 sec)
离线drbd1后再drbd1上连接测试:
root@drbd1:~# crm status Last updated: Mon May 23 21:13:24 2016 Last change: Mon May 23 21:13:22 2016 via cibadmin on drbd1 Stack: corosync Current DC: drbd1 (168495249) - partition with quorum Version: 1.1.10-42f2063 2 Nodes configured 5 Resources configured Online: [ drbd1 drbd2 ] Master/Slave Set: ms_drbd_data [drbd_data] Masters: [ drbd2 ] Slaves: [ drbd1 ] mount (ocf::heartbeat:Filesystem): Started drbd2 mysql_ip (ocf::heartbeat:IPaddr): Started drbd2 mysqld (lsb:mysql): Started drbd2 root@drbd1:~# mysql -h10.11.8.200 -ushiina -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 40 Server version: 5.6.30-0ubuntu0.14.04.1 (Ubuntu) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ha_test | | lost+found | | mysql | | performance_schema | +--------------------+ 5 rows in set (0.00 sec)
本篇关于《HA_Cluster: corosync+pacemaker+drbd+mysql》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!
声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
499 收藏
-
244 收藏
-
235 收藏
-
157 收藏
-
101 收藏
最新阅读
更多>
-
485 收藏
-
113 收藏
-
293 收藏
-
365 收藏
-
247 收藏
-
188 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 507次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习