percona mysql server5.7基于gtid的主从复制

时间:2021-12-05 23:18:00
配置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. MySQL5.7.18基于GTID的主从复制过程实现

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

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

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

  9. Mysql 基于GTID的主从复制(实操)

    实现环境: Master 主:192.168.0.102 (Mysql 5.6.36) Slave  从 :192.168.0.103 (Mysql 5.6.36) 步骤1.在主DB服务器上建立复制账 ...

随机推荐

  1. NYOJ 485

    A*B Problem 描述 设计一个程序求出A*B,然后将其结果每一位相加得到C,如果C的位数大于等于2,继续将C的各位数相加,直到结果是个一位数k. 例如: 6*8=48: 4+8=12: 1+2 ...

  2. Junit使用

    eclipse Junit的简单使用: eclipse自带了Junit插件. 安装Junit,如下图所示,右键项目-->Properties-->Add Library 选择Junit 选 ...

  3. C#访问ORALCE数据库

    随着时间的推移知识也在更新,原来可用的技术也会被淘汰或更新. framework4.0开始不再支持System.Data.OracleClient了,但是令人欣慰的是ORACLE公司自己出了一个Ora ...

  4. VMWare的网络

    1.VMWare的网络连接方式区别 连接方式 宿主机和虚拟机 虚拟机对外网的访问 外网对虚拟机的访问 Host-Only 可以相互访问 不能直接访问 不能直接访问 NAT 虚拟机可以访问宿主机 可以( ...

  5. HBase LSM树存储引擎详解

    1.前提 讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎. B树存储引擎. LSM树(Log-Structured Merge Tree)存储引擎. 2. 哈希 ...

  6. 使用Docker发布DNC项目

    项目结构 可以忽略中间三个Console项目 ApiCenter 是一个WebAPI项目,引用了NLog.MQ项目 ApiCenter使用5001端口 public static IWebHost B ...

  7. 有关java(初学笔记)

    JAVA的主要优势:跨平台性,可以在Linux,windows,mac三个系统上运行. 跨平台的核心:JAVA虚拟机--JVM 原理就是将Java语言在这个系统上翻译.JAVA在jvm上运行,jvm进 ...

  8. 高级版本VS打开低版本VS工程,无法调试的问题

    选中Debugging选项,在Command命令行里面输入生成exe文件的相对路径. 转载:http://blog.csdn.net/x931100537/article/details/405052 ...

  9. ASP.NET Core 2 学习笔记

    之前的ASP.NET网站,只要把*.html.*.css.*.jpg.*.png.*.js等静态文件放在项目根目录,默认都可以直接被浏览:但ASP.NET Core 小改了浏览静态文件的方式,默认根目 ...

  10. Maven项目导出可执行jar

    配置文件中添加插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>m ...