Mysql的主从复制和级联(二)
e-do-db=db_kenyon #需要同步的库
log-slave-updates=1 #启用从库日志,这样可以设置链式复制
read-only = 1 #0表示可读写,1表示只读,但是只针对普通用户,超级用户和同步用户不受此限制
6.重启slave,并指定主机检查
mysql> change master to master_host='192.25.10.71',master_user='repl',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=120
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.25.10.71
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 120
Relay_Log_File: localhost-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: db_kenyon
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: 120
Relay_Log_Space: 120
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
调整网络和mysql参数等,使两个参数:Slave_IO_Running, Slave_SQL_Running的状态为YES
7.级联过程
其他配置如上,注意级联参数log-slave-updates开启,该参数在my.cnf里值应为1,或者
mysql> show variables like 'log_slave_%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | log_slave_updates | ON | +-------------------+-------+ 1 row in set (0.00 sec)
8.主主的过程就是主从的基础上再以从机为主机,反向操作一遍即可。简单测试,在71上建表,73、76上都能看到该表即成功。
四、级联的性能损耗测试
使用mysqlslap
[root@proxy1 bin]# ./mysqlslap --concurrency=2 --iterations=5 --number-int-cols=10 --number-char-cols=10 -a --auto-generate-sql-guid-primary --number-of-queries=10000 --auto-generate-sql-load-type=write
Benchmark
Average number of seconds to run all queries: 5.324 seconds
Minimum number of seconds to run all queries: 4.106 seconds
Maximum number of seconds to run all queries: 6.113 seconds
Number of clients running queries: 2
Average number of queries per client: 5000
每秒处理能力1878
改变concurrency,得到如下结果:
并发数
平均时间s(后者开启级联)
每秒处理
损耗
2
5.324
1878
0.6s 11%
2
5.912
1691
0.6s 11%
10
2.521
3966
0.3s 12%
10
2.828
3536
0.3s 12%
50
2.161
4627
0.2s 7%
50
2.331
4290
0.2s 7%
100
2.355
4246
0.3s 11%
100
2.618
3819
0.3s 11%