Linux-mycat installation, configuration, use

1. Download and unzip mycat

2. Check mycat directory structure
[root @ aliyun-ecs mycat] # ll
total 24
drwxr-xr-x 2 root root 4096 Apr 18 10:28 bin
drwxrwxrwx 2 root root 4096 Oct 22 21:26 catlet
drwxrwxrwx 4 root root 4096 Feb 22:21 the conf. 9
drwxr XR-2 X-18 is the root the root on Apr 4096 10:28 lib
drwxrwxrwx the root 2 23:04 16 Jan 4096 logs the root
-rwxrwxrwx the root. 1. 9 on Feb 22:22 version.txt the root 227
than on completed structures mycat By the way, notice that mycat is developed in java language.
So installing mycat requires a jdk environment

3. Configure mycat
  3.1 Modify wrapper.conf
  [root @ aliyun-ecs mycat] # vim conf / wrapper.conf In
 informal environment, modify the following two parameters to 256M, otherwise there will be insufficient memory
 before modification:
 wrapper.java.additional.10 = -Xmx4G
 wrapper.java.additional.11 = -Xms1G
 after modification:
 wrapper.java.additional.10 = -Xmx256M
 wrapper.java.additional.11 = -Xms256M

 3.2 Configure server.xml
 [root @ aliyun-ecs mycat] # vim conf / server.xml
 add a mycat user: scwyfy
 and set the corresponding logic library: admin_db, order_db, product_db
 <user name = "scwyfy">
  <property name = "password"> 123456 </ property>
  <property name = "schemas"> admin_db , order_db, product_db </ property>
  <property name = "readOnly"> true </ property>
 </ user>


 3.3 Configure schema.xml
       configuration schema-> table-> dataNode-> dataHost-> writeHost-> readHost

 [root@aliyun-ecs mycat]# vim conf/schema.xml

 <!-name: Configure the corresponding logic library for the newly added mycat user->
 <schema name = " admin_db " checkSQLschema = "false" sqlMaxLimit = "100">
  <!-auto sharding by id (long): Conventional range 0-1k = 0 1k-10k = 1 10k-100k = 2-> 
       <!-Name: data table name->
       <!-DataNode: actual node where the data table is stored (real server + database) ->
      <table name = "travelrecord" dataNode = "dn1, dn2, dn3" rule = "auto-sharding-long" />

  <!-- global table is auto cloned to all defined data nodes ,so can join with any table whose sharding node is in the same data node -->
  <table name="company" primaryKey="ID"  type="global"  dataNode="dn1,dn2,dn3" />

  <!-random sharding using mod sharind rule->
  <table name = "hotnews" primaryKey = "ID" autoIncrement = "true" dataNode = "dn1, dn2, dn3" rule = "mod-long" />
       
        <!
       --Table data configured with contingency table relationship is stored on the same shard- > <table name = "customer" primaryKey = "ID" dataNode = "dn1, dn2" rule = "sharding-by-intfile">
     <! -Associate the customer_id of the orders table with the id of the customer table, so that when the orders table is inserted, it will first determine which shard the customer_id is on and then insert the data into the
      shard. The purpose
    of-
> <childTable name = "orders" primaryKey = "ID" joinKey = "customer_id"   parentKey = "id">      <childTable name = "order_items" joinKey = "order_id"   parentKey = "id" />
    </childTable>

    <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" />
  </table>
 </schema>

 <!--配置数据节点信息-->
 <dataNode name="dn1" dataHost="localhost1" database="db1" />
<dataNode name="dn2" dataHost="localhost1" database="db2" />
<dataNode name="dn3" dataHost="localhost1" database="db3" />

 <!-Configure database server information->
 <dataHost name = "localhost1" maxCon = "1000" minCon = "10" balance = "0"
  writeType = "0" dbType = "mysql" dbDriver = "native" switchType = "1" slaveThreshold = "100">
   <!-Used to detect heartbeat->
   <heartbeat> select user () </ heartbeat>

  <!-- can have multi write hosts :配置写库-->
  <writeHost host="hostM1" url="localhost:3306" user="root"  password="123456">
    <!-- can have multi read hosts :配置从库-->
    <readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />
  </writeHost>
</dataHost>


 

Guess you like

Origin www.cnblogs.com/yuefeng123/p/12724969.html