MySQL-group-replication 配置步骤(推荐)
作者:jingxian 发布时间:2024-01-17 20:51:36
标签:group,replication,mysql
MySQL-Group-Replication 是mysql-5.7.17版本开发出来的新特性;它在master-slave 之间实现了强一致性,
但是就目前来说主要是性能不太好。
【1】确定当前的mysql数据库版本为5.7.17及以上
/usr/local/mysql/bin/mysqld --version
/usr/local/mysql/bin/mysqld Ver 5.7.17 for linux-glibc2.5 on x86_64 (MySQL Community Server (GPL))
【2】实验环境为一台主机上安装3台mysql,它们三个组成一个group-replication 组
/tmp/4406.cnf 内容如下:
[mysqld]
####: for global
user =jianglexing # mysql
basedir =/usr/local/mysql # /usr/local/mysql/
datadir =/tmp/4406/ # /usr/local/mysql/data
server_id =4406 # 0
port =4406 # 3306
socket =/tmp/4406/mysql.sock # /tmp/mysql.sock
auto_increment_increment =1 # 1
auto_increment_offset =1 # 1
lower_case_table_names =1 # 0
secure_file_priv = # null
####: for binlog
binlog_format =row # row
log_bin =mysql-bin # off
binlog_rows_query_log_events =on # off
log_slave_updates =on # off
expire_logs_days =4 # 0
binlog_cache_size =32768 # 32768(32k)
binlog_checksum =none # CRC32
sync_binlog =1 # 1
####: for error-log
log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err
####: for slow query log
####: for gtid
gtid_mode =on # off
enforce_gtid_consistency =on # off
####: for replication
master_info_repository =table # file
relay_log_info_repository =table # file
####: for group replication
transaction_write_set_extraction =XXHASH64 # off
loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" #
loose-group_replication_start_on_boot =off # off
loose-group_replication_local_address ="127.0.0.1:24901" #
loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
loose-group_replication_bootstrap_group =off # off
####: for innodb
default_storage_engine =innodb # innodb
default_tmp_storage_engine =innodb # innodb
innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend
innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend
innodb_log_group_home_dir =./ # ./
innodb_log_files_in_group =2 # 2
innodb_log_file_size =48M # 50331648(48M)
innodb_file_format =Barracuda # Barracuda
innodb_file_per_table =on # on
innodb_page_size =16k # 16384(16k)
innodb_thread_concurrency =0 # 0
innodb_read_io_threads =4 # 4
innodb_write_io_threads =4 # 4
innodb_purge_threads =4 # 4
innodb_print_all_deadlocks =on # off
innodb_deadlock_detect =on # on
innodb_lock_wait_timeout =50 # 50
innodb_spin_wait_delay =6 # 6
innodb_autoinc_lock_mode =2 # 1
innodb_stats_persistent =on # on
innodb_stats_persistent_sample_pages =20 # 20
innodb_adaptive_hash_index =on # on
innodb_change_buffering =all # all
innodb_change_buffer_max_size =25 # 25
innodb_flush_neighbors =1 # 1
innodb_flush_method =O_DIRECT #
innodb_doublewrite =on # on
innodb_log_buffer_size =16M # 16777216(16M)
innodb_flush_log_at_timeout =1 # 1
innodb_flush_log_at_trx_commit =1 # 1
autocommit =1 # 1
[client]
auto-rehash
/tmp/5506.cnf 内容如下:
[mysqld]
####: for global
user =jianglexing # mysql
basedir =/usr/local/mysql # /usr/local/mysql/
datadir =/tmp/5506 # /usr/local/mysql/data
server_id =5506 # 0
port =5506 # 3306
socket =/tmp/5506/mysql.sock # /tmp/mysql.sock
auto_increment_increment =1 # 1
auto_increment_offset =1 # 1
lower_case_table_names =1 # 0
secure_file_priv = # null
####: for binlog
binlog_format =row # row
log_bin =mysql-bin # off
binlog_rows_query_log_events =on # off
log_slave_updates =on # off
expire_logs_days =4 # 0
binlog_cache_size =32768 # 32768(32k)
binlog_checksum =none # CRC32
sync_binlog =1 # 1
####: for error-log
log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err
####: for slow query log
####: for gtid
gtid_mode =on # off
enforce_gtid_consistency =on # off
####: for replication
master_info_repository =table # file
relay_log_info_repository =table # file
####: for group replication
transaction_write_set_extraction =XXHASH64 # off
loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" #
loose-group_replication_start_on_boot =off # off
loose-group_replication_local_address ="127.0.0.1:24902" #
loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
loose-group_replication_bootstrap_group =off # off
####: for innodb
default_storage_engine =innodb # innodb
default_tmp_storage_engine =innodb # innodb
innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend
innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend
innodb_log_group_home_dir =./ # ./
innodb_log_files_in_group =2 # 2
innodb_log_file_size =48M # 50331648(48M)
innodb_file_format =Barracuda # Barracuda
innodb_file_per_table =on # on
innodb_page_size =16k # 16384(16k)
innodb_thread_concurrency =0 # 0
innodb_read_io_threads =4 # 4
innodb_write_io_threads =4 # 4
innodb_purge_threads =4 # 4
innodb_print_all_deadlocks =on # off
innodb_deadlock_detect =on # on
innodb_lock_wait_timeout =50 # 50
innodb_spin_wait_delay =6 # 6
innodb_autoinc_lock_mode =2 # 1
innodb_stats_persistent =on # on
innodb_stats_persistent_sample_pages =20 # 20
innodb_adaptive_hash_index =on # on
innodb_change_buffering =all # all
innodb_change_buffer_max_size =25 # 25
innodb_flush_neighbors =1 # 1
innodb_flush_method =O_DIRECT #
innodb_doublewrite =on # on
innodb_log_buffer_size =16M # 16777216(16M)
innodb_flush_log_at_timeout =1 # 1
innodb_flush_log_at_trx_commit =1 # 1
autocommit =1 # 1
/tmp/6606.cnf 内容如下:
[mysqld]
####: for global
user =jianglexing # mysql
basedir =/usr/local/mysql # /usr/local/mysql/
datadir =/tmp/6606/ # /usr/local/mysql/data
server_id =6606 # 0
port =6606 # 3306
socket =/tmp/6606/mysql.sock # /tmp/mysql.sock
auto_increment_increment =1 # 1
auto_increment_offset =1 # 1
lower_case_table_names =1 # 0
secure_file_priv = # null
####: for binlog
binlog_format =row # row
log_bin =mysql-bin # off
binlog_rows_query_log_events =on # off
log_slave_updates =on # off
expire_logs_days =4 # 0
binlog_cache_size =32768 # 32768(32k)
binlog_checksum =none # CRC32
sync_binlog =1 # 1
####: for error-log
log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err
####: for slow query log
####: for gtid
gtid_mode =on # off
enforce_gtid_consistency =on # off
####: for replication
master_info_repository =table # file
relay_log_info_repository =table # file
####: for group replication
transaction_write_set_extraction =XXHASH64 # off
loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" #
loose-group_replication_start_on_boot =off # off
loose-group_replication_local_address ="127.0.0.1:24903" #
loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
loose-group_replication_bootstrap_group =off # off
####: for innodb
default_storage_engine =innodb # innodb
default_tmp_storage_engine =innodb # innodb
innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend
innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend
innodb_log_group_home_dir =./ # ./
innodb_log_files_in_group =2 # 2
innodb_log_file_size =48M # 50331648(48M)
innodb_file_format =Barracuda # Barracuda
innodb_file_per_table =on # on
innodb_page_size =16k # 16384(16k)
innodb_thread_concurrency =0 # 0
innodb_read_io_threads =4 # 4
innodb_write_io_threads =4 # 4
innodb_purge_threads =4 # 4
innodb_print_all_deadlocks =on # off
innodb_deadlock_detect =on # on
innodb_lock_wait_timeout =50 # 50
innodb_spin_wait_delay =6 # 6
innodb_autoinc_lock_mode =2 # 1
innodb_stats_persistent =on # on
innodb_stats_persistent_sample_pages =20 # 20
innodb_adaptive_hash_index =on # on
innodb_change_buffering =all # all
innodb_change_buffer_max_size =25 # 25
innodb_flush_neighbors =1 # 1
innodb_flush_method =O_DIRECT #
innodb_doublewrite =on # on
innodb_log_buffer_size =16M # 16777216(16M)
innodb_flush_log_at_timeout =1 # 1
innodb_flush_log_at_trx_commit =1 # 1
autocommit =1 # 1
【3】初始化三个数据库实例
cd /usr/local/mysql/
./bin/mysqld --defautls-file=/tmp/4406.cnf --datadir=/tmp/4406 --initialize-insecrue
./bin/mysqld --defautls-file=/tmp/5506.cnf --datadir=/tmp/5506 --initialize-insecrue
./bin/mysqld --defautls-file=/tmp/6606.cnf --datadir=/tmp/6606 --initialize-insecrue
【4】配置group-replication 的初始实例
/usr/local/mysql/bin/mysqld --defaults-file=/tmp/4406.cnf &
mysql -h127.0.0.1 -uroot -P4406
-- 增加用户
set sql_log_bin=0;
create user rpl_user@'%' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'%';
create user rpl_user@'127.0.0.1' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'127.0.0.1';
create user rpl_user@'localhost' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'localhost';
set sql_log_bin=1;
-- 增加复制凭证
change master to
master_user='rpl_user',
master_password='123456'
for channel 'group_replication_recovery';
-- 安装组复制物件
install plugin group_replication soname 'group_replication.so';
-- 启动组复制
set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;
【5】5506 实例的配置过程如下:
/usr/local/mysql/bin/mysqld --defaults-file=/tmp/5506.cnf &
mysql -h127.0.0.1 -uroot -P5506
-- 增加用户
set sql_log_bin=0;
create user rpl_user@'%' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'%';
create user rpl_user@'127.0.0.1' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'127.0.0.1';
create user rpl_user@'localhost' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'localhost';
set sql_log_bin=1;
-- 增加复制凭证
change master to
master_user='rpl_user',
master_password='123456'
for channel 'group_replication_recovery';
-- 安装组复制物件
install plugin group_replication soname 'group_replication.so';
-- 启动组复制
start group_replication; # 注意这里不是初始化了,只要加入就行
【6】6606 实例的操作与5506的操作一样,这样group replication 的配置就完成了。


