MySQL Group Replication的安装部署
一、简介
这次给大家介绍下MySQL官方最新版本5.7.17中GA的新功能 Group Replication 。
但是,在不同服务器上并发执行的事务之间可能存在冲突。通过在称为认证的过程中检查两个不同的并发事务的写集合来检测这样的冲突。如果在不同的服务器上执行的两个并发事务更新同一行,则会出现冲突。解析过程指出,首先订购的事务在所有服务器上提交,而顺序第二次中止的事务将在源服务器上回滚,并由组中的其他服务器删除。这实际上是一个分布式的第一个提交赢的规则。
MySQL组复制协议
最后,组复制是一种无共享复制方案,其中每个服务器都有自己的整个数据副本。
上图描述了MySQL组复制协议,并通过将其与MySQL复制(或甚至MySQL半同步复制)进行比较,您可以看到一些差异。注意,为了清楚起见,这个图片中缺少一些基本的共识和Paxos相关消息。
介绍就到这,本文中我将一步一步的安装部署group_replication的三个节点,并让你看到它的功能和特性,如果看完全文,你十分的感兴趣的话,可以去mysql的Group Replication主页去查看更详细的信息。
二、正式部署
1. 环境介绍
basedir = /usr/local/mysql
(PS: 这点还是要吐槽一下的,mysql官方basedir如果不在这个目录的话,mysql.server也不好使,这个实验也不成功,我们还是勉强先放在这)
端口号 | 数据及日志目录 | Group_Replication通讯端口 |
3306 | /data/mysql/mysql_3306/{data,logs,tmp} | 33061 |
3307 | /data/mysql/mysql_3307/{data,logs,tmp} | 33062 |
3308 | /data/mysql/mysql_3308/{data,logs,tmp} | 33063 |
2. 初始化
①、下载and解压缩,并把mysql放到指定地方(标准目录: /usr/local/mysql)
cd /opt/
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.-linux-glibc2.-x86_64 /usr/local/mysql
②、 创建数据库需要的数据、日志和临时目录并赋权:
mkdir -p /data/mysql/{mysql_3306,mysql_3307,mysql_3308}/{data,logs,tmp}
chown -R mysql.mysql /data/mysql/
3. 初始化
安装机器: 192.168.0.162 (单机多实例安装)
配置文件说明:
端口号 | 配置文件 |
3306 | /data/mysql/mysql_3306/my3306.cnf |
3307 | /data/mysql/mysql_3306/my3307.cnf |
3308 | /data/mysql/mysql_3306/my3308.cnf |
[client]
port =
socket = /tmp/mysql3306.sock
[mysql]
prompt = mysql [\d]>
default_character_set = utf8
no-auto-rehash
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql_3306/data
port =
socket = /tmp/mysql3306.sock
event_scheduler =
tmpdir=/data/mysql/mysql_3306/tmp
#timeout
interactive_timeout =
wait_timeout =
#character set
character-set-server = utf8
open_files_limit =
max_connections =
max_connect_errors =
#
explicit_defaults_for_timestamp
#logs
log-output=file
slow_query_log =
slow_query_log_file = slow.log
log-error = error.log
log_error_verbosity=
pid-file = mysql.pid
long_query_time =
#log-slow-admin-statements =
#log-queries-not-using-indexes =
log-slow-slave-statements =
#binlog
binlog_format = row
server-id =
log-bin = /data/mysql/mysql_3306/logs/mysql-bin
binlog_cache_size = 1M
max_binlog_size = 200M
max_binlog_cache_size = 2G
sync_binlog =
expire_logs_days = #group replication
server_id=
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="13855fca-d2ab-11e6-8f37-005056b8286c"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.0.162:33061"
loose-group_replication_group_seeds= "192.168.0.162:33061,192.168.0.162:33071,192.168.0.162:33081"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=off
loose-group_replication_enforce_update_everywhere_checks=on
#relay log
skip_slave_start =
max_relay_log_size = 500M
relay_log_purge =
relay_log_recovery =
#slave-skip-errors=,,
#buffers & cache
table_open_cache =
table_definition_cache =
table_open_cache =
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size =
query_cache_size =
query_cache_type =
query_cache_limit = 256K
query_cache_min_res_unit =
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
#innodb
innodb_buffer_pool_size = 500M
innodb_buffer_pool_instances =
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_file_per_table =
innodb_rollback_on_timeout
innodb_status_file =
innodb_io_capacity =
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
其中比较重要的地方,也是安装Group_replication必须要有的配置项,需要注意一下:
#group replication
server_id=
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="13855fca-d2ab-11e6-8f37-005056b8286c"
loose-group_replication_start_on_boot=off
loose-group_replication_local_address= "192.168.0.162:33061"
loose-group_replication_group_seeds= "192.168.0.162:33061,192.168.0.162:33071,192.168.0.162:33081"
loose-group_replication_bootstrap_group= off loose-group_replication_single_primary_mode=off
loose-group_replication_enforce_update_everywhere_checks=on
在这里有一些技术细节要说明一下:
上面的三个配置文件省略了所有不必要的配置项、但是看起来还是有点多、这些都是mgr环境要求的。
server_id 每个实例都要不要样
loose-group_replication_group_name:为mgr高可用组起一个名字,必须是有效的UUID。在二进制日志中为组复制事件设置GTID时,将在内部使用此UUID。使用SELECT UUID()
生成一个UUID。
loose-group_replication_local_address:mgr各实例之前都是要进行通信的、这个配置项设置的就是本实例所监听的ip:端口
loose-group_replication_group_seeds:各mgr实例所监听的ip:端口信息
其他配置参数,请参考官方文档:
https://dev.mysql.com/doc/refman/5.7/en/group-replication-configuring-instances.html
4. 启动Group_replication第一个节点
初始化3306实例:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my3306.cnf --initialize-insecure
启动3306实例:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my3306.cnf &
进入mysql进行change操作:
/usr/local/mysql/bin/mysql -u root -S /tmp/mysql3306.sock
mysql> SET SQL_LOG_BIN=;
mysql> CREATE USER rpl_user@'%';
mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
mysql> SET SQL_LOG_BIN=;
mysql> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> SHOW PLUGINS;
+----------------------------+----------+--------------------+----------------------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+----------------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
|... ... ... |
| group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL |
+----------------------------+----------+--------------------+----------------------+---------+
mysql> SET GLOBAL group_replication_bootstrap_group=ON; #只在第一个节点使用
mysql> START GROUP_REPLICATION;
确认节点加入情况:
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 68ce93ca-d292-11e6-bdf9-005056b8286c | localhost.localdomain | | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
rows in set (0.00 sec)
mysql> create database boom;
mysql> use boom;
mysql> create table boomballa(id int not null,name varchar(),primary key(id));
mysql> insert into boomballa(id,name) values(,'boomballa.top');
mysql> insert into boomballa(id,name) values(,'myblog');
查看端口是否启动
root@ubuntu:/data/mysql/mysql_3306# netstat -anpt | grep 33061
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
5. 启动Group_replication第二个节点
复制配置文件:
# 复制配置文件
cd /data/mysql/mysql_3307/
cp ../mysql_3306/my3306.cnf my3307.cnf # 编辑配置文件
vim my3307.cnf #将替换3306为3307
loose-group_replication_local_address= "192.168.0.162:33071"
loose-group_replication_group_seeds= "192.168.0.162:33061,192.168.0.162:33071,192.168.0.162:33081"
注意:loose-group_replication_local_address配置参数,必须要在loose-group_replication_group_seeds里面!
否则会出现3092错误
初始化并启动实例:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my3307.cnf --initialize-insecure
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my3307.cnf &
mysql> SET SQL_LOG_BIN=;
mysql> CREATE USER rpl_user@'%';
mysql> GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
mysql> SET SQL_LOG_BIN=;
mysql> CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
mysql> START GROUP_REPLICATION;
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 5aaa8529-d296-11e6-a7be-005056b8286c | localhost.localdomain | | ONLINE |
| group_replication_applier | 68ce93ca-d292-11e6-bdf9-005056b8286c | localhost.localdomain | | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
rows in set (0.00 sec)
root@ubuntu:/data/mysql/mysql_3306# netstat -anpt | grep 33061
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
6. 第三节点安装配置
这里省略了,参考第二个节点。注意:替换端口为3308
安装好了以后的状态应该是(三节点上查询结果都是如此):
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
| group_replication_applier | 5aaa8529-d296-11e6-a7be-005056b8286c | localhost.localdomain | | ONLINE |
| group_replication_applier | 68ce93ca-d292-11e6-bdf9-005056b8286c | localhost.localdomain | | ONLINE |
| group_replication_applier | af93afd1-d297-11e6-b8e9-005056b8286c | localhost.localdomain | | ONLINE |
+---------------------------+--------------------------------------+-----------------------+-------------+--------------+
rows in set (0.00 sec) mysql> use boom
Database changed
mysql> select * from boomballa;
+----+---------------+
| id | name |
+----+---------------+
| | boomballa.top |
| | myblog |
+----+---------------+
rows in set (0.00 sec)
确认一下:
[root@localhost ~]# echo "select * from boom.boomballa;"|/usr/local/mysql/bin/mysql -S /tmp/mysql3306.sock
id name
boomballa.top
myblog
[root@localhost ~]# echo "select * from boom.boomballa;"|/usr/local/mysql/bin/mysql -S /tmp/mysql3307.sock
id name
boomballa.top
myblog
[root@localhost ~]# echo "select * from boom.boomballa;"|/usr/local/mysql/bin/mysql -S /tmp/mysql3308.sock
id name
boomballa.top
myblog
三、测试
查看mysql进程
root@ubuntu:/data/mysql/mysql_3306# ps -aux | grep mysql
mysql 0.1 6.3 pts/ Sl : : /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3306/my3306.cnf
mysql 0.1 6.2 pts/ Sl : : /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my3307.cnf
mysql 0.2 6.2 pts/ Sl : : /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3308/my3308.cnf
root 0.0 0.0 pts/ S+ : : grep --color=auto mysql
设置第一个mysql实例密码,设置密码为root
/usr/local/mysql/bin/mysqladmin -u root -S /tmp/mysql3306.sock -p password root
授权root用户远程连接
/usr/local/mysql/bin/mysql -u root -S /tmp/mysql3306.sock -proot
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql> flush privileges;
测试其他端口,比如:3307和3308,也应该是可以查看表数据!
在3306修改表数据,在3307查看数据,会立即同步的
关闭其中一个节点
关闭3308的进程
kill
再次查看3306和3307表数据,是ok的。
在3306修改表数据,3307也是会同步的
启动3308实例
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql_3308/my3308.cnf &
查看3308数据,发现数据没有更新过来
进入到3308,开启GROUP_REPLICATION
/usr/local/mysql/bin/mysql -u root -S /tmp/mysql3308.sock -proot
mysql> START GROUP_REPLICATION;
MySQL Group Replication的安装部署的更多相关文章
- mysql group replication 安装&配置详解
一.原起: 之前也有写过mysql-group-replication (mgr) 相关的文章.那时也没有什么特别的动力要写好它.主要是因为在 mysql-5.7.20 之前的版本的mgr都有着各种各 ...
- MySQL Group Replication 动态添加成员节点
前提: MySQL GR 3节点(node1.node2.node3)部署成功,模式定为多主模式,单主模式也是一样的处理. 在线修改已有GR节点配置 分别登陆node1.node2.node3,执行以 ...
- MySQL双主+keeplived安装部署说明
MySQL双主+keeplived安装部署说明 一.环境介绍 1.1.规划 序号 类别 版本 主机名 IP 端口 备注 1 OS CentOS release 6.9 (Final) (minimal ...
- Mysql 5.7 基于组复制(MySQL Group Replication) - 运维小结
之前介绍了Mysq主从同步的异步复制(默认模式).半同步复制.基于GTID复制.基于组提交和并行复制 (解决同步延迟),下面简单说下Mysql基于组复制(MySQL Group Replication ...
- Mysql Group Replication 简介及单主模式组复制配置【转】
一 Mysql Group Replication简介 Mysql Group Replication(MGR)是一个全新的高可用和高扩张的MySQL集群服务. 高一致性,基于原生复制及p ...
- MySQL Group Replication 技术点
mysql group replication,组复制,提供了多写(multi-master update)的特性,增强了原有的mysql的高可用架构.mysql group replication基 ...
- mysql group replication 主节点宕机恢复
一.mysql group replication 生来就要面对两个问题: 一.主节点宕机如何恢复. 二.多数节点离线的情况下.余下节点如何继续承载业务. 在这里我们只讨论第一个问题.也就是说当主结点 ...
- mysql group replication观点及实践
一:个人看法 Mysql Group Replication 随着5.7发布3年了.作为技术爱好者.mgr 是继 oracle database rac 之后. 又一个“真正” 的群集,怎么做到“ ...
- MySQL Group Replication配置
MySQL Group Replication简述 MySQL 组复制实现了基于复制协议的多主更新(单主模式). 复制组由多个 server成员构成,并且组中的每个 server 成员可以独立地执行事 ...
随机推荐
- 66、Spark Streaming:数据处理原理剖析与源码分析(block与batch关系透彻解析)
一.数据处理原理剖析 每隔我们设置的batch interval 的time,就去找ReceiverTracker,将其中的,从上次划分batch的时间,到目前为止的这个batch interval ...
- 【luoguP1414]】又是毕业季II
题目链接 \(solution\) 暴力求每个数有多少个倍数,从大到小,数\(i\)的倍数有\(f_i\)个,那么选\(1\)~\(f_i\)个同学的答案可以为\(i\),取第一次更新的答案最大 #i ...
- ICEM-两管相贯
原视频下载地址:https://pan.baidu.com/s/1qYe0AzM 密码: tmd5
- Maven中使用<version>LATEST</version>自动依赖最新版本引发的问题
今天在打包项目的过程中出现了编译问题,奇怪的是这个项目已经好久没有修改过了,报错如下. 找不到符号 [ERROR] 符号: 方法 intent(java.lang.String) [ERROR] 位置 ...
- python练习:寒冰猴子狐狸,猫狗咬架
python练习:寒冰猴子狐狸,猫狗咬架 一,寒冰猴子狐狸 class Person: def __init__(self, na, gen, age, fig): self.name = na se ...
- 清理收藏夹中的CSS
1.去掉元素的属性, 例如宽度 #blog-calendar { width: initial !important; }
- Eclipse创建Maven父子项目
Eclipse创建Maven父子项目 - 木头若愚 - CSDN博客https://blog.csdn.net/jay_1989/article/details/53906995 创建maven项目是 ...
- windows系统下同时安装mysql5.5和8.0.11
前提:电脑已安装5.5,增安装8.0.11 zip版本 1.官网下载mysql10.8.0.11 —找到mysql community server 为下载页面URL:https://dev.mysq ...
- layui自定义模块
想把用了layui的页面的一些函数抽取公用,直接引入外部js不可行,只能用layui的模块功能.官网没有说明,但模块名必须和文件名一致 新建yananmod.js文件,内容如下: layui.defi ...
- 【tensorflow基础】Tensorpack-API
安装 pip install tensorpack 使用 参考 1. Tensorpack: 2. Tensorpack,一个基于TensorFlow的神经网络训练界面,源码包含很多示例: 完