Mysql之MGR高可用实战案例
MGR高可用实战案例
1、环境准备
node1 rocky8.6 10.0.0.8
node2 rocky8.6 10.0.0.18
node3 rocky8.6 10.0.0.28
2、所有节点更改主机名和名称解析
hostnamectl set-hostname node1.wang.org
cat >> /etc/hosts <<EOF
10.0.0.8 node1.wang.org
10.0.0.18 node2.wang.org
10.0.0.28 node3.wang.org
EOF
yum -y install mysql-server
3、所有节点修改配置文件
[root@node1 ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=8
gtid_mode=ON
enforce_gtid_consistency=ON
default_authentication_plugin=mysql_native_password
binlog_checksum=NONE
loose-group_replication_group_name="ef0143b7-94df-40ee-b798-95849678a271"
loose-group_replication_start_on_boot=OFF
loose-group_replication_local_address="10.0.0.8:24901"
loose-group_replication_group_seeds="10.0.0.8:24901,10.0.0.18:24901,10.0.0.28:24901"
loose-group_replication_bootstrap_group=OFF
loose-group_replication_recovery_use_ssl=ON
[root@node2 ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=18
gtid_mode=ON
enforce_gtid_consistency=ON
default_authentication_plugin=mysql_native_password
binlog_checksum=NONE
loose-group_replication_group_name="ef0143b7-94df-40ee-b798-95849678a271"
loose-group_replication_start_on_boot=OFF
loose-group_replication_local_address="10.0.0.18:24901"
loose-group_replication_group_seeds="10.0.0.8:24901,10.0.0.18:24901,10.0.0.28:24901"
loose-group_replication_bootstrap_group=OFF
loose-group_replication_recovery_use_ssl=ON
[root@node3 ~]# vim /etc/my.cnf.d/mysql-server.cnf
[mysqld]
server-id=28
gtid_mode=ON
enforce_gtid_consistency=ON
default_authentication_plugin=mysql_native_password
binlog_checksum=NONE
loose-group_replication_group_name="ef0143b7-94df-40ee-b798-95849678a271"
loose-group_replication_start_on_boot=OFF
loose-group_replication_local_address="10.0.0.28:24901"
loose-group_replication_group_seeds="10.0.0.8:24901,10.0.0.18:24901,10.0.0.28:24901"
loose-group_replication_bootstrap_group=OFF
loose-group_replication_recovery_use_ssl=ON
4、在所有主机创建复制用户 并安装插件
[root@node1 ~]# mysql
mysql> set sql_log_bin=0;
mysql> create user repluser@'%' identified by '123456'
mysql> grant replication slave on *.* to repluser@'%';
mysql> flush privileges;
mysql> set sql_log_bin=1;
mysql> install plugin group_replication soname 'group_replication.so';
mysql> select * from information_schema.plugins where plugin_name='group_replication'\G
*************************** 1. row ***************************
PLUGIN_NAME: group_replication
PLUGIN_VERSION: 1.1
PLUGIN_STATUS: ACTIVE
PLUGIN_TYPE: GROUP REPLICATION
PLUGIN_TYPE_VERSION: 1.4
PLUGIN_LIBRARY: group_replication.so
PLUGIN_LIBRARY_VERSION: 1.10
PLUGIN_AUTHOR: Oracle Corporation
PLUGIN_DESCRIPTION: Group Replication (1.1.0)
PLUGIN_LICENSE: GPL
LOAD_OPTION: ON
# node2、node3步骤同node1
5、启用第一个节点Primary (引导启动)
[root@node1 ~]# mysql
mysql> set global group_replication_bootstrap_group=ON;
mysql> start group_replication;
mysql> set global group_replication_bootstrap_group=OFF;
mysql> mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 81df7810-2d21-11ed-a76f-000c2942b4d3 | node1.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
1 row in set (0.00 sec)
6、启用剩余的所有节点Secondary
[root@node2 ~]# mysql
mysql> change master to master_user='repluser',master_password='123456' for channel 'group_replication_recovery';
mysql> start group_replication;
[root@node3 ~]# mysql
mysql> change master to master_user='repluser',master_password='123456' for channel 'group_replication_recovery';
mysql> start group_replication;
6-1、在所有节点都可以查看到信息:
mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 81df7810-2d21-11ed-a76f-000c2942b4d3 | node1.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
| group_replication_applier | a4f0d915-2d22-11ed-a541-000c29720654 | node2.wang.org | 3306 | ONLINE | SECONDARY | 8.0.26 |
| group_replication_applier | a8259348-2d22-11ed-8440-000c295d78d1 | node3.wang.org | 3306 | ONLINE | SECONDARY | 8.0.26 |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
3 rows in set (0.00 sec)
6-2、测试
# 主节点新增数据库,其他节点查看
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db1 |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
[root@node1 ~]# systemctl stop mysqld.service #停掉一个服务
[root@node2 ~]# mysql
mysql> select * from performance_schema.replication_group_members; #可以看到主切换到了node2上
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| group_replication_applier | a4f0d915-2d22-11ed-a541-000c29720654 | node2.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
| group_replication_applier | a8259348-2d22-11ed-8440-000c295d78d1 | node3.wang.org | 3306 | ONLINE | SECONDARY | 8.0.26 |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
[root@node1 ~]# systemctl start mysqld.service #再恢复服务
[root@node1 ~]# mysql
mysql> change master to master_user='repluser',master_password='123456' for channel 'group_replication_recovery';
mysql> start group_replication;
mysql> mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 81df7810-2d21-11ed-a76f-000c2942b4d3 | node1.wang.org | 3306 | ONLINE | SECONDARY | 8.0.26 |
| group_replication_applier | a4f0d915-2d22-11ed-a541-000c29720654 | node2.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
| group_replication_applier | a8259348-2d22-11ed-8440-000c295d78d1 | node3.wang.org | 3306 | ONLINE | SECONDARY | 8.0.26 |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
7、单主切换多主模式
mysql> select group_replication_switch_to_multi_primary_mode(); #任意节点都可执行
+--------------------------------------------------+
| group_replication_switch_to_multi_primary_mode() |
+--------------------------------------------------+
| Mode switched to multi-primary successfully. |
+--------------------------------------------------+
1 row in set (1.02 sec)
mysql> select * from performance_schema.replication_group_members; #查看切换状态
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 81df7810-2d21-11ed-a76f-000c2942b4d3 | node1.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
| group_replication_applier | a4f0d915-2d22-11ed-a541-000c29720654 | node2.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
| group_replication_applier | a8259348-2d22-11ed-8440-000c295d78d1 | node3.wang.org | 3306 | ONLINE | PRIMARY | 8.0.26 |
+---------------------------+--------------------------------------+----------------+-------------+--------------+-------------+----------------+
mysql> show variables like '%read_only%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| super_read_only | OFF |
| transaction_read_only | OFF |
+-----------------------+-------+
4 rows in set (0.07 sec)
8、多主模式切换单主模式
mysql> select group_replication_switch_to_single_primary_mode(); #任意节点都可执行
Mysql之MGR高可用实战案例的更多相关文章
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- MySQL主主高可用(keepalive)
2台新的虚拟机172.16.1.1.172.16.1.2 (配置yum源 ) 安装数据库服务 其中 172.16.1.1.172.16.1.2运行数据库服务并设置数据库管理员从本机登录的密码是xzw ...
- LVS集群和Keepalived高可用实战
第四十章LVS集群和Keepalived高可用实战 一.ARP协议 1.概念 地址解析协议,即ARP(AddressResolutionProtocol),是根据IP地址获取物理MAC地址的一个TCP ...
- MySQL数据库的优化(下)MySQL数据库的高可用架构方案
MySQL数据库的优化(下)MySQL数据库的高可用架构方案 2011-03-09 08:53 抚琴煮酒 51CTO 字号:T | T 在上一篇MySQL数据库的优化中,我们跟随笔者学习了单机MySQ ...
- mysql数据库的高可用方法总结
高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一 些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无 ...
- 浅谈mysql主从复制的高可用解决方案
1.熟悉几个组件(部分摘自网络)1.1.drbd —— DRBD(Distributed Replicated Block Device),DRBD号称是 "网络 RAID" ...
- MySQL集群(四)之keepalived实现mysql双主高可用
前面大家介绍了主从.主主复制以及他们的中间件mysql-proxy的使用,这一篇给大家介绍的是keepalived的搭建与使用! 一.keepalived简介 1.1.keepalived介绍 Kee ...
- MySQL系列:高可用架构之MHA
前言 从11年毕业到现在,工作也好些年头,入坑mysql也有近四年的时间,也捣鼓过像mongodb.redis.cassandra.neo4j等Nosql数据库.其实一直想写博客分享下工作上的零零碎碎 ...
- Flume 高可用配置案例+load balance负载均衡+ 案例:日志的采集及汇总
高可用配置案例 (一).failover故障转移 在完成单点的Flume NG搭建后,下面我们搭建一个高可用的Flume NG集群,架构图如下所示: (1)节点分配 Flume的Agent和Colle ...
随机推荐
- flutter系列之:widgets,构成flutter的基石
目录 简介 StatelessWidget和StatefulWidget StatelessWidget详解 StatefulWidget详解 总结 简介 flutter中所有的组件都是由widget ...
- Spring 14: Spring + MyBatis初步整合开发
SM整合步骤 预期项目结构 新建数据库和数据表 springuser.sql脚本如下 create database ssm; use ssm; create table users( userid ...
- kingbaseES R3 集群配置 SSL
案例说明: 本测试是在非生产环境下,在官方没有明确声明支持KingbaseCluster使用ssl的前提下,建议只能在测试环境使用,避免生产环境下直接使用. 数据库版本: TEST=# selec ...
- angr原理与实践(二)—— 各类图的生成(CFG CG ACFG DDG等)
本文系原创,转载请说明出处 Please Subscribe Wechat Official Account:信安科研人,获取更多的原创安全资讯 上一篇文章介绍了angr的原理,自此篇文章开始, ...
- 树莓派学习笔记 (1) - 安装&初始设置
1. 设备 Raspberry Pi 4B MicorSD card (tf 卡) Windows 10 电脑 Android 手机 2. 烧录系统 利用官网提供的 Raspberry Pi Imag ...
- dotnet 为大型应用接入 ApplicationStartupManager 启动流程框架
对于大型的应用软件,特别是客户端应用软件,应用启动过程中,需要执行大量的逻辑,包括各个模块的初始化和注册等等逻辑.大型应用软件的启动过程都是非常复杂的,而客户端应用软件是对应用的启动性能有所要求的,不 ...
- github配置添加SSH秘钥
在 github 上添加 SSH key 的步骤: 1.首先需要检查你电脑是否已经有 SSH key 运行 git Bash 客户端,输入如下代码: $ cd ~/.ssh $ ls 这两个命令就是检 ...
- AQS:Java 中悲观锁的底层实现机制
介绍 AQS AQS(AbstractQueuedSynchronizer)是 Java 并发包中,实现各种同步组件的基础.比如 各种锁:ReentrantLock.ReadWriteLock.Sta ...
- Kubernetes里的Service是如何工作的
Service是Kubernetes接入层的一种抽象资源,它为我们提供了一种固定的.统一的访问接口地址和负载均衡能力,这时可能会想到,当时使用docker-compose的时候,不存在Service概 ...
- 添加 K8S CPU limit 会降低服务性能
文章转载自:https://mp.weixin.qq.com/s/cR6MpQu-n1cwMbXmVaXqzQ