docker compose mysql主从复制及orchestrator高可用使用

 1.orchestrator 功能演示:

1.1 多级级联:

1.2 主从切换:

切换成功后,原来的主库是红色的,需要在主库的配置页面点击“start replication ”,重新连接上新的主库。

1.3 主从故障,从库自动切换新主库

2.mysql主从复制 搭建

参考地址:https://www.jb51.net/server/3105779cp.htmhttps://www.jb51.net/server/3105779cp.htm

主库my.cnf配置文件如下:

[mysqld]
log-bin=mysql-bin
server-id=1
report_host=172.22.0.103
log-slave-updates=1
# 启用GTID模式
gtid_mode=ON
# 确保一致性
enforce_gtid_consistency=ON
# 使用表格存储master信息
master_info_repository=TABLE
# 使用表格存储relay log信息
relay_log_info_repository=TABLE
# 设置binlog格式为ROW
binlog_format=ROW

其他数据库的my.cnf只需要修改server-id和report_host就行了。

docker compose 配置文件如下:

version: "3"services:mysql-master:container_name: mysql-masterhostname: mysql-masterimage: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3307:3306"networks:mysql-network:ipv4_address: 172.22.0.103volumes:- ./mysql1/conf/my.cnf:/etc/my.cnf- ./mysql1/data:/var/lib/mysqlmysql-slave:container_name: mysql-slavehostname: mysql-slaveimage: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3308:3306"networks:mysql-network:ipv4_address: 172.22.0.104volumes:- ./mysql2/conf/my.cnf:/etc/my.cnf- ./mysql2/data:/var/lib/mysqlmysql-slave2:container_name: mysql-slave2hostname: mysql-slave2image: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3309:3306"networks:mysql-network:ipv4_address: 172.22.0.105volumes:- ./mysql3/conf/my.cnf:/etc/my.cnf- ./mysql3/data:/var/lib/mysql
networks:mysql-network:driver: bridgeipam:config:- subnet: 172.22.0.0/16

主从复制使用gtid,

主库需要执行的sql:

create user 'repl_user'@'%' identified by 'test123456';
grant replication slave on *.* to 'repl_user'@'%';

从库需要执行的sql:

stop slave ;CHANGE MASTER TO MASTER_HOST='192.168.0.62', MASTER_PORT=3306, MASTER_USER='repl_user',
MASTER_PASSWORD='test123456',master_auto_position=1;start slave;show slave status;--主从切换时要用到,提前创建好用户create user 'repl_user'@'%' identified by 'test123456';
grant replication slave on *.* to 'repl_user'@'%';

检查主从同步是否配置好,在主库执行以下sql:

show slave hosts;

主从复制正常时,显示如下:

3.orchestrator 搭建

参考地址:Orchestrator实现MySQL故障切换 - 墨天轮 (modb.pro)

orchestrator.conf.json配置文件如下:

