配置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的主从复制的更多相关文章

  1. mysql主从之基于gtid的主从复制

    一 GITD介绍 1.1 gtid的含义 Global Transaction Identifier,全局事务标识 阿里云的rds目前已经使用gtid 基于gtid的主从复制原理 每个mysql数据库 ...

  2. MySQL 5.7基于GTID的主从复制

            since i've broken down the replication enviornment by "reset master;" yesterday.th ...

  3. MySQL 5.7基于GTID的主从复制环境搭建(一主一从)

      Preface       As wel all know,replication base on GTID with row format of binary log is comprehens ...

  4. Mysql5.7实现主从复制、基于GTID的主从复制、并行复制

    (一.主从复制) 一.mysql主从复制原理    mysql的默认复制方式是主从复制.Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制, ...

  5. MySQL 5.7基于GTID复制的常见问题和修复步骤(二)

    [问题二] 有一个集群(MySQL5.7.23)切换后复制slave报1236,其实是不小心在slave上执行了事务导致 Got fatal error 1236 from master when r ...

  6. 实现mysql的读写分离(mysql-proxy)____1(mysql的主从复制,基于gtid的主从复制,半同步复制,组复制)

    主从复制原理: 从库生成两个线程,一个I/O线程,一个SQL线程: i/o线程去请求主库 的binlog,并将得到的binlog日志写到relay log(中继日志) 文件中:主库会生成一个 log ...

  7. MySQL 5.7 基于GTID主从复制+并行复制+半同步复制

    环境准备 IP HOSTNAME SERVICE SYSTEM 192.168.131.129 mysql-master1 mysql CentOS7.6 192.168.131.130 mysql- ...

  8. MySQL5.7.18基于GTID的主从复制过程实现

    GTID是5.6时加入的,在5.7中被进一步完善,生产环境建议在5.7版本中使用.GTID全称为Global Transaction Identifiers,全局事务标识符.GTID的复制完全是基于事 ...

  9. MySQL5.6基于GTID的主从复制配置

    全局事务标示符(Global Transactions Identifier)是MySQL 5.6复制的一个新特性. GTID实际上是由UUID+TID组成的.其中UUID是一个MySQL实例的唯一标 ...

随机推荐

  1. nginx 前端POST请求405问题解决与排查过程

    问题描述 在请求时,f12提示POST请求报错405 环境描述 nginx转发至后端nginx,后端nginx转发至后端golang api接口 解决步骤 根据网上方法排查,发现80%以上无非就是以下 ...

  2. Centos配置ARP和Tomcat Native

    Tomcat Native是用于Tomcat的一个可选组件,能够允许Tomcat使用一定的本地资源.性能.兼容性. 具体来说,Tomcat Native给了Tomcat访问 Apache Portab ...

  3. 完全使用UDP登录Linux

    ===============Mosh 登录器========================================= == 针对TCP被某些防火墙阻断的Linux机器, 该程序可以让你不使 ...

  4. Nginx 配置反向代理后,页面中取绝对URL地址的问题显示代理端口

    本文有V型知识库提供 upstream tomcat {    server 127.0.0.1:82;} location / {     proxy_pass http://tomcat;} 如上 ...

  5. Java8新特性_接口中的默认方法

    默认方法由来猜想 1. Collection接口.Collections公共类.  同是操作集合,为啥要搞俩?没必要.在接口中搞一些默认实现,一个接口即搞定了. 2. Java8支持Lambda表达式 ...

  6. spring注解第04课 @Import

    1.beans package com.atguigu.bean; public class Blue { public Blue(){ System.out.println("blue.. ...

  7. 【VS2015】链接器错误link2001

    昨天的D3d第一章代码自己打了一遍结果运行报错LINK2001,无法解析外部的MinMain. 解决方法: 项目[属性]→[链接器]→[系统]→[子系统(subsystem)]改为控制台或者留空也可以 ...

  8. 【bzoj 2049】Cave 洞穴勘测

    Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...

  9. Kali Linux之常见后门工具介绍

    1.Meterpreter 它是Metasploit框架中功能强大的后渗透模块.可以通过Meterpreter的客户端执行攻击脚本,远程调用目标主机上运行的Meterpreter服务端. 命令 作用 ...

  10. antd card 组件实现鼠标移入移出效果

    鼠标移出: 鼠标移入: import React, { Component } from 'react' import { Card, Icon, Avatar } from 'antd'; cons ...