猜你喜欢
- 在本文中,我们向您介绍一些提示和技巧,以帮助您更快地编写代码Python的可读性和设计简单性是其广受欢迎的两个主要原因。一些常见的Pytho
- python 字典操作提取key,value dictionaryName[key] = value1.为字典增加一项 2.访问字典中的值
- 一、单个文件打包1.1 简单打包例如现在有一个main.py文件内容如下import osprint("hello world&q
- 当Python执行import语句时,它会在一些路径中搜索Python模块和扩展模块。可以通过sys.path查看这些路径,比如:>&
- 前言在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的。而MySql数据库提供了多种存储引擎。
- urllib的基本用法urllib库的基本组成利用最简单的urlopen方法爬取网页html利用Request方法构建headers模拟浏览
- ThinkPHP提供的视图查询应用功能十分强大,用户利用视图查询功能可以将多个数据表的字段内容按需要进行指定和筛选,组织成一个基于这些数据表
- 在CSS中我们会经常要用到“清除浮动”Clear,比较典型的就是clear:both;CSS手册上是这样说明的:该属性的值指出了不允许有浮动
- 学过 Python 的朋友应该都知道 f-strings 是用来非常方便的格式化输出的,觉得它的使用方法无外乎就是 print(f'
- 最近自己在搭建一个基于webpack的react项目,遇到关于output.publicPath和webpack-dev-server中pu
- 首先创建Profile应用python manage.py startapp profilesprofiles/models.py# -*-
- 前言在制作论文插图时,有时要求将图片的局部放大来展示细节内容,同时将放大图拼接在原图上以方便观察对比。当然直接利用电脑自带的画图软件或者别的
- vue的传值及赋值作为Vue非资深的学习者,在工作中使用vue的时候还是遇见的很多所谓的坑,打算总结一下;就在昨天PM找到我,给我看了一个b
- 本文实例讲述了Python实现的ftp服务器功能。分享给大家供大家参考,具体如下:python 具备强大的网络编程功能,而且代码简介,用简单
- 闭包函数什么是闭包函数如果内函数使用了外函数的局部变量,并且外函数把内函数返回出来的过程叫做闭包,里面的内函数是闭包函数。# 外函数 out
- 一、scrapy1.1 概述Scrapy,Python开发的一个快速、高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构
- 我是新手学习如何管理和导航MySQL数据库和表是要掌握的首要任务之一,下面的内容将主要对MySQL的数据库和表的一些常用命令进行总结,一些我
- 1.首先在Xshell上通过conda创建新的虚拟环境2.此时在 /home/y210101004/.conda/envs下多了刚
- golang中默认使用一个CPU,这时程序无法并发,只能是并发。因为始终只有一个CPU在运行。package main import ( &
- 在写代码的时候,免不了要使用变量。但程序中的一个变量并不一定是在哪里都可以被使用,根据情况不同,会有不同的“有效范围”。看这样一段代码:de