再加一个读写分离配置即可,配置上m2 s2 注意IP别写错;
<dataHost name="host1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="172.20.0.2:3306" user="root"
password="123456">
<readHost host="hostS1" url="172.20.0.3:3306" user="root"
password="123456"/>
</writeHost>
<writeHost host="hostM2" url="172.20.0.5:3306" user="root"
password="123456">
<readHost host="hostS2" url="172.20.0.6:3306" user="root"
password="123456"/>
</writeHost>
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>
以及balance要搞成1 现在是双主双从;
balance="1",全部的 readHost 与 stand by writeHost 参与 select 语句的负载均衡,简单的说,当双主双从模式(M1->S1,M2->S2,并且 M1 与 M2 互为主备),正常情况下,M2,S1,S2 都参与 select 语句的负载均衡。
上一篇:m1和m2配置互为主从复制