mysql-ab-abb

基于mysql-ab,在加一台slave2,要求在master上不做任何操作,使slave2实现备份。

masterIP:192.168.33.10,slave1IP:192.168.33.20,slave2IP:192.168.33.30

(1)master配置

修改vim /etc/my.cnf 文件

 user=mysql[下面添加]

server_id = 1
log-bin=binlog
log-bin-index=binlog.index

(2)slave1配置

修改vim /etc/my.cnf 文件

user=mysql[下面添加]

server-id = 2

relay_log = /var/lib/mysql/mysql-relay-bin

relay_log_index=/var/lib/mysql/mysql-relay-bin.index

(3)master && slave
service mysqld restart

(4)在master上创建一个帐号使slave1可以连接上来

mysql>  GRANT replication slave ON *.* TO 'bob'@'192.168.30.20' identified by '123'; 

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

(5)删除slave1下 /var/lib/mysql/所有文件,然后重启mysql服务

(6)在master上备份,然后在slave1上恢复。-A所有库,-x锁表

mysqldump -A -x > /tmp/full.sql

scp /tmp/full.sql [email protected]:/tmp/

(7)slave1上导入数据

mysql < /tmp/full.sql

(8)master上

mysql> flush tables with read lock;(加把锁)

Query OK, 0 rows affected (0.00 sec)

mysql> show master status;(查看master状态binlog+position)

 +---------------+----------+--------------+------------------+

| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+---------------+----------+--------------+------------------+

| binlog.000002 |       295 |              |                  | 

+---------------+----------+--------------+------------------+

1 row in set (0.00 sec)

mysql> unlock tables;(解锁)
Query OK, 0 rows affected (0.00 sec)

(9)slave1上改变master
mysql>  change master to master_host='192.168.33.10', master_port=3306, master_user='bob', master_password='123', master_log_file='binlog.000002',master_log_pos=295;

 Query OK, 0 rows affected (0.00 sec)

 
mysql> show slave status \G(查看slave1的状态,IO是通信,SQL是进程)
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
 
以上mysql-ab,然后在加一台slave2
 
(1)修改vim /etc/my.cnf 文件

master上为slave2添加一个同步账号,

master

mysql> grant replication slave on *.* to 'bob'@'192.168.33.30' identified by '123';

 

//slave2上登陆成功

保存后,重启mastermysql服务:

service mysql restart;

show master status命令查看日志情况

mysql> show master status\G;

  修改slave1上的配置文件my.cnf

[mysqld]下添加如下字段

vi /etc/my.cnf

server-id = 2

master-host=192.168.33.10

master-user= bob

master-password=123

master-port=3306

relay_log = /var/lib/mysql/mysql-relay-bin

relay_log_index=/var/lib/mysql/mysql-relay-bin.index

保存后,重启slave1mysql服务:

service mysql restart;

修改slave2上的配置文件my.cnf,和slave1一样,只是把server-id改成3即可

在进入两个slave机中的mysql

mysql>start slave;

mysql>show slave status\G;
slave1和slave2 IO和SQL状态均为Yes

 

 Slave_IO_Running: Yes

 Slave_SQL_Running: Yes

本文出自 “村里的男孩” 博客,谢绝转载!

你可能感兴趣的:(mysql-ab-abb)