mysql5.7 gtid use to build a master-slave replication mode architecture

First, architecture

Two mysql make a master-slave servers, 172.28.18.69 (primary) 172.28.18.78 (from)

Second, were compiled and installed mysql5.7

1, download the source package mysql5.7.26

[root@server-1 /]# mkdir  /usr/local/src/mysql-5.7.26-src
[root@server-1]# cd /usr/local/src/mysql-5.7.26-src/
[root@server-1 mysql-5.7.26-src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26.tar.gz

2, add users and groups mysql

[root@server-1 mysql-5.7.26-src]# useradd mysql
[root@server-1 mysql-5.7.26-src]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)

3, set the mysql user password

[root @ Server- 1 mysql- 5.7 . 26 -src] # passwd mysql 
to change the user's password mysql. 
New Password: 
Re-enter the new password: 
passwd : all authentication tokens have been successfully updated.

4, a new mysql directory relevant, and assign permissions to user mysql

[root@server-1 mysql-5.7.26-src]# mkdir /home/mysql-5.7.26
[root@server-1 mysql-5.7.26-src]# mkdir /home/mysql-5.7.26/data
[root@server-1 mysql-5.7.26-src]# mkdir  /home/mysql-5.7.26/log
[root@server-1 mysql-5.7.26-src]# mkdir -p /home/mysql-5.7.26/run
[root@server-1 home]# chown -R mysql:mysql  mysql-5.7.26/
[root@server-1 home]# cd mysql-5.7.26/
[root@server-1 mysql-5.7.26]# ll
总用量 0
drwxr-xr-x 2 mysql mysql 6 5月  31 14:25 data
drwxr-xr-x 2 mysql mysql 6 5月  31 14:26 log
drwxr-xr-x 2 mysql mysql 6 5月  31 14:26 run

5, the installation dependencies

[root@server-1]# yum install cmake gcc gcc-c++ ncurses-devel bison zlib libxml openssl automake autoconf make libtool bison-devel libaio-devel -y

6, install boost

MySQL5.7.24 required boost version 1.59, later NA MySQL5.7.24

[root@server-1 /]# cd /usr/local/src/
[root@server-1 src]# wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@server-1 src]# tar -zxvf  boost_1_59_0.tar.gz
[root@server-1 src]# mv boost_1_59_0 /usr/local/

7, compile and install

[root@server-1 /]# cd /usr/local/src/mysql-5.7.26-src/
[root@server-1 mysql-5.7.26-src]# tar -zxvf mysql-5.7.26.tar.gz 
[root@server-1 mysql-5.7.26]# cd mysql-5.7.26
[root@server-1 mysql-5.7.26]# cmake -DCMAKE_INSTALL_PREFIX=/home/mysql-5.7.26 -DINSTALL_DATADIR=/home/mysql-5.7.26/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_SSL=yes -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/home/mysql-5.7.26/run/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DSYSCONFDIR=/etc -DWITH_READLINE=on -DWITH_BOOST=/usr/local/boost_1_59_0

If an error occurs midway, then the error information to find the problem, once again compile time, then we need to delete this file CMakeCache.txt under mysql-5.7.26, empty the cache to compile again, just like last error or otherwise appear.

Last seen

CMake Warning:
  Manually-specified variables were not used by the project:

    INSTALL_DATADIR
    WITH_READLINE


-- Build files have been written to: /usr/local/src/mysql-5.7.26-src/mysql-5.7.26

Compile successful, then execute

[root@server-1 mysql-5.7.26]# make && make install

Last seen 

-- Installing: /home/mysql-5.7.26/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /home/mysql-5.7.26/support-files/mysqld_multi.server
-- Installing: /home/mysql-5.7.26/support-files/mysql-log-rotate
-- Installing: /home/mysql-5.7.26/support-files/magic
-- Installing: /home/mysql-5.7.26/share/aclocal/mysql.m4
-- Installing: /home/mysql-5.7.26/support-files/mysql.server

8, write a configuration file my.cnf 

[root@server-1 mysql-5.7.26]# vim /etc/my.cnf
[mysqld] bsedir
=/home/mysql-5.7.26 datadir=/home/mysql-5.7.26/data socket=/home/mysql-5.7.26/run/mysql.sock user=mysql symbolic-links=0 [mysqld_safe] log-error=/home/mysql-5.7.26/log/mysqld.log pid-file=/home/mysql-5.7.26/run/mysqld.pid

9, configure the environment variables

[root @ Server- 1 mysql- 5.7 . 26 ] # vim / etc / Profile 
at the end of the file add 
the PATH = $ the PATH: / Home / mysql- 5.7 . 26 / bin / 
[root @ Server - 1 mysql- 5.7 . 26 ] # source / etc / profile

10, initialize the database system

[root@server-1 /]# mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26/ --datadir=/home/mysql-5.7.26/data/
[root@server-1 /]# 

No error, see the initial password log

[root@server-1 /]# cat /home/mysql-5.7.26/log/mysqld.log |grep password
2019-06-04T01:56:14.224507Z 1 [Note] A temporary password is generated for root@localhost: dyB8iUq<EaK;

11, start the database

[root@server-1 /]# mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
2019-06-04T02:00:01.566664Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
2019-06-04T02:00:01.629556Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data

12, start the client, enter the initial password database

[root@server-1 ~]# mysql -uroot -p

13, change passwords