{"Debug": true,"EnableSyslog": false,"ListenAddress": ":3000","MySQLTopologyUser": "orc_client_user","MySQLTopologyPassword": "test123456","MySQLTopologyCredentialsConfigFile": "","MySQLTopologySSLPrivateKeyFile": "","MySQLTopologySSLCertFile": "","MySQLTopologySSLCAFile": "","MySQLTopologySSLSkipVerify": true,"MySQLTopologyUseMutualTLS": false,"MySQLOrchestratorHost": "172.22.0.102","MySQLOrchestratorPort": 3306,"MySQLOrchestratorDatabase": "orcdb","MySQLOrchestratorUser": "orc1","MySQLOrchestratorPassword": "orc123456","MySQLOrchestratorCredentialsConfigFile": "","MySQLOrchestratorSSLPrivateKeyFile": "","MySQLOrchestratorSSLCertFile": "","MySQLOrchestratorSSLCAFile": "","MySQLOrchestratorSSLSkipVerify": true,"MySQLOrchestratorUseMutualTLS": false,"MySQLConnectTimeoutSeconds": 1,"RaftEnabled": true,"RaftDataDir": "/var/lib/orchestrator","RaftBind": "172.22.0.91",	"DefaultRaftPort": 10008,"RaftNodes": ["172.22.0.91","172.22.0.92","172.22.0.93"], "DefaultInstancePort": 3306,"DiscoverByShowSlaveHosts": false,"InstancePollSeconds": 5,"DiscoveryIgnoreReplicaHostnameFilters": ["a_host_i_want_to_ignore[.]example[.]com",".*[.]ignore_all_hosts_from_this_domain[.]example[.]com","a_host_with_extra_port_i_want_to_ignore[.]example[.]com:3307"],"UnseenInstanceForgetHours": 240,"SnapshotTopologiesIntervalHours": 0,"InstanceBulkOperationsWaitTimeoutSeconds": 10,"HostnameResolveMethod": "default","MySQLHostnameResolveMethod": "@@hostname","SkipBinlogServerUnresolveCheck": true,"ExpiryHostnameResolvesMinutes": 60,"RejectHostnameResolvePattern": "","ReasonableReplicationLagSeconds": 10,"ProblemIgnoreHostnameFilters": [],"VerifyReplicationFilters": false,"ReasonableMaintenanceReplicationLagSeconds": 20,"CandidateInstanceExpireMinutes": 60,"AuditLogFile": "","AuditToSyslog": false,"RemoveTextFromHostnameDisplay": ".mydomain.com:3306","ReadOnly": false,"AuthenticationMethod": "","HTTPAuthUser": "","HTTPAuthPassword": "","AuthUserHeader": "","PowerAuthUsers": ["*"],"ClusterNameToAlias": {"127.0.0.1": "test suite"},"ReplicationLagQuery": "","DetectClusterAliasQuery": "SELECT SUBSTRING_INDEX(@@hostname, '.', 1)","DetectClusterDomainQuery": "","DetectInstanceAliasQuery": "","DetectPromotionRuleQuery": "","DataCenterPattern": "[.]([^.]+)[.][^.]+[.]mydomain[.]com","PhysicalEnvironmentPattern": "[.]([^.]+[.][^.]+)[.]mydomain[.]com","PromotionIgnoreHostnameFilters": [],"DetectSemiSyncEnforcedQuery": "","ServeAgentsHttp": false,"AgentsServerPort": ":3001","AgentsUseSSL": false,"AgentsUseMutualTLS": false,"AgentSSLSkipVerify": false,"AgentSSLPrivateKeyFile": "","AgentSSLCertFile": "","AgentSSLCAFile": "","AgentSSLValidOUs": [],"UseSSL": false,"UseMutualTLS": false,"SSLSkipVerify": false,"SSLPrivateKeyFile": "","SSLCertFile": "","SSLCAFile": "","SSLValidOUs": [],"URLPrefix": "","StatusEndpoint": "/api/status","StatusSimpleHealth": true,"StatusOUVerify": false,"AgentPollMinutes": 60,"UnseenAgentForgetHours": 6,"StaleSeedFailMinutes": 60,"SeedAcceptableBytesDiff": 8192,"PseudoGTIDPattern": "","PseudoGTIDPatternIsFixedSubstring": false,"PseudoGTIDMonotonicHint": "asc:","DetectPseudoGTIDQuery": "","BinlogEventsChunkSize": 10000,"SkipBinlogEventsContaining": [],"ReduceReplicationAnalysisCount": true,"FailureDetectionPeriodBlockMinutes": 60,"FailMasterPromotionOnLagMinutes": 0,"RecoveryPeriodBlockSeconds": 60,"RecoveryIgnoreHostnameFilters": [],"RecoverMasterClusterFilters": ["*"],"RecoverIntermediateMasterClusterFilters": ["*"],"OnFailureDetectionProcesses": ["echo 'Detected {failureType} on {failureCluster}. Affected replicas: {countSlaves}' >> /tmp/recovery.log"],"PreGracefulTakeoverProcesses": ["echo 'Planned takeover about to take place on {failureCluster}. Master will switch to read_only' >> /tmp/recovery.log"],"PreFailoverProcesses": ["echo 'Will recover from {failureType} on {failureCluster}' >> /tmp/recovery.log"],"PostFailoverProcesses": ["echo '(for all types) Recovered from {failureType} on {failureCluster}. Failed: {failedHost}:{failedPort}; Successor: {successorHost}:{successorPort}' >> /tmp/recovery.log"],"PostUnsuccessfulFailoverProcesses": [],"PostMasterFailoverProcesses": ["echo 'Recovered from {failureType} on {failureCluster}. Failed: {failedHost}:{failedPort}; Promoted: {successorHost}:{successorPort}' >> /tmp/recovery.log"],"PostIntermediateMasterFailoverProcesses": ["echo 'Recovered from {failureType} on {failureCluster}. Failed: {failedHost}:{failedPort}; Successor: {successorHost}:{successorPort}' >> /tmp/recovery.log"],"PostGracefulTakeoverProcesses": ["echo 'Planned takeover complete' >> /tmp/recovery.log"],"CoMasterRecoveryMustPromoteOtherCoMaster": true,"DetachLostSlavesAfterMasterFailover": true,"ApplyMySQLPromotionAfterMasterFailover": true,"PreventCrossDataCenterMasterFailover": false,"PreventCrossRegionMasterFailover": false,"MasterFailoverDetachReplicaMasterHost": false,"MasterFailoverLostInstancesDowntimeMinutes": 0,"PostponeReplicaRecoveryOnLagMinutes": 0,"OSCIgnoreHostnameFilters": [],"GraphiteAddr": "","GraphitePath": "","GraphiteConvertHostnameDotsToUnderscores": true,"ConsulAddress": "","ConsulAclToken": "","ConsulKVStoreProvider": "consul"
}

