实现mysql的a-b-b ,a-b-c结构

一、实现mysql的a-b-b结构

 

 

先说ab结构

master:
 vim /etc/my.cnf
 [mysqld]
server_id = 1

slave:
 vim /etc/my.cnf
 [mysqld]
server_id = 2

 

2
master:
 vim /etc/my.cnf
 [mysqld]
server_id = 1
log-bin=binlog
log-bin-index=binlog.index


3
slave:
 vim /etc/my.cnf
 [mysqld]
 server_id = 2
 relay_log = /var/lib/mysql/mysql-relay-bin
 relay_log_index=/var/lib/mysql/mysql-relay-bin.index


4
 master && slave
 service mysqld restart

5
 master:
mysql> GRANT replication slave ON *.* TO 'username'@'%' identified by 'passwd';
Query OK, 0 rows affected (0.05 sec)

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

##################################################
slave:
 cd /var/lib/mysql
 rm -fr *
 service mysqld restart
master
 mysqldump -A -x > /tmp/full.sql
 scp /tmp/full.sql root@salveip:/tmp/

slave:
 mysql < /tmp/full.sql


********************6******************************
master:
 mysql> flush tables with read lock;
 mysql> show master status;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000003 |      295 |              |                  |

mysql>unlock tables;


6
slave:
mysql> change master to master_host='master的IP地址', master_port=3306, master_user='username', master_password='passwd', master_log_file='binlog.000003',master_log_pos=295;

mysql> start slave;

7
slave:
 mysql> show slave status \G
   Slave_IO_Running: Yes
     Slave_SQL_Running: Yes
 

至此ab结构就配置完成了

 

A-B-B主从配置

原理依然是基于最普通的master-slave就再增加一台slave服务器,即可。

A-B-C主从配置

原理依然是基于最普通的master-slave。 首先建立A-B之间的master-slave。然后建立B-C之间的master-slave, 需要注意的是必须在Bmy.cnf配置中加上 log-slave-updates=1,这是为了将中继日志接收到的信息复制到本地的binlog,这样C才能收到更新信息。

 

你可能感兴趣的:(master,结构,a-b-b,a-b-c,a-b)