mysql5.7 main building from the library

mysql #MYSQL single node is far from full to generation, to prevent the production server downtime, overflowing disk space and other reasons, the need for a standby database,

This time from the main library is a good choice, in a database cluster also played a big role

#MySQL master-slave replication concepts:

Refers to the replication master MySQL data can be copied from a master node to a MySQL database server from one or more nodes. MySQL default asynchronous replication, so that node would not have to access the main server from updating update their data, the data can be performed on a remote connection, you can copy all database master database or specific database from the node, or a specific table .

# General master-slave architecture

  • A master-slave

  A master-slave and a master multi-slave is the most common master-slave architecture, simple to implement and effective, not only to achieve HA, but also to read and write separation, and thus enhance the ability of concurrent cluster.

  

  • From a multi-master

  From a multi-master mysql database can be backed up to a plurality of storage servers better performance

  

  •  

    Dual master replication

    Dual-master replication, i.e. replication mutual shots from each of both master master, and a slave of another server. Such changes made by either party, the other party will be applied to the database by copying

  • Cascading replication

  

 

 

   Cascade copy mode, the slave portion of the master node is not connected to data synchronization, but is connected from the node. If there are too many because the master node from the node, the loss will be part of the performance for replication, then we can make three to five connecting node from the master node, the other nodes connected to a two or three from the node, so that not only you can ease the pressure of the master node, and no negative impact on data consistency.

1. The main requirements from the server

(1) version of the same

(2) initialize the table and start mysql in the background

(3) for mysql user

 

2. Main Library Configuration

 

2. From the library configuration, the library does not configure log also can specify only the server_id to meet

 

3. Check the main library log information

mysql>show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000004 | 308 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

 

4.重启主从库,配置从库的slave

mysql>change master to master_host='192.168.145.222',master_user='mysync',master_password='q123456', master_log_file='mysql-bin.000004',master_log_pos=308; //注意不要断开,308数字前后无单引号。 Mysql>start slave; //启动从服务器复制功能

 

5.查看从库复制功能状态

mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.2.222 //主服务器地址 Master_User: mysync //授权帐户名,尽量避免使用root Master_Port: 3306 //数据库端口,部分版本没有此行 Connect_Retry: 60 Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 600 //#同步读取二进制日志的位置,大于等于Exec_Master_Log_Pos Relay_Log_File: ddte-relay-bin.000003 Relay_Log_Pos: 251 Relay_Master_Log_File: mysql-bin.000004 Slave_IO_Running: Yes //此状态必须YES Slave_SQL_Running: Yes //此状态必须YES

注:Slave_IO及Slave_SQL进程必须正常运行,即YES状态,否则都是错误的状态(如:其中一个NO均属错误)。

 

6.进行验证,在主库建表,从库会同步数据过来,可编写shell脚本监控salve两个yes(Slave_IO及Slave_SQL进程),如发现只有一个或零个yes,就表明主从有问题了,发短信警报吧。

 

Guess you like

Origin www.cnblogs.com/xiaolongui/p/12073930.html