多个orchestrator.conf.json需要修改的地方如下:

"MySQLTopologyUser": "orc_client_user","MySQLTopologyPassword": "test123456",......"MySQLOrchestratorHost": "172.22.0.102","MySQLOrchestratorPort": 3306,"MySQLOrchestratorDatabase": "orcdb","MySQLOrchestratorUser": "orc1","MySQLOrchestratorPassword": "orc123456",......"AuthenticationMethod": "basic","HTTPAuthUser": "admin","HTTPAuthPassword": "uq81sgca1da",  "RaftEnabled":true,"RaftDataDir":"/usr/local/orchestrator/raftdata","RaftBind": "172.22.0.91",	"DefaultRaftPort": 10008,"RaftNodes": ["172.22.0.91","172.22.0.92","172.22.0.93"], ......"RecoveryPeriodBlockSeconds": 60,"RecoveryIgnoreHostnameFilters": [],"RecoverMasterClusterFilters": ["*"],"RecoverIntermediateMasterClusterFilters": ["*"],......

MySQLTopologyUser是orchestrator监听mysql主从数据库时使用的用户

MySQLOrchestratorUser是orchestrator自身需要的数据库

在主库和从库执行以下sql,创建MySQLTopologyUser:

create user 'orc_client_user'@'%' identified by 'test123456'; 
GRANT ALL PRIVILEGES ON *.* TO 'orc_client_user'@'%';

在orchestrator自身的数据库(这个数据库是独立的,不在三个mysql主从库之中)执行以下sql,创建MySQLOrchestratorUser:

CREATE USER 'orc1'@'%' IDENTIFIED BY 'orc123456';
GRANT ALL PRIVILEGES ON *.* TO 'orc1'@'%';

 成功启动后,如下图:

4.完整的docker-compose.yml文件

version: "3"services:# orchestrator 监控orchestrator-test1:container_name: orchestrator-test1image: openarkcode/orchestrator:latestrestart: alwaysports:- "3000:3000"networks:mysql-network:ipv4_address: 172.22.0.91volumes:- ./orchestrator.conf.json:/etc/orchestrator.conf.jsonorchestrator-test2:container_name: orchestrator-test2image: openarkcode/orchestrator:latestrestart: alwaysports:- "3002:3000"networks:mysql-network:ipv4_address: 172.22.0.92volumes:- ./orchestrator2.conf.json:/etc/orchestrator.conf.jsonorchestrator-test3:container_name: orchestrator-test3image: openarkcode/orchestrator:latestrestart: alwaysports:- "3003:3000"networks:mysql-network:ipv4_address: 172.22.0.93volumes:- ./orchestrator3.conf.json:/etc/orchestrator.conf.json# orc 使用的数据库orc-mysql:container_name: orc-mysqlimage: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456MYSQL_PASSWORD: orc123456MYSQL_USER: orc1MYSQL_DATABASE: orcdbports:- "3306:3306"networks:mysql-network:ipv4_address: 172.22.0.102volumes:- ./mysql:/var/lib/mysqlmysql-master:container_name: mysql-masterhostname: mysql-masterimage: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3307:3306"networks:mysql-network:ipv4_address: 172.22.0.103volumes:- ./mysql1/conf/my.cnf:/etc/my.cnf- ./mysql1/data:/var/lib/mysqlmysql-slave:container_name: mysql-slavehostname: mysql-slaveimage: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3308:3306"networks:mysql-network:ipv4_address: 172.22.0.104volumes:- ./mysql2/conf/my.cnf:/etc/my.cnf- ./mysql2/data:/var/lib/mysqlmysql-slave2:container_name: mysql-slave2hostname: mysql-slave2image: mysql:5.7.30restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: test123456ports:- "3309:3306"networks:mysql-network:ipv4_address: 172.22.0.105volumes:- ./mysql3/conf/my.cnf:/etc/my.cnf- ./mysql3/data:/var/lib/mysql
networks:mysql-network:driver: bridgeipam:config:- subnet: 172.22.0.0/16

