MySQL (double main) master main frame configuration

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43442524/article/details/100077120

Foreword

The main building Mysql main architecture is based on my keepalived + nginx + apache + mysql to achieve high availability, load balancing website article

Before we first set up the master who introduced the main configuration mysql master-slave scheme

mysql master-slave scheme, a master from multiple, separate read and write functions, but a single main single point of failure, the need to make the main library Coetzee replaced disadvantages like 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.

MySQL dual master (primary master) architecture program ideas:

  1. Two mysql can read and write, 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. High availability strategy is recommended when, masterA or masterB not because of the downtime and recovery seize the VIP (non-preemptive mode);

Doing so can guarantee the high availability of the main library to a certain extent, after a master database goes down, you can switch to another main library in a very short period of time (to minimize downtime caused by the main library on the business Effect), to reduce the pressure of the main line from the main synchronization brought to the library;

But there are several deficiencies in the:

  1. masterB might have been in an idle state (from the library can use it as a responsible part of the query);

  2. Serving behind the main library from the library to wait after masterB first synchronous data over up to go masterB synchronize data, this may cause some degree of synchronization delay;

Built environment

Host Name install software ip address
mysql1 mysql、mysql-server 172.18.74.76
mysql2 mysql、mysql-server 172.18.74.71

Installation process

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

mv http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm /etc/yum.repo/

rpm -ivh mysql.com/mysql-community-release-el7-5.noarch.rpm

yum install -y mysql&&yum install mysql-server -y

systemctl start mysql

First, we configure mysql double master model, let data synchronization

vim /etc.my.cnf

server-id=1
log-bin=mysql-bin
binlog_format=mixed
relay-log=relay-bin
relay-log-index=slave-relay-bin.index
auto-increment-increment=2
auto-increment-offset=1
log-slave-updates

Red box in which you need to add the contents of history

Powder box are two different places mysql

Powder is 2 at block mysql2

Then restart the mysql

systemctl restart mysql

Auto-increment arranged in two rows, so masterA field values ​​generated is an odd number below masterB 1,3,5,7 2,4,6,8 like is generated, it will avoid duplication of dual master id

Create a user

grant replication slave on *.* to 'repl'@'172.18.74.71' identified by '123456'; ';

flush privileges;

web server license

mysql> create database db_jd;
Query OK, 1 row affected (0.00 sec)

mysql> create user web@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to web@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> create user [email protected] identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> create user [email protected] identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'web'@'%' IDENTIFIED BY '123456' WITH GRANT OPTTION;
--------------
GRANT ALL PRIVILEGES ON *.* TO 'web'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION
--------------
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

Check the status of the main library

Configuration synchronization information

masterA 上:

change master to master_host='172.18.74.71',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=632;

start slave;

show slave status\G

masterB on:

change master to master_host='172.18.74.76',master_port=3306,master_user='repl',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=632;

start slave;

show slave status\G

The Lord synchronization test

Creating a database synchronization test results on masterA

mysql> create database myTest;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myTest             |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

MasterB to check whether they have created a database synchronization

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| myTest             |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

success!

Guess you like

Origin blog.csdn.net/qq_43442524/article/details/100077120