mysql> set PASSWORD=PASSWORD('xxxxxxx');
mysql> alter user 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

Exit, log in again

[root@server-1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

 Third, the master-slave configuration Configuration

1, the main library 172.28.18.69 profile

[mysqld] 
the basedir = / Home / MySQL- 5.7 . 26 is 
DATADIR = / Home / MySQL- 5.7 . 26 is / Data 
Socket = / Home / MySQL- 5.7 . 26 is / RUN / mysql.sock 
User = MySQL 
symbolic -links = 0 
the server_id = 69 
gtid_mode = ON # gtid open mode 
enforce_gtid_consistency = ON # gtid mandatory conformance 
log -bin = Master # turn on binary logging 
binlog_format = Row 


[mysqld_safe] 
log-error=/home/mysql-5.7.26/log/mysqld.log
pid-file=/home/mysql-5.7.26/run/mysqld.pid

Restart mysql, mysql and log

[root@server-1 /]# mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
[1] 29747
[root@server-1 /]# 2019-06-04T02:34:07.501598Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
2019-06-04T02:34:07.554499Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data
^C
[root@server-1 /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-log Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

Query status main library

mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| master.000001 |      154 |              |                  |                   |
+---------------+----------+--------------+------------------+-------------------+

One more Executed_Gtid_Set

Queries related variables gitd

mysql> show variables like '%gtid%';
+----------------------------------+-----------+
| Variable_name                    | Value     |
+----------------------------------+-----------+
| binlog_gtid_simple_recovery      | ON        |
| enforce_gtid_consistency         | ON        |
| gtid_executed_compression_period | 1000      |
| gtid_mode                        | ON        |
| gtid_next                        | AUTOMATIC |
| gtid_owned                       |           |
| gtid_purged                      |           |
| session_track_gtids              | OFF       |
+----------------------------------+-----------+
8 rows in set (0.00 sec)

2, create an account on the main library repl

mysql> grant replication slave,replication client on *.* to 'repl'@'%' identified by 'xxxxxx';
Query OK, 0 rows affected, 1 warning (0.02 sec)

3 configuration file from the library

[mysqld]
basedir=/home/mysql-5.7.26
datadir=/home/mysql-5.7.26/data
socket=/home/mysql-5.7.26/run/mysql.sock
user=mysql
symbolic-links=0
server_id=103
gtid_mode=on #开启gtid模式
enforce_gtid_consistency=on
log-bin=salve
binlog_format=row


[mysqld_safe]
log-error=/home/mysql-5.7.26/log/mysqld.log
pid-file=/home/mysql-5.7.26/run/mysqld.pid

Restart mysql

[root@server-2 log]# mysqld_safe --defaults-file=/etc/mysql/my.cnf &
[1] 1037
[root@server-2 log]# 2019-06-04T02:49:07.867996Z mysqld_safe Logging to '/home/mysql-5.7.26/log/mysqld.log'.
2019-06-04T02:49:07.899183Z mysqld_safe Starting mysqld daemon with databases from /home/mysql-5.7.26/data

Log mysql, execute the following command from the library

mysql> change master to master_host='172.28.18.69' ,master_user='repl',master_password='xxxxxx',master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.30 sec)

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

View from the library status

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.28.18.69
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master.000001
          Read_Master_Log_Pos: 457
               Relay_Log_File: server-2-relay-bin.000002
                Relay_Log_Pos: 664
        Relay_Master_Log_File: master.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: 457
              Relay_Log_Space: 874
              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: 69
                  Master_UUID: ee3e292b-866b-11e9-9df8-14feb5dc2c77
             Master_Info_File: /home/mysql-5.7.26/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: ee3e292b-866b-11e9-9df8-14feb5dc2c77:1
            Executed_Gtid_Set: 520b8b86-8675-11e9-8283-90b11c15be09:1-3,
ee3e292b-866b-11e9-9df8-14feb5dc2c77:1
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

success

mysql> mysql> show variables like '%gtid%';
+----------------------------------+----------------------------------------+
| Variable_name                    | Value                                  |
+----------------------------------+----------------------------------------+
| binlog_gtid_simple_recovery      | ON                                     |
| enforce_gtid_consistency         | ON                                     |
| gtid_executed_compression_period | 1000                                   |
| gtid_mode                        | ON                                     |
| gtid_next                        | AUTOMATIC                              |
| gtid_owned                       |                                        |
| gtid_purged                      | ee3e292b-866b-11e9-9df8-14feb5dc2c77:1 |
| session_track_gtids              | OFF                                    |
+----------------------------------+----------------------------------------+

test

New test libraries main library and the test table, a record is inserted

mysql> create database test;
Query OK, 1 row affected (0.02 sec)

mysql> use test;
Database changed
mysql> create table test(id int ,name varchar(20));
Query OK, 0 rows affected (0.14 sec)

mysql> insert into test values(1,'aaaaa');
Query OK, 1 row affected (0.05 sec)

mysql> select * from test;
+------+-------+
| id   | name  |
+------+-------+
|    1 | aaaaa |
+------+-------+
1 row in set (0.00 sec)

In the view from the library

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from test;
+------+-------+
| id   | name  |
+------+-------+
|    1 | aaaaa |
+------+-------+
1 row in set (0.00 sec)

Data synchronization is successful.

 

Guess you like

Origin www.cnblogs.com/sky-cheng/p/10955054.html