MySQL replication configuration to achieve the main from the library, AB

 

 

AB replication is a data replication technique, is a high availability database provides myslq, high-performance solution.

AB copy modes:
a master-slave, a master from multiple, double main, multi-master from multiple

Replication works:
To achieve ab replication, the prerequisite is to turn on the master binary log
1) First of all master data updates to the binary log files recorded
2) starting from the slave start, slave to master a request by the binary I / O thread log files, slave to know whom to call for the point from which position request
after 3) master receives I / O requests slave, it will start from the corresponding position of the point, to slave transfer log
4) after receiving a slave to the log, write into local relay logs in
. 5) is read by the slave thread sql content relay log, the appropriate action in the database so far, and consistent data on the master slave, a slave server then enters a wait state waiting subsequent updates of master

Copy the operating principle:

 

 

 Configuration instructions:

Installation Configuration
1. Preparation
1. Close the firewall
2. Close SELinux
3. Configure a fixed ip address
4. configured yum source
5. The modified host name

 

2. Experimental environment
master server: 192.168.1.3 master.uplook.com # master database
slave server: 192.168.1.4 slave.uplook.com # from the library

 

 

3. The configuration process
master configuration (where the main library server)
1) Install the software
to install MySQL database (not installed can see this reference  https://www.cnblogs.com/pxblog/p/10529943.html )

 

2) modify the configuration file of the main library server

vim /etc/my.cnf

[mysqld]
log-bin = binlog // open the binary log
server-id = 1 // id specified service

 

 

3) Start Service

systemctl start mysqld 

 

 

4) Check whether the service is listening

 netstat -tulnp | grep 3306

  The following is displayed, indicating a successful start (parameter may be different)

tcp6       0      0 :::3306                 :::*                    LISTEN      11156/mysqld

  

 

5) authorized users to copy data to a realization (problems with specific instructions can view https://www.cnblogs.com/pxblog/p/10721939.html )
MySQL> Grant Slave Replication, Replication Client ON *. * To 'repluser '@' 192.168.1.4 'identified by' 123456 ';

 

 

In the slave remote login authorization test

mysql -u repluser -h 192.168.1.3 -p123456

  

 

slave configuration (from the library where the server)
1) Install the software
(installed as the MySQL database)

 

2) modify the configuration file

vim /etc/my.cnf  

[mysqld]
Server-ID = 2 // master server and ensure that inconsistencies

 

 

3) Start Service

systemctl start mysqld

 

 

4) Check whether the service is listening

netstat -tulnp | grep 3306

The following describes the successful emergence (parameters may be different)

tcp6       0      0 :::3306                 :::*                    LISTEN      11156/mysqld

 

5) On the master (where the main library server) to view, log in MySQL database

mysql> show master status\G

 Shows the following 

*************************** 1. row ***************************
File: binlog.000001
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)

 

6) synchronize data on a slave, you need to tell the slave master position from which to start synchronization (following parameters may be different for each person)

mysql> change master to master_host='192.168.1.3',
master_port=3306,master_user='repluser',
master_password='123456',
master_log_file='binlog.000001',master_log_pos=154;  

  Description:

        master_host: database server ip

        master_port: database port

        master_user: User

        master_password: Password

        master_log_file: File parameter value corresponding to the above

        master_log_pos: Position value as the same as above

 

7) starting from the server

mysql> start slave;  

Query OK, 0 rows affected (0.00 sec)

 

8) Check the status from the server

mysql> show slave status\G;

Slave_IO_Running: Yes // ensure io and sql thread is yes
Slave_SQL_Running: Yes

 

Test: master-slave synchronization is successful
to create the table insert data in the master
view on whether there is the slave table
indicating the completion of the master-slave synchronization

 

Question:
1. If you change the statement in question
MySQL> Slave STOP;
change statement Problem Cause
1) may be more spaces
2) keyword is incorrect
2. account data synchronization can not connect to the master
1) account password is wrong
2) can not telnet

 

All add to the table read locks
> flush tables with read lock;
unlock
> unlock tables;

 

Guess you like

Origin www.cnblogs.com/pxblog/p/12501417.html