percona mysql server5.7基于gtid的主从复制
配置mysql基于gtid主从复制架构 一、二进制安装mysql [root@node5 data]# tar -zxf Percona-Server-5.7.--Linux.x86_64.ssl101.tar.gz
[root@node5 data]# mv Percona-Server-5.7.--Linux.x86_64.ssl101 percona-server-5.7.-
[root@node5 data]# mv percona-server-5.7.- /usr/local/
[root@node5 local]# cd /usr/local/
[root@node5 local]# ln -s percona-server-5.7.- mysql # 添加用户
useradd -u -G users -s /sbin/nologin -M -d /usr/local/mysql/bin mysql mkdir -p /data/mysql_data
chown -R mysql.mysql /data/mysql_data # 编辑配置
vim /etc/my.cnf [client]
port =
socket = /tmp/mysql.sock # The MySQL server
[mysqld]
user = mysql
port =
bind-address = 0.0.0.0
socket = /tmp/mysql.sock
datadir = /data/mysql_data
pid-file = /data/mysql_data/mysql.pid skip-external-locking
#memory is 16G
#key_buffer_size = 16M
key_buffer_size = 32M
#table_open_cache =
table_open_cache =
innodb_open_files =
#sort_buffer_size = 512K
sort_buffer_size = 2M
#net_buffer_length = 4K
net_buffer_length = 32K
#read_buffer_size = 256K
read_buffer_size = 2M
#read_rnd_buffer_size = 4M
read_rnd_buffer_size = 8M
#myisam_sort_buffer_size = 4M
myisam_sort_buffer_size = 32M
thread_cache_size =
query_cache_size = 32M
query_cache_type =
max_write_lock_count =
skip-name-resolve
wait_timeout =
interactive_timeout =
max_connections =
max_connect_errors =
max_allowed_packet = 320M
back_log =
log_timestamps = system sync_binlog =
#当链接数耗尽后,通过设置别用端口,让root可以登录
extra_max_connections =
extra_port =
##让mysql不区分大小写敏感
lower_case_table_names = character_set_server = utf8mb4
performance_schema = ON #for FULLTEXT index , if your progrom used fulltext index please change the value your want.
#ft_min_word_len =
#ft_max_work_len =
slave-skip-errors = ,
#if the query is exec time great than 2 seconds, the query will log to slow log if slowlog is enabled.
long_query_time = 0.5
slow_query_log = on
slow-query-log-file = /data/mysql_data/slow.log
#skip-networking # Replication Master Server (default)
# binary logging is required for replication
log-bin = mysql-bin
expire_logs_days =
log_error = error.log
log_warnings =
# binary logging format - mixed recommended
binlog_format = row
#binlog_format=mixed
relay-log = mysql-relay-bin # required unique id between and ^ -
# defaults to if master-host is not set
# but will not function as a master if omitted
#server-id =
server-id =
sql-mode = "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#sync_binlog = ##### Replication #####
replicate-ignore-db = mysql
replicate-ignore-db = information_schema
replicate-ignore-db = performance_schema
replicate-ignore-db = sys
replicate-ignore-db = undolog
replicate-ignore-db = for_nagios
replicate_wild_ignore_table = mysql.%
replicate_wild_ignore_table = information_schema.%
replicate_wild_ignore_table = performance_schema.%
replicate_wild_ignore_table = sys.% log-slave-updates #skip-slave-start #skip-grant-tables ###rds-ecs,此处配置根据rds的配置来进行设置
innodb_data_file_path = ibdata1:200M:autoextend
innodb_log_files_in_group =
innodb_log_file_size = master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要 #innodb_fast_checksum = false
#innodb_page_size =
#innodb_log_block_size = #innodb_checksum_algorithm = crc32
#innodb_log_checksum_algorithm = strict_crc32 #####
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /data/mysql_data
#innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
innodb_log_group_home_dir = /data/mysql_data #innodb_undo_directory = /data/mysql_data/undolog/
#innodb_undo_logs =
#innodb_undo_tablespaces = # You can set .._buffer_pool_size up to - %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 1G
innodb_buffer_pool_instances =
#innodb_additional_mem_pool_size = 8M # Set .._log_file_size to % of buffer pool size
#innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
#innodb_log_files_in_group =
innodb_flush_log_at_trx_commit =
innodb_lock_wait_timeout =
innodb_file_per_table =
innodb_thread_concurrency =
innodb_max_dirty_pages_pct =
innodb_flush_method = O_DIRECT innodb_purge_threads =
innodb_large_prefix =
innodb_read_io_threads =
innodb_write_io_threads =
innodb_io_capacity =
innodb_io_capacity_max = thread_pool_size =
thread_handling = pool-of-threads
thread_pool_oversubscribe =
thread_pool_stall_limit =
thread_pool_max_threads = #解释: 在启动时把热数据加载到内存。
innodb_buffer_pool_load_at_startup = ##解释: 在关闭时把热数据dump到本地磁盘
innodb_buffer_pool_dump_at_shutdown = [mysqldump]
quick
max_allowed_packet = 320M [mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates [myisamchk]
#key_buffer_size = 20M
#sort_buffer_size = 20M
key_buffer_size = 200M
sort_buffer_size = 200M
read_buffer = 2M
write_buffer = 2M [mysqlhotcopy]
interactive-timeout 初始化MySQL数据库的数据文件路径,并且创建系统表,5.7.6及以上版本,要使用mysqld来初始化数据库
将mysql命令加入环境变量中
vim /etc/profile
export PATH=/usr/local/mysql/bin:$PATH # 修改权限
chown -R mysql.mysql /data/mysql_data [root@node5 local]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql [root@node5 local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@node5 local]# chmod +x /etc/init.d/mysql 修改启动脚本
vim /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/data/mysql_data 启动mysql
/etc/init.d/mysql start
设置root密码,默认密码为空
mysql> set password = password('root');
Query OK, rows affected, warning (0.00 sec) mysql> flush privileges; 二、通过gtid的方式配置mysql主从 主库配置片段:
log-slave-updates = ON master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要
binlog-checksum = CRC32
master-verify-checksum = 从库配置片段:
log-slave-updates = ON master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要
skip-slave-start = true
read_only = ON
slave-sql-verify-checksum =
relay-log = relay-log
relay-log-index = relay-log-index
relay-log-recovery = ON
slave-sql-verify-checksum = 主库添加复制用户:
mysql> grant replication slave on *.* to 'repl'@'10.11.0.215' identified by 'replpass';
mysql> flush privileges; 查看主库与从库的GTID是否开启
mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name | Value |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery | ON |
| enforce_gtid_consistency | ON |
| gtid_executed_compression_period | |
| gtid_mode | ON |
| gtid_next | AUTOMATIC |
| gtid_owned | |
| gtid_purged | |
| session_track_gtids | OFF |
+----------------------------------+-----------+ mysql> show variables like '%gtid_next%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| gtid_next | AUTOMATIC |
+---------------+-----------+
row in set (0.00 sec) 查看服务器server_uuid
mysql> show variables like '%uuid%';
+---------------+--------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------+
| server_uuid | ea04f6f3-631c-11e8-9eac-000c29ff3eec |
+---------------+--------------------------------------+
row in set (0.00 sec) 查看主服务器状态,如果Executed_Gtid_Set字段为空,则可能配置错误需要自行检查配置
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql-bin. | | | | 190a16f8-63b4-11e8-a82d-000c29ff3eec:- |
+------------------+----------+--------------+------------------+------------------------------------------+
row in set (0.00 sec) 配置从库连接至主库
mysql> CHANGE MASTER TO MASTER_HOST='10.11.0.210',MASTER_USER='repl',MASTER_PASSWORD='replpass',MASTER_AUTO_POSITION=;
在从服务器上启动复制
mysql> START SLAVE;
启动成功后查看SLAVE的状态 mysql> SHOW SLAVE STATUS\G ...
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
...
确认 Slave_IO_Running 和 Slave_SQL_Running 两个参数都为 Yes 状态。 在主服务器查看从库连接的主机信息 测试GTID主从复制
在主库(node1)实例创建一些数据,看从库是否能够正常新增 **********
配置mysql基于gtid一主多从方式
node1(master) --> node5(slave) --> node2(主库指向node5,slave) 在之前基于gtid的主从模式:node1(master) --> node5(slave)基础上配置 添加第二个从库node2 10.11..212的过程: 通过二进制安装好数据库my.cnf配置片段 *********************
log-slave-updates ###rds-ecs,此处配置根据rds的配置来进行设置
innodb_data_file_path = ibdata1:200M:autoextend
innodb_log_files_in_group =
innodb_log_file_size = master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要
slave-sql-verify-checksum =
relay-log = relay-log
relay-log-index = relay-log-index
relay-log-recovery = ON
slave-sql-verify-checksum = ********************* 主库node5中添加复制用户:
mysql> grant replication slave on *.* to 'repl'@'10.11.0.212' identified by 'replpass';
mysql> flush privileges; node2上配置从库连接至主库
mysql> CHANGE MASTER TO MASTER_HOST='10.11.0.215',MASTER_USER='repl',MASTER_PASSWORD='replpass',MASTER_AUTO_POSITION=;
在从服务器上启动复制
mysql> START SLAVE;
启动成功后查看SLAVE的状态 mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.11.0.215
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes 看到主库的数据成功复制过来了 mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| china |
| master1 |
| mysql |
| performance_schema |
| sys |
+--------------------+ mysql> use master1;
Database changed
mysql> show tables;
+-------------------+
| Tables_in_master1 |
+-------------------+
| test1 |
+-------------------+
row in set (0.00 sec) mysql> select * from test1;
+------+-------+
| id | count |
+------+-------+
| | |
| | |
| | | 报错处理: 看到Slave_IO_Running: Connecting一只处于连接中状态 mysql> show slave status\G
*************************** . row ***************************
Slave_IO_State: Connecting to master
Master_Host: 10.11.0.215
Master_User: repl
Master_Port:
Connect_Retry:
Master_Log_File:
Read_Master_Log_Pos:
Relay_Log_File: relay-log.
Relay_Log_Pos:
Relay_Master_Log_File:
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes 观察日志:
[root@node02 ~]# tail -f /data/mysql_data/error.log
--31T20::55.187975+: [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
--31T20::55.187987+: [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
--31T20::07.059454+: [Warning] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
--31T20::07.062633+: [ERROR] Slave I/O for channel '': error connecting to master 'repl@10.11.0.215:3306' - retry-time: retries: , Error_code: 原来是授权用户配置错误,修改到repl@10.11.0.212:3306即可 ***************************** 主从切换: *********** .锁定原主数据写操作
原主库中操作:
mysql> flush tables with read lock;
Query OK, rows affected (0.01 sec) .在从服务器中执行stop slave io_thread,用show processlist检查,查看状态是否是Has read all relay log,表示更新完成.
从服务器执行
mysql> show processlist;
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+-----------+---------------+
| Id | User | Host | db | Command | Time | State | Info | Rows_sent | Rows_examined |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+-----------+---------------+
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for more updates | NULL | | |
| | root | localhost | NULL | Query | | starting | show processlist | | |
+----+-------------+-----------+------+---------+------+--------------------------------------------------------+------------------+-----------+---------------+ .在新的主服务器上(原从服务器)执行stop slave,reset master命令,重置成主数据库 新的主库上添加复制用户
mysql> grant replication slave on *.* to 'repl'@'10.11.0.212' identified by 'replpass';
mysql> flush privileges; mysql> stop slave;
mysql> reset master;
mysql> reset slave all; -- 清除同步信息 .删除新的主服务器数据库目录中的master.info和relay-log.info文件,否则下次重启时还会按照从服务器来启动. .原主库切换到从库
# 解锁
mysql> unlock tables; mysql> CHANGE MASTER TO MASTER_HOST='10.11.0.212',MASTER_USER='repl',MASTER_PASSWORD='replpass',MASTER_AUTO_POSITION=;
Query OK, rows affected, warnings (0.01 sec)
mysql> start slave; .修改主从服务器的配置(下次重启后参数改变)
主库配置片段:
log-slave-updates = ON master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要
binlog-checksum = CRC32
master-verify-checksum = 从库配置片段:
log-slave-updates = ON master-info-repository = TABLE ###Slave配置需要
relay-log-info_repository = TABLE ###Slave配置需要
binlog-format =ROW ####Slave配置需要
gtid-mode = on ###开启GTID需要
enforce-gtid-consistency = true ###开启GTID需要
skip-slave-start = true
read_only = ON
slave-sql-verify-checksum =
relay-log = relay-log
relay-log-index = relay-log-index
relay-log-recovery = ON
slave-sql-verify-checksum = 报错的处理:
mysql> start slave;
ERROR (HY000): Slave failed to initialize relay log info structure from the repository 解决:
mysql> reset slave;
Query OK, rows affected (0.00 sec)
mysql> start slave;
配置percona mysql5.7主从,日志同步的方式:
注意server-id必须不同
1.主库master上面配置repl复制同步用户
mysql> CREATE USER 'repl'@'10.11.0.212' IDENTIFIED BY 'replpass';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.11.0.212';
记录主库状态:
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 615 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2.从库配置
放在一行执行方便
CHANGE MASTER TO MASTER_HOST='10.11.0.210', MASTER_USER='repl', MASTER_PASSWORD='replpass', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=615;
启动从服务器复制线程
mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)
查看复制状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.11.0.210
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 615
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql,information_schema,performance_schema,mysql,information_schema,performance_schema
Slave_SQL_Running: Yes
数据库分析工具percona-toolkit
[root@node1 data]# yum localinstall -y percona-toolkit-2.2.19-1.noarch.rpm
percona mysql server5.7基于gtid的主从复制的更多相关文章
- mysql主从之基于gtid的主从复制
一 GITD介绍 1.1 gtid的含义 Global Transaction Identifier,全局事务标识 阿里云的rds目前已经使用gtid 基于gtid的主从复制原理 每个mysql数据库 ...
- MySQL 5.7基于GTID的主从复制
since i've broken down the replication enviornment by "reset master;" yesterday.th ...
- MySQL 5.7基于GTID的主从复制环境搭建(一主一从)
Preface As wel all know,replication base on GTID with row format of binary log is comprehens ...
- Mysql5.7实现主从复制、基于GTID的主从复制、并行复制
(一.主从复制) 一.mysql主从复制原理 mysql的默认复制方式是主从复制.Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制, ...
- MySQL 5.7基于GTID复制的常见问题和修复步骤(二)
[问题二] 有一个集群(MySQL5.7.23)切换后复制slave报1236,其实是不小心在slave上执行了事务导致 Got fatal error 1236 from master when r ...
- 实现mysql的读写分离(mysql-proxy)____1(mysql的主从复制,基于gtid的主从复制,半同步复制,组复制)
主从复制原理: 从库生成两个线程,一个I/O线程,一个SQL线程: i/o线程去请求主库 的binlog,并将得到的binlog日志写到relay log(中继日志) 文件中:主库会生成一个 log ...
- MySQL 5.7 基于GTID主从复制+并行复制+半同步复制
环境准备 IP HOSTNAME SERVICE SYSTEM 192.168.131.129 mysql-master1 mysql CentOS7.6 192.168.131.130 mysql- ...
- MySQL5.7.18基于GTID的主从复制过程实现
GTID是5.6时加入的,在5.7中被进一步完善,生产环境建议在5.7版本中使用.GTID全称为Global Transaction Identifiers,全局事务标识符.GTID的复制完全是基于事 ...
- MySQL5.6基于GTID的主从复制配置
全局事务标示符(Global Transactions Identifier)是MySQL 5.6复制的一个新特性. GTID实际上是由UUID+TID组成的.其中UUID是一个MySQL实例的唯一标 ...
随机推荐
- 使用JMeter进行一次简单的带json数据的post请求测试,json可配置参数
配置: 1.新建一个线程组: 然后设置线程数.运行时间.重复次数. 2.新建Http请求: 设置服务器域名,路径,方法,编码格式,数据内容. 可以在函数助手中,编辑所需要的变量,比如本例中的随机生成电 ...
- idea搭建Spring Boot+MyBatis
需要准备的环境: idea 2017.2 jdk1.8.0_144 Maven 3.5.0 请提前将idea与Maven.jdk配置好,本次项目用的都是比较新的. 步骤: 一.首先使用idea新建一个 ...
- 用python实现单向链表
单向链表 单向链表也叫单链表,是链表中最简单的一种形式,它的每个节点包含两个域,一个信息域(元素域)和一个链接域.这个链接指向链表中的下一个节点,而最后一个节点的链接域则指向一个空值. 表元素域ele ...
- 【一】java 虚拟机 监控示例 Eclipse Memory Analyser
1.堆内存溢出示例代码 import java.util.ArrayList; import java.util.List; public class TestHeap { public static ...
- 微信小程序开发(3) 热门电影
在这篇微信小程序开发教程中,我们将介绍如何使用微信小程序开发热门电影及预览功能. 本文主要分为两个部分,小程序主体部分及电影主页和详情页页面部分 一.小程序主体部分 一个小程序主体部分由三个文件组成, ...
- MVC设置启动页
设置启动页需要在路由中添加一段代码: public static void RegisterRoutes(RouteCollection routes) { rou ...
- springboot04-mongodb
1.搭建mongodb服务 在https://www.mongodb.com/下载mongodb安装包,解压到本地 cmd中执行命令,启动本地mongodb: cd D:\Program Files\ ...
- [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...
- 安装UEStudio以及破解
1.下载UEStudio以及注册机 百度网盘地址:链接:http://pan.baidu.com/s/1hrJfxx6 密码:td1b 如图:第一个是注册机,第二个是UEStudio 2.安装UESt ...
- UOJ #276「清华集训2016」汽水
为什么你们常数都这么小啊 UOJ #276 题意:在树上找一条链使得|边权平均值$ -k$|尽量小,$ n<=5e4$ $ Solution:$ 首先二分答案$ ans$,即我们需要找一条链使得 ...