5.常见问题 

5.1 拖动报Relocating m03:3306 below m02:3306 turns to be too complex; please do it manually错误

解决办法:检查mysql是否启用gtid模式

5.2 mysql无法拖动到另一个mysql的下级,报ERROR m04:3306 cannot replicate from m03:3306. Reason: instance does not have log_slave_updates enabled: m03:3306错误

解决办法:mysql需要开启log-slave-updates

5.3 主从故障后,从库上显示errant gtid found错误

解决办法1:执行reset master

解决办法2:跳过从库多余的gtid,参考https://blog.csdn.net/weixin_48154829/article/details/124200051

5.4 orchestrator无法发现mysql主从集群,后台日志报hostname无法解析错误

解决办法:需要在安装orchestrator的机器上,修改hosts文件

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/6306.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

高精度(加减乘除)

1.加法 我们第一位存低位&#xff08;倒着存方便&#xff09; 下面是AC代码&#xff1a; #include<bits/stdc.h> using namespace std; const int N1e610; vector<int> add(vector<int> &A,vector<int> &B) {vector<int> c;int t0;for…

【JVM】从硬件层面和应用层面的有序性和可见性,到Java的volatile和synchronized

Java的关键字volatile保证了有序性和可见性&#xff0c;这里我试着从底层开始讲一下有序性和可见性。 一&#xff0c;一致性 数据如果同时被两个cpu读取了&#xff0c;如何保证数据的一致性&#xff1f;或者换句话说&#xff0c;cpu1改了数据&#xff0c;cpu2的数据就成了无效…

基于AT89C52单片机的智能热水器控制系统

点击链接获取Keil源码与Project Backups仿真图&#xff1a; https://download.csdn.net/download/qq_64505944/89242443?spm1001.2014.3001.5503 C 源码仿真图毕业设计实物制作步骤05 题 目 基于单片机的智能热水器系统 学 院 专 业 班 级 学 号 学生姓名 指导教师 完成日期…

242 基于matlab的3D路径规划

基于matlab的3D路径规划&#xff0c;蚁群算法&#xff08;ACO&#xff09;和天牛须&#xff08;BAS&#xff09;以及两种结合的三种优化方式&#xff0c;对3D路径规划的最短路径进行寻优。程序已调通&#xff0c;可直接运行。 242 3D路径规划 蚁群算法和天牛须 - 小红书 (xiaoh…

ant-design中的穿梭框提示文字修改

ant-design中的穿梭框提示文字修改 1.ant-design中的穿梭框提示文字修改 <a-transferv-model:target-keys"targetKeys":data-source"transform.list":filter-option"filterOption":list-style"{width: 100%,height: 500px,}":rowK…

unity入门学习笔记

文章目录 unity学习笔记熟悉界面窗口页面快捷键视图特点移动、旋转、缩放快捷键聚焦和隐藏 一些基本概念模型模型的导入一些补充 资源文件资源包的导出资源包的导入 轴心物体的父子关系空物体Global与localpivot与center 组件脚本基础我的第一个脚本 获取脚本组件本地坐标播放模…

顶顶顶顶顶顶顶顶顶顶顶顶

欢迎关注博主 Mindtechnist 或加入【智能科技社区】一起学习和分享Linux、C、C、Python、Matlab&#xff0c;机器人运动控制、多机器人协作&#xff0c;智能优化算法&#xff0c;滤波估计、多传感器信息融合&#xff0c;机器学习&#xff0c;人工智能等相关领域的知识和技术。关…

【电子通识】为什么用双绞线?双绞线抗干扰的原理是什么?

使用双绞线最大的理由是抗干扰。不仅可以防止别人干扰,也可以防止自己干扰别人。这与EMC中的EMS和EMI相对应(参考【EMC专题】电磁兼容--基本概念)。 双绞线是由一对带有绝缘层的铜线(绝缘层使两根线中的金属导体不会因为互碰而导致短路)以螺旋的方式缠绕在一起所构成的。通…

