HA_Cluster: corosync+pacemaker+drbd+mysql
来源:SegmentFault
2023-02-24 19:45:03
0浏览
收藏
来到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删除
mysql 配置优化
- 上一篇
- mysql 配置优化
- 下一篇
- MySQL避免索引列使用 OR 条件
查看更多
最新文章
-
- 数据库 · MySQL | 6小时前 |
- MySQL collation 不一致导致 JOIN 报错怎么统一
- 446浏览 收藏
-
- 数据库 · MySQL | 14小时前 |
- MySQL 递归 CTE 生成日期序列时为什么列类型会截断
- 104浏览 收藏
-
- 数据库 · MySQL | 18小时前 |
- MySQL 递归 CTE 遍历树数据时怎么防止无限循环
- 142浏览 收藏
-
- 数据库 · MySQL | 21小时前 |
- MySQL invisible index 如何安全观察索引下线影响
- 300浏览 收藏
-
- 数据库 · MySQL | 22小时前 | MySQL · 索引优化 · generated column · mysql 索引 优化器 生成列
- MySQL 生成列索引为什么没有被优化器使用
- 300浏览 收藏
-
- 数据库 · MySQL | 1天前 |
- MySQL 窗口函数取每组最新记录时如何处理并列时间
- 242浏览 收藏
-
- 数据库 · MySQL | 1天前 |
- MySQL JSON_VALUE 返回 NULL 时怎么区分缺少路径和空值
- 170浏览 收藏
-
- 数据库 · MySQL | 1天前 | MySQL · JSON查询 · JSON_TABLE · SQL技巧 · mysql JSON_TABLE FOR ORDINALITY JSON数组序号
- MySQL JSON_TABLE 的 FOR ORDINALITY 怎么保留数组原始序号
- 139浏览 收藏
-
- 数据库 · MySQL | 1天前 |
- MySQL 复制延迟升高时怎么区分 SQL 线程和 IO 线程
- 304浏览 收藏
查看更多
课程推荐
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 543次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 516次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 500次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 485次学习
查看更多
AI推荐
-
- H2O EvalGPT
- H2O EvalGPT是H2O.ai推出的开源LLM评估平台,提供详细的大模型性能排行榜、行业特定基准测试及A/B测试功能,助您快速选择最适合项目的高性能大语言模型。
- 61次使用
-
- SuperCLUE
- SuperCLUE是权威的中文大语言模型综合评测基准,涵盖语言理解、知识应用、AI Agent智能体及安全性等12项核心能力。通过多轮对话与客观测试,定期发布榜单与技术报告,为模型研发、优化及行业选型提供科学依据。
- 216次使用
-
- C-Eval
- 深入了解C-Eval中文评估套件,涵盖52个学科与4级难度。本文详解其功能特点、Zero-shot/Few-shot使用方法及代码示例,助您全面评测LLM中文理解与泛化能力。
- 145次使用
-
- AI Prompt Library
- 探索AI Prompt Library免费资源库,涵盖营销、写作及多场景AI提示词。兼容ChatGPT、Claude等工具,一键复制优化输出,提升工作效率。
- 79次使用
-
- Generrated
- Generrated汇集9300+张DALL·E生成图像及对应提示词,支持查看完整图集、对比DALL·E 2与3版本差异,是AI绘图新手学习Prompt设计与获取创作灵感的实用工具。
- 55次使用
查看更多
相关文章
-
- MySQL 明明加了索引,为什么查询还是很慢?先查这 6 个点
- 2026-06-27 374浏览
-
- golang MySQL实现对数据库表存储获取操作示例
- 2022-12-22 499浏览
-
- golang 基于 mysql 简单实现分布式读写锁
- 2023-01-07 384浏览
-
- 详解如何利用GORM实现MySQL事务
- 2023-01-07 184浏览
-
- Go语言实现操作MySQL的基础知识总结
- 2023-01-23 265浏览

