写一份mycat双主双从server.xml的配置文件
时间: 2024-02-02 17:11:45 浏览: 127
以下是一个简单的MyCat双主双从的server.xml配置文件示例:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<property name="user">mycat</property>
<property name="password">mycat</property>
<property name="useSqlStat">true</property>
<property name="useGlobleTableCheck">false</property>
</system>
<user name="mycat">
<property name="password">mycat</property>
<property name="schemas">db1,db2,db3</property>
</user>
<dataHost name="master1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db1" user="root" password="root">
<readHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db1" user="root" password="root" />
</writeHost>
<writeHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db2" user="root" password="root">
<readHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db2" user="root" password="root" />
</writeHost>
</dataHost>
<dataHost name="master2" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db3" user="root" password="root">
<readHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db3" user="root" password="root" />
</writeHost>
<writeHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db4" user="root" password="root">
<readHost host="127.0.0.1" url="jdbc:mysql://127.0.0.1:3306/db4" user="root" password="root" />
</writeHost>
</dataHost>
<dataNode name="dn1" dataHost="master1" database="db1" />
<dataNode name="dn2" dataHost="master1" database="db2" />
<dataNode name="dn3" dataHost="master2" database="db3" />
<dataNode name="dn4" dataHost="master2" database="db4" />
<tableRule name="rule1">
<rule>
<columns>id</columns>
<algorithm>hash</algorithm>
</rule>
<dataSource name="ds1">
<rule>
<table name="table1" dataNode="dn1,dn2" />
<table name="table2" dataNode="dn1,dn2" />
</rule>
</dataSource>
<dataSource name="ds2">
<rule>
<table name="table3" dataNode="dn3,dn4" />
<table name="table4" dataNode="dn3,dn4" />
</rule>
</dataSource>
</tableRule>
</mycat:server>
```
这个文件定义了两个数据主机(master1和master2),每个主机都有两个写主机和两个读主机。每个数据主机有两个数据节点(dn1,dn2,dn3,dn4),每个数据节点对应一个具体的数据库。最后,还定义了一个名为“rule1”的表规则,将不同的数据表分配到不同的数据源中。
阅读全文