ElementUI从unpkg.com完整下载到本地的方法 - 解决unpkg.com不稳定的问题 - 自建镜像站 - 不想打包只想cdn一下

方法 方法1&#xff09;随便弄个文件夹&#xff0c;根据官网npm方法下载包&#xff0c;提取即可 npm i element-ui -S cd /node_modules/element-ui/ ls src 安装npm方法&#xff1a;https://nodejs.org/en 方法2&#xff09;不推荐 - 在github中搜索对应的库zip包&#xff0…

【网络原理】HTTP 协议的基本格式和 fiddler 抓包工具的用法

系列文章目录 【网络通信基础】网络中的常见基本概念 【网络编程】网络编程中的基本概念及Java实现UDP、TCP客户端服务器程序&#xff08;万字博文&#xff09; 【网络原理】UDP协议的报文结构 及 校验和字段的错误检测机制&#xff08;CRC算法、MD5算法&#xff09; 【网络…

PG实例连接访问控制

实例访问控制可以控制来自于不同主机&#xff0c;不同用户是否允许访问指定的数据库&#xff0c;以及验证方式。 与oracle中的连接管理器的功能相同&#xff0c;之前有写过一篇oracleCMAN连接管理器的配置实操&#xff1a; 配置oracle连接管理器&#xff08;cman&#xff09;…

深度学习每周学习总结P7(咖啡豆识别)

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 | 接辅导、项目定制 –来自百度网盘超级会员V5的分享 数据链接 提取码&#xff1a;7zt2 –来自百度网盘超级会员V5的分享 目录 0. 总结1. 数据导入及处理部分…

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《电-氢-混氢天然气耦合的城市综合能源系统低碳优化调度》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

Java | Leetcode Java题解之第68题文本左右对齐

题目&#xff1a; 题解&#xff1a; class Solution {private String line(List<String> list,int maxWidth,int totalLength,boolean isLast){StringBuilder sb new StringBuilder();sb.append(list.get(0));if(list.size() 1){String ap " ".repeat(maxW…

二维数组的鞍点(C语言)

一、鞍点解释&#xff1b; 鞍点就是该位置上的元素在该行上最大、在该列上最小&#xff1b; 二、N-S流程图&#xff1b; 三、运行结果&#xff1b; 四、源代码&#xff1b; # define _CRT_SECURE_NO_WARNINGS # include <stdio.h>int main() {//初始化变量值&#xff…

定制开发AI名片商城AI导购系统:引领营销自动化的新时代

在数字营销日新月异的今天&#xff0c;一个革命性的工具——定制开发AI名片商城AI导购系统&#xff0c;正逐渐崭露头角&#xff0c;成为企业私域运营中的得力助手。它不仅仅是一个营销工具&#xff0c;更是一个拥有强大营销自动化能力和先进算法技术的在线助理&#xff0c;为企…

【neteq】tgcall的调用

G:\CDN\P2P-DEV\Libraries\tg_owt\src\call\call.cc基本是按照原生webrtc的来的:G:\CDN\P2P-DEV\tdesktop-offical\Telegram\ThirdParty\tgcalls\tgcalls\group\GroupInstanceCustomImpl.cpptg对neteq的使用 worker 线程创建call Call的config需要neteqfactory Call::CreateAu…

[1702]java旅游资源网上填报系统Myeclipse开发mysql数据库web结构java编程计算机网页项目

一、源码特点 java旅游资源网上填报系统是一套完善的java web信息管理系统&#xff0c;对理解JSP java编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为 TOMCAT7.0,Myeclipse8.5开发&#xff0c;数据库为Mysql…

模式识别作业:颜色算子的三种阈值分割算法

一、引言&#xff1a; 在图像处理中&#xff0c;我们往往需要提取图像的一些关键信息&#xff0c;比如本篇文章的内容——提取颜色&#xff0c;然而当我们需要提取某一种颜色时&#xff0c;无论图像余下的部分如何“丰富多彩”&#xff0c;他们都不再重要&#xff0c;需要被忽…

如何使用SSH密钥克隆仓库

1.创建SSH Key 在用户目录下查看有没有.ssh目录。如果有且该.ssh目录下有id_rsa&#xff08;私钥&#xff09;&#xff0c;和id_rse_pub(公钥)这俩文件&#xff0c;那么这一步就可以跳过。否则使用以下指令创建SSH Key ssh-keygen -t rsa -C "xxxqq.com" "xx…