• MySQL半同步复制


    在做MySQL主从半同步之前先做主从复制

    一、部署MySQL主从半同步复制

    半同步复制支持多种插件:/usr/lib64/mysql/plugin/*

    半同步复制插件:

     semisync_master.so

     semisync_slave.so

    [root@localhost ~]# rpm -ql mariadb-server | grep semisync
    /usr/lib64/mysql/plugin/semisync_master.so
    /usr/lib64/mysql/plugin/semisync_slave.so

    1、111、112进入mysql查看插件是否安装

    [root@localhost ~]# mysql
    Welcome to the MariaDB monitor. Commands end with ; or g.
    Your MariaDB connection id is 6
    Server version: 5.5.41-MariaDB-log MariaDB Server

    Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    MariaDB [(none)]> show plugins;

    2、如果没有安装,则先在主节点安装并启用插件:

    MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [(none)]> show plugins;

    MariaDB [(none)]> show global variables like '%semi%';
    +------------------------------------+-------+
    | Variable_name | Value |
    +------------------------------------+-------+
    | rpl_semi_sync_master_enabled | OFF |
    | rpl_semi_sync_master_timeout | 10000 |
    | rpl_semi_sync_master_trace_level | 32 |
    | rpl_semi_sync_master_wait_no_slave | ON |
    +------------------------------------+-------+
    4 rows in set (0.00 sec)

    MariaDB [(none)]> set @@global.rpl_semi_sync_master_enabled=ON;

    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> show global variables like '%semi%';

    +------------------------------------+-------+
    | Variable_name | Value |
    +------------------------------------+-------+
    | rpl_semi_sync_master_enabled | ON |
    | rpl_semi_sync_master_timeout | 10000 |
    | rpl_semi_sync_master_trace_level | 32 |
    | rpl_semi_sync_master_wait_no_slave | ON |
    +------------------------------------+-------+
    4 rows in set (0.00 sec)

    3、在从节点安装并启用插件:

    MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so';
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [(none)]> show plugins;

    MariaDB [(none)]> show global variables like '%semi%';
    +------------------------------------+-------+
    | Variable_name | Value |
    +------------------------------------+-------+
    | rpl_semi_sync_master_enabled | OFF |
    | rpl_semi_sync_master_timeout | 10000 |
    | rpl_semi_sync_master_trace_level | 32 |
    | rpl_semi_sync_master_wait_no_slave | ON |
    +------------------------------------+-------+
    4 rows in set (0.00 sec)

    MariaDB [(none)]> set @@global.rpl_semi_sync_master_enabled=ON;

    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> show global variables like '%semi%';

    +------------------------------------+-------+
    | Variable_name | Value |
    +------------------------------------+-------+
    | rpl_semi_sync_master_enabled | ON |
    | rpl_semi_sync_master_timeout | 10000 |
    | rpl_semi_sync_master_trace_level | 32 |
    | rpl_semi_sync_master_wait_no_slave | ON |
    +------------------------------------+-------+
    4 rows in set (0.00 sec)

    4、先查看主节点,然后从节点启动IO线程,在查看主节点

    MariaDB [(none)]> show global status like '%semi%';

    从节点启动IO线程:

    MariaDB [(none)]> stop slave IO_THREAD;
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> start slave IO_THREAD;
    Query OK, 0 rows affected (0.00 sec)

    主节点:

    5、在主节点为事先创建的用户进行主从复制授权:

    MariaDB [(none)]> grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123456';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [(none)]> show master status;
    +---------------------+----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +---------------------+----------+--------------+------------------+
    | mysql-binlog.000004 | 931 | | |
    +---------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

    6、从节点:

    MariaDB [(none)]> stop slave;
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [(none)]> CHANGE MASTER TO
    -> MASTER_HOST='192.168.200.111',
    -> MASTER_USER='myslave',
    -> MASTER_PASSWORD='123456',
    -> MASTER_LOG_FILE='mysql-binlog.000004',
    -> MASTER_LOG_POS=931;
    Query OK, 0 rows affected (0.01 sec)

    MariaDB [(none)]> start slave;
    Query OK, 0 rows affected (0.00 sec)

    7、在主节点创建数据库mydb

    MariaDB [(none)]>create database nydb character set 'utf8';

    Query OK, 1 row affected (0.00 sec)

    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mydb |
    | mysql |
    | performance_schema |
    | test |
    | test01 |
    | test02 |
    +--------------------+
    7 rows in set (0.01 sec)

    在从节点查看数据库是否复制成功:

    发现数据库mydb复制成功

    在主节点进行数据操作:

    MariaDB [(none)]> use mydb
    Database changed
    MariaDB [mydb]> create table tbl1 (id int,name varchar(100));
    Query OK, 0 rows affected (0.03 sec)

     主节点继续操作:

    MariaDB [mydb]> insert into tbl1 values (1,'tom');
    Query OK, 1 row affected (0.01 sec)

    我们发现从节点的数据都在变化:

  • 相关阅读:
    HDFS snapshot操作实战
    不是技术牛人,如何拿到国内IT巨头的Offer(转载)
    HBase的RowKey设计原则
    hbase shell 基本命令总结
    13_Python数据类型字符串加强_Python编程之路
    监督学习与无监督学习的区别_机器学习
    12_Python的(匿名函数)Lambda表达式_Python编程之路
    Python数据挖掘_Python2模块Spynner的安装(安装失败)
    06_Linux目录文件操作命令3查找命令_我的Linux之路
    python数据挖掘_Json结构分析
  • 原文地址:https://www.cnblogs.com/990624lty-jhc/p/11691034.html
Copyright © 2020-2023  润新知