mysql cluster basis of mariadb double main (primary master) architecture

First, the concept

  In the enterprise, the enterprise database availability has been a top priority, many SMEs are using the mysql master-slave scheme, a master multi-slave, read and write separation, but single-master single point of failure, replace the master-slave Coetzee libraries need to make changes. Thus, if a dual master or multi-master, mysql inlet increases, increasing availability. But more needs to be considered self-growth ID main issues, especially the need to set up profiles, such as dual master, you can use the parity, in short, self-growth ID settings do not conflict with each other can be the perfect solution for self-growth ID conflict between the Lord.

Single point of failure Solution:
  The Lord Architecture:
    mutual backup, monitor each other's binary log files synchronized
    note: When two sql statements conflict with the main architecture of the main possible data inconsistencies arise;
  MHA (Master High dostępność ):
    HMA can have multiple profiles, a profile monitor a master-slave architecture

Second, the main idea of ​​the main architecture

1, two mysql can read writeable, mutual backup, using only a default write (masterA) is responsible for data, the other (masterB) backup;

2, masterA is masterB host library, masterB is masterA primary library, from which the main interaction;

3, do high availability between the two main libraries, and other programs can be used keepalived (VIP use external services);

4, all services will be a primary synchronization (multiple master from bis) from the server masterB;

5, recommended when high availability strategy, masterA or masterB not because of the downtime and recovery seize the VIP (non-preemptive mode);

 Third, demonstrate the steps

Environment (1 master server IP: 192.168.11.7; 2 master server IP: 192.168.11.8)

 

1, modify the configuration file, the configuration server number, open the bin-log

[root@ren7 ~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=7
log_bin=mysql-bin
binlog_format=row
relay-log=relay-mysql
relay-log-index=relay-mysql.index
log_slave_updates=on
auto-increment-increment=2
auto-increment-offset=1
[root@ren8 ~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=8
log_bin=mysql-bin
binlog_format=row
relay-log=relay-mysql
relay-log-index=relay-mysql.index
log_slave_updates=on
auto-increment-increment=2
auto-increment-offset=2

2, restart the mysql service (two hosts)

 systemctl restart mariadb
 ss -tnl |grep 3306
LISTEN     0      80          :::3306                    :::*

3, create a copy of the user (two hosts)

[root@ren8 ~]# mysql -uroot -proot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.2.26-MariaDB-log MariaDB Server

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant replication slave on *.* to 'master'@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

4, (if the first synchronization can ignore this step) where two hosts can clear master and slave log (if there had opened before synchronization, synchronization needs to stop: stop slave;)
entered in the command line mysql:
  RESET Master;
  RESET Slave;

5, see the binary log files

--主1 
MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 1087 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
--主2
MariaDB [(none)]> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 520 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

6, while data is written in synchronization to prevent configuration, can be added to the database read lock:

MariaDB [(none)]> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

7, two servers are connected

--主1连接主2
MariaDB [(none)]> change master to master_host='192.168.11.8',master_user='master',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=520;
Query OK, 0 rows affected (0.01 sec)
--主2连接主1
MariaDB [(none)]> change master to master_host='192.168.11.7',master_user='master',master_password='123',master_log_file='mysql-bin.000001',master_log_pos=1087;
Query OK, 0 rows affected (0.05 sec)

8, start slave

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

9, check the connection status

MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.11.7
                  Master_User: master
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 1087
               Relay_Log_File: relay-mysql.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            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: 1087
              Relay_Log_Space: 256
              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: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60  maximum-retries: 86400  message: Can't connect to MySQL server on '192.168.11.7' (113 "No route to host")
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
      Replicate_Do_Domain_Ids: 
  Replicate_Ignore_Domain_Ids: 
                Parallel_Mode: conservative
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
1 row in set (0.00 sec)

10, add firewall rules

[root@ren7 ~]# firewall-cmd --add-port=3306/tcp
success
[root@ren7 ~]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@ren8 ~]# firewall-cmd --add-port=3306/tcp
success
[root@ren8 ~]# firewall-cmd --add-port=3306/tcp --permanent
success

11, check the connection status again

MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.11.8
                  Master_User: master
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 520
               Relay_Log_File: relay-mysql.000002
                Relay_Log_Pos: 555
        Relay_Master_Log_File: mysql-bin.000001
             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: 520
              Relay_Log_Space: 860
              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: 8
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
                   Using_Gtid: No
                  Gtid_IO_Pos: 
      Replicate_Do_Domain_Ids: 
  Replicate_Ignore_Domain_Ids: 
                Parallel_Mode: conservative
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
1 row in set (0.00 sec)

12, the test

--解锁
MariaDB [(none)]> unlock tables; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| ren                |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> create database if not exists yang default character set utf8;
Query OK, 1 row affected (0.00 sec)

 

Guess you like

Origin www.cnblogs.com/renyz/p/11488236.html