Heim  >  Artikel  >  Datenbank  >  Mysql测试一:Mysql Slave群切换Master

Mysql测试一:Mysql Slave群切换Master

WBOY
WBOYOriginal
2016-06-07 16:31:271550Durchsuche

测试环境: Type OS Mysql Master rhel3.5 5.1.22-rc-log Slave1 rhel3.5 5.1.22-rc-log Slave2 rhel4.4 5.1.22-rc-log 切换测试过程是:1) Master down 2) Slave1 切换成新的Master 3) Slave2 更换Master配置为原Slave1 详细过程如下: 1、从slave(slave1

测试环境:

Type OS Mysql

Master rhel3.5 5.1.22-rc-log

Slave1 rhel3.5 5.1.22-rc-log

Slave2 rhel4.4 5.1.22-rc-log

切换测试过程是:1) Master down

2) Slave1 切换成新的Master

3) Slave2 更换Master配置为原Slave1

详细过程如下:

1、从slave(slave1)群众中选定一个slave,准备钱换成master;

2、检查slave1的复制状态:

mysql> SHOW PROCESSLIST ;
+—-+————-+———–+——+———+————+———————————————————————–+——————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+————-+———–+——+———+————+———————————————————————–+——————+
| 1 | system user | | NULL | Connect | 54733 | Waiting for master to send event | NULL |
| 2 | system user | | NULL | Connect | 4294965772 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 8 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+—-+————-+———–+——+———+————+———————————————————————–+——————+

这里主要是检测Slave1是否已经应用完从Master读取过来的在relay log中的操作,如果未应用完不能stop slave,否则数据肯定会有丢失。

3、停止slave1的slave进程,并reset称master:

mysql> STOP SLAVE ;
Query OK, 0 rows affected (0.00 sec)

mysql> RESET MASTER;
Query OK, 0 rows affected, 8 warnings (0.02 sec)

4、将slave 群中的其他slave(slave2)的Master切换成新的master(由原slave1reset成的):

1) 停slave进程:
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
2) 更换master:
mysql> CHANGE MASTER TO
-> MASTER_HOST=’10.0.65.106′,
-> MASTER_USER=’repl’,
-> MASTER_PASSWORD=’slavepass’
-> ;
Query OK, 0 rows affected (0.00 sec)
3) 开启slave:
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

5、检查slave的状态:

mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.0.65.106
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 106
Relay_Log_File: oindeve-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.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: 106
Relay_Log_Space: 408
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:
1 row in set (0.00 sec)

6、最后变换实际数据监测新的复制是否能成功进行:

1) 在新的Master创建测试表:

mysql> create table t3 as select * from test;
Query OK, 100003 rows affected (0.11 sec)
Records: 100003 Duplicates: 0 Warnings: 0

mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| t1 |
| t2 |
| t3 |
| test |
+—————-+
4 rows in set (0.00 sec)

mysql> select count(*) from t3;
+———-+
| count(*) |
+———-+
| 100003 |
+———-+
1 row in set (0.00 sec)
2) 在slave2上面看是否已经复制过去:

mysql> show tables;
+—————-+
| Tables_in_test |
+—————-+
| t1 |
| t2 |
| t3 |
| test |
+—————-+
4 rows in set (0.00 sec)

mysql> select count(*) from t3;
+———-+
| count(*) |
+———-+
| 100003 |
+———-+
1 row in set (0.00 sec)

7、到此确认复制正常,master切换完成。

注:整个切换测试过程时间较短,大家从每一步操作后面反馈的执行时间也可以看出,所需要的操作步骤也不太多。但是此测试并不是数据库整体环境在提供服务的压力环境下所测试进行的,该过程数据库整体环境较为空闲,所以目前还不敢确保在压力环境下也会如此的顺利,等后面还会找机会在有应用压力的情况下再测试。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn