mycat配置主从复制,读写分离,分库分表

妖狐艹你老母 2021-10-19 07:42 471阅读 0赞

1.server.xml中文件配置完整内容

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- - - Licensed under the Apache License, Version 2.0 (the "License");
  3. - you may not use this file except in compliance with the License. - You
  4. may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
  5. - - Unless required by applicable law or agreed to in writing, software -
  6. distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
  7. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
  8. License for the specific language governing permissions and - limitations
  9. under the License. -->
  10. <!DOCTYPE mycat:server SYSTEM "server.dtd">
  11. <mycat:server xmlns:mycat="http://io.mycat/">
  12. <system>
  13. <property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->
  14. <property name="useHandshakeV10">1</property>
  15. <property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->
  16. <property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
  17. <property name="sqlExecuteTimeout">300</property> <!-- SQL 执行超时 单位:秒-->
  18. <property name="sequnceHandlerType">0</property> <!--配置为0表示使用本地文件读取。 配置为1表示从数据库表中读取 配置为2表示时间戳方式-->
  19. <!--<property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>-->
  20. <!--必须带有MYCATSEQ_或者 mycatseq_进入序列匹配流程 注意MYCATSEQ_有空格的情况-->
  21. <property name="sequnceHandlerPattern">(?:(\s*next\s+value\s+for\s*MYCATSEQ_(\w+))(,|\)|\s)*)+</property>
  22. <property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->
  23. <!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
  24. <!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
  25. <!-- <property name="processorBufferChunk">40960</property> -->
  26. <!--
  27. <property name="processors">1</property>
  28. <property name="processorExecutor">32</property>
  29. -->
  30. <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
  31. <property name="processorBufferPoolType">0</property>
  32. <!--默认是65535 64K 用于sql解析时最大文本长度 -->
  33. <!--<property name="maxStringLiteralLength">65535</property>-->
  34. <!--<property name="sequnceHandlerType">0</property>-->
  35. <!--<property name="backSocketNoDelay">1</property>-->
  36. <!--<property name="frontSocketNoDelay">1</property>-->
  37. <!--<property name="processorExecutor">16</property>-->
  38. <!--
  39. <property name="serverPort">8066</property> <property name="managerPort">9066</property>
  40. <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>
  41. <property name="dataNodeIdleCheckPeriod">300000</property> 5 * 60 * 1000L; //连接空闲检查
  42. <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
  43. <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
  44. <property name="handleDistributedTransactions">0</property>
  45. <!--
  46. off heap for merge/order/group/limit 1开启 0关闭
  47. -->
  48. <property name="useOffHeapForMerge">0</property>
  49. <!--
  50. 单位为m
  51. -->
  52. <property name="memoryPageSize">64k</property>
  53. <!--
  54. 单位为k
  55. -->
  56. <property name="spillsFileBufferSize">1k</property>
  57. <property name="useStreamOutput">0</property>
  58. <!--
  59. 单位为m
  60. -->
  61. <property name="systemReserveMemorySize">384m</property>
  62. <!--是否采用zookeeper协调切换 -->
  63. <property name="useZKSwitch">false</property>
  64. <!-- XA Recovery Log日志路径 -->
  65. <!--<property name="XARecoveryLogBaseDir">./</property>-->
  66. <!-- XA Recovery Log日志名称 -->
  67. <!--<property name="XARecoveryLogBaseName">tmlog</property>-->
  68. <!--如果为 true的话 严格遵守隔离级别,不会在仅仅只有select语句的时候在事务中切换连接-->
  69. <property name="strictTxIsolation">false</property>
  70. <property name="useZKSwitch">true</property>
  71. </system>
  72. <!-- 全局SQL防火墙设置 -->
  73. <!--白名单可以使用通配符%或着*-->
  74. <!--例如<host host="127.0.0.*" user="root"/>-->
  75. <!--例如<host host="127.0.*" user="root"/>-->
  76. <!--例如<host host="127.*" user="root"/>-->
  77. <!--例如<host host="1*7.*" user="root"/>-->
  78. <!--这些配置情况下对于127.0.0.1都能以root账户登录-->
  79. <!--
  80. <firewall>
  81. <whitehost>
  82. <host host="1*7.0.0.*" user="root"/>
  83. </whitehost>
  84. <blacklist check="false">
  85. </blacklist>
  86. </firewall>
  87. -->
  88. <user name="mycat" defaultAccount="true">
  89. <property name="password">123456</property>
  90. <property name="schemas">mycatdb</property>
  91. <!-- 表级 DML 权限设置 -->
  92. <!--
  93. <privileges check="false">
  94. <schema name="TESTDB" dml="0110" >
  95. <table name="tb01" dml="0000"></table>
  96. <table name="tb02" dml="1111"></table>
  97. </schema>
  98. </privileges>
  99. -->
  100. </user>
  101. <user name="user">
  102. <property name="password">user</property>
  103. <property name="schemas">mycatdb</property>
  104. <property name="readOnly">true</property>
  105. </user>
  106. </mycat:server>

2.schema.xml文件完整内容

  1. <?xml version="1.0"?>
  2. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  3. <mycat:schema xmlns:mycat="http://io.mycat/">
  4. <schema name="mycatdb" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
  5. <!-- 实现分库分表 -->
  6. <!-- 订单表数据量太大,有千万条数据,需要水平切分,原来这个表在t_order1现在将数据 切分到t_order2,t_order3 -->
  7. <!-- rule配置在rule.xml文件中配置 -->
  8. <table name="t_order" primaryKey="id" dataNode="dn1,dn2,dn3" rule="mod-long"/>
  9. </schema>
  10. <!-- springdb,springdc,springdd是同一个服务器的 三张表 ,需要先在一个mysql服务器建立好 -->
  11. <dataNode name="dn1" dataHost="localhost1" database="springdb" />
  12. <dataNode name="dn2" dataHost="localhost1" database="springdc" />
  13. <dataNode name="dn3" dataHost="localhost1" database="springdd" />
  14. <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1"
  15. writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
  16. <heartbeat>select user()</heartbeat>
  17. <!-- can have multi write hosts -->
  18. <!-- 里面用的是双主双从 hostM132,hostM134是双主两个可以互相复制 hostS133,host135是从,分别复制 hostM132,hostM134主机的数据-->
  19. <writeHost host="hostM132" url="192.168.72.132:3306" user="root" password="123456">
  20. <!-- can have multi read hosts -->
  21. <readHost host="hostM134" url="192.168.72.134:3306" user="root" password="123456" />
  22. <readHost host="hostS133" url="192.168.72.133:3306" user="root" password="123456" />
  23. </writeHost>
  24. <writeHost host="hostM134" url="localhost:3316" user="root" password="123456" >
  25. <readHost host="hostM132" url="192.168.72.132:3306" user="root" password="123456" />
  26. <readHost host="hostS135" url="192.168.72.135:3306" user="root" password="123456" />
  27. </writeHost>
  28. </dataHost>
  29. </mycat:schema>

发表评论

表情:
评论列表 (有 0 条评论,471人围观)

还没有评论,来说两句吧...

相关阅读