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.hqwc.cn/news/660740.html

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

相关文章

Go中为什么不建议用锁?

Go语言中是不建议用锁,而是用通道Channel来代替(不要通过共享内存来通信,而通过通信来共享内存),当然锁也是可以用,锁是防止同一时刻多个goroutine操作同一个资源; GO语言中,要传递某个数据给另一个gorout…

Stm32CubeMX 为 stm32mp135d 添加 spi

Stm32CubeMX 为 stm32mp135d 添加 spi 一、启用设备1. spi 设备添加2. spi 引脚配置2. spi 时钟配置 二、 生成代码1. optee 配置 spi 时钟和安全验证2. linux spi 设备 dts 配置 bringup 可参考:Stm32CubeMX 生成设备树 一、启用设备 1. spi 设备添加 选中spi设…

使用UmcFramework和unimrcpclient.xml连接多个SIP设置的配置指南及C代码示例

使用UmcFramework和unimrcpclient.xml连接多个SIP设置的配置指南及C代码示例 引言1. UniMRCP和UmcFramework简介2. 准备工作3. unimrcpclient.xml配置文件3.1 定义SIP设置3.2 定义MRCP会话配置文件 4. C代码示例5. 测试和验证6. 故障排查7. 结论8. 参考文献 引言 在多媒体通信…

js语法---map,set结构

map和set是像对象和数组一样的数据结构集,内部可以按照一定的关系存放一串数据 map map是一个带键的数据项的集合,就像一个 Object 一样。 但是它们最大的差别是 Map 允许任何类型的键(key)。 它的方法和属性如下: n…

后端方案设计文档结构模板可参考

文章目录 1 方案设计文档整体结构2 方案详细设计2.1 概要设计2.2 详细设计方案2.2.1 需求分析2.2.2 业务流程设计2.2.3 抽象类:实体对象建模2.2.4 接口设计2.2.5 存储设计 1 方案设计文档整体结构 一,现状:把项目的基本情况和背景都说清楚&a…

SpringCloud学习笔记(二)Ribbon负载均衡、Nacos注册中心、Nacos与Eureka的区别

文章目录 4 Ribbon负载均衡4.1 负载均衡原理4.2 源码解读4.3 负载均衡策略4.3.1 内置的负载均衡策略4.3.2 自定义负载均衡策略4.3.2.1 方式一:定义IRule4.3.2.2 方式二:配置文件 4.4 饥饿加载 5 Nacos注册中心5.1 认识和安装Nacos5.2 服务注册到Nacos5.3…

【linux-1-Ubuntu常用命令-vim编辑器-Vscode链接ubuntu远程开发】

目录 1. 安装虚拟机Vmare和在虚拟机上安装Ubuntu系统:2. 常用的Ubuntu常识和常用命令2.1 文件系统结构2.2 常用命令2.3 vim编辑器 3. Ubuntu能联网但是ping不通电脑:4. Windows上安装VScode链接ubuntu系统,进行远程开发: 1. 安装虚…

qt5-入门-2D绘图-Graphics View 架构

参考: Qt Graphics View Framework_w3cschool https://www.w3cschool.cn/learnroadqt/4mvj1j53.html C GUI Programming with Qt 4, Second Edition 本地环境: win10专业版,64位,Qt 5.12 基础知识 QPainter比较适合少量绘图的情…

【webrtc】MessageHandler 2: 基于线程的消息处理:以PeerConnectionClient为例

PeerConnectionClient 前一篇 nullaudiopoller 并么有场景线程,而是就是在当前线程直接执行的, PeerConnectionClient 作为一个独立的客户端,默认的是主线程。 PeerConnectionClient 同时维护客户端的信令状态,并且通过OnMessage实现MessageHandler 消息处理。 目前只处理一…

【分享】如何将word格式文档转化为PDF格式

在日常的办公和学习中,我们经常需要将Word文档转换为PDF格式。PDF作为一种通用的文件格式,具有跨平台、易读性高等优点,因此在许多场合下都更为适用。那么,如何实现Word转PDF呢?本文将介绍几种常用的方法,帮…

Aker(安碁科技)晶振产品应用和选型

一、石英晶体振荡器简介 在电子电路系统中,特定的动作需要严格按照一定的顺序进行,以确保数据被正确处理和操作,时钟信号就成了系统工作的重要引导者。而且在多模块复杂电路系统中,为了确保不同功能模块能协调一致地工作&#xf…

怎么用微信小程序实现远程控制台球室

怎么用微信小程序实现远程控制台球室呢? 本文描述了使用微信小程序调用HTTP接口,实现控制台球室,控制球台上方的照明灯,单台设备可控制多张球台的照明灯。 可选用产品:可根据实际场景需求,选择对应的规格 …