美文网首页
mysql主从复制

mysql主从复制

作者: 逢场作戏_6fb9 | 来源:发表于2017-09-17 19:21 被阅读0次

原理:

    主节点生成了二进制日志文件之后,从节点的i/o thread发送读请求,主节点经由dump发送给从节点的中继日志,最后由SQL thread读取中继日志中的内容replay完成复制。
QQ截图20170917185021.png

准备环境:

    主节点:192.168.52.138
    从节点:192.168.52.139

禁用selinux策略,清空防火墙规则

    iptables -F
    setenforce 0

更改配制文件:

    主节点:
    Vim /etc/my.cnf.d/server.cnf
    [mysqld]
    log_bin=master-log
    server_id=1
    skip_name_resolve=on
    从节点:
    [mysqld]
    server-id=7
    relay-log=relay-log
    skip_name_resolve=on

配置完成后启动服务:

    systemvtl start mariadb
    ss -ntl | grep '3306'
    确保3306端口打开

主从配置:

    在主节点上授权一个用户
    MariaDB [(none)]> grant replication client,replication slave on *.* to 'kongbinquan'@'192.168.52.139' identified by 'kbq';
    Query OK, 0 rows affected (0.00 sec)
    并找出当前所在节点:
    MariaDB [(none)]> SHOW MASTER STATUS;
    +-------------------+----------+--------------+------------------+
    | File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +-------------------+----------+--------------+------------------+
    | master-log.000006 |      423 |              |                  |
    +-------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)
    接着在从节点上配置:
    
    MariaDB [(none)]> change master to    master_host='192.168.52.138',master_user='kongbinquan',master_password='kbq',master_log_file='master-log.000006', master_log_pos=423;
    Query OK, 0 rows affected (0.03 sec)

从节点状态:

    MariaDB [(none)]> start slave  ;
    Query OK, 0 rows affected (0.02 sec)
    MariaDB [(none)]>  SHOW SLAVE STATUS\G;
    *************************** 1. row ***************************
           Slave_IO_State: Waiting for master to send event
              Master_Host: 192.168.52.138
              Master_User: kongbinquan
              Master_Port: 3306
            Connect_Retry: 60
          Master_Log_File: master-log.000006
      Read_Master_Log_Pos: 423
           Relay_Log_File: relay-log.000002
            Relay_Log_Pos: 530
    Relay_Master_Log_File: master-log.000006
         Slave_IO_Running: Yes
        Slave_SQL_Running: Yes
          Replicate_Do_DB: 
      Replicate_Ignore_DB: 
       Replicate_Do_Table: 
       Replicate_Ignore_Table: 
        Replicate_Wild_Do_Table: 
        Replicate_Wild_Ignore_Table: 
                 Last_Errno: 0
               Last_Error: 
             Skip_Counter: 0
        Exec_Master_Log_Pos: 423
          Relay_Log_Space: 818
          Until_Condition: None
           Until_Log_File: 
            Until_Log_Pos: 0
       Master_SSL_Allowed: No
       Master_SSL_CA_File: 
       Master_SSL_CA_Path: 
          Master_SSL_Cert: 
        Master_SSL_Cipher: 
           Master_SSL_Key: 
    Seconds_Behind_Master: 0
    Master_SSL_Verify_Server_Cert: No
            Last_IO_Errno: 0
            Last_IO_Error: 
           Last_SQL_Errno: 0
           Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
         Master_Server_Id: 1
  1 row in set (0.00 sec)

相关文章

  • MySQL如何配置主从复制,如何修复主从复制出现的异常?

    MySQL如何配置主从复制,如何修复主从复制出现的异常? 一、什么是Mysql主从复制 MySQL主从复制是其最重...

  • MySQL-主从复制&读写分离

    零、本文纲要 一、MySQL主从复制 主从复制 主从复制过程 配置主从复制 二、MySQL读写分离 读写分离 Sh...

  • Mysql 主从复制

    Mysql 主从复制 MySQL Replication 主从复制(也称 AB 复制)允许将来自一个MySQL数据...

  • 主从复制 & MHA

    一,mysql主从复制 (1)场景一(主从复制 _ 全新环境下) (2)场景二(主从复制 _ mysql已经使用一...

  • mysql主从复制

    构建MySQL主从复制 MySQL的主从复制和mysql的读写分离两者有着紧密联系,数据的读写分离实在主从复制的基...

  • Spring Data JPA 使用主从数据源

    Mysql 配置主从复制 参考:Mysql主从复制-半同步复制[https://www.jianshu.com/p...

  • MySQL集群篇

    1 集群之主从复制 1.1 主从复制概述 MySQL主从复制也可以称为MySQL主从同步,它是构建数据库高可用集群...

  • 深度探索MySQL主从复制原理

    概要 MySQL Replication (MySQL 主从复制) 是什么? 为什么要主从复制以及它的实现原理是什...

  • 【转】MySQL 8.0复制改进

    1 - MySQL主从复制模型 我们从最基本的主从复制模型开始说起,下图是最经典的MySQL主从复制架构图: My...

  • mysql主从代理

    mysql主从复制+读写分离 环境: mysql主:193.168.1.1 mysql从:193.168.1.2 ...

网友评论

      本文标题:mysql主从复制

      本文链接:https://www.haomeiwen.com/subject/nvapsxtx.html