Mycat負載均衡型別,目前的取值有3種:
1. balance="0", 不開啟讀寫分離機制,所有讀操作都傳送到當前可用的writeHost上。
2. balance="1",全部的readHost與stand by writeHost參與select語句的負載均衡,簡單的說,當雙主雙從模式(M1->S1,M2->S2,並且M1與 M2互為主備),正常情況下,M2,S1,S2都參與select語句的負載均衡。
3. balance="2",所有讀操作都隨機的在writeHost、readhost上分發。
4. balance="3",所有讀請求隨機的分發到wiriterHost對應的readhost執行,writerHost不負擔讀壓力
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="host1" database="testdb" />
<dataHost name="host1" maxCon="1000" minCon="10" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="192.168.8.51:3306" user="slave"
password="12345678">
<readHost host="hostS1" url="192.168.8.50:3306" user="slave" password="12345678" />
</writeHost>
</dataHost>
</mycat:schema>
主從配置
192.168.8.51 (主)
server-id=1
log-bin=mysql-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-do-db=testdb
binlog_format=STATEMENT
192.168.8.50 (從)
server-id=2
relay-log=mysql-relay
192.168.8.51(主)
GRANT REPLICATION SLAVE ON *.* TO 'qiao'@'%' IDENTIFIED BY '12345678';
show master status;
192.168.8.50(從)
// 如果之前搭建過的使用 stop slave reset master
change master to master_host='192.168.8.51',master_port=3306,master_user='qiao',master_password='12345678',master_log_file='mysql-bin.000001',master_log_pos=437;
start slave;
show slave status\G;
本作品採用《CC 協議》,轉載必須註明作者和本文連結