中间件mycat入门(一):部署与介绍

初期测试过程中,原本采用kingshard中作为中间件的项目,但在测试的过程中,发现了不支持不同分表的join,只能选择放弃,改成mycat做测试

下载地址为

[root@gzsd-ks01-101110214 download]# wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20171117203123-linux.tar.gz
[root@gzsd-ks01-101110214 download]# tar xvf Mycat-server-1.6.5-release-20171117203123-linux.tar.gz 
  • 需要有java的支持,这里直接使用yum进行安装
[root@gzsd-ks01-101110214 mycat]# yum -y install java
  • 将解压的目录放到标准目录中
[root@gzsd-ks01-101110214 download]# mv mycat /usr/local/
  • 查看对应的目录树
[root@gzsd-ks01-101110214 download]# tree /usr/local/mycat/
/usr/local/mycat/
├── bin
│   ├── dataMigrate.sh
│   ├── init_zk_data.sh
│   ├── mycat
│   ├── rehash.sh
│   ├── startup_nowrap.sh
│   ├── wrapper-linux-ppc-64
│   ├── wrapper-linux-x86-32
│   └── wrapper-linux-x86-64
├── catlet
├── conf
│   ├── autopartition-long.txt
│   ├── auto-sharding-long.txt
│   ├── auto-sharding-rang-mod.txt
│   ├── cacheservice.properties
│   ├── dbseq.sql
│   ├── ehcache.xml
│   ├── index_to_charset.properties
│   ├── log4j2.xml
│   ├── migrateTables.properties
│   ├── myid.properties
│   ├── partition-hash-int.txt
│   ├── partition-range-mod.txt
│   ├── rule.xml
│   ├── schema.xml
│   ├── sequence_conf.properties
│   ├── sequence_db_conf.properties
│   ├── sequence_distributed_conf.properties
│   ├── sequence_time_conf.properties
│   ├── server.xml
│   ├── sharding-by-enum.txt
│   ├── wrapper.conf
│   ├── zkconf
│   │   ├── autopartition-long.txt
│   │   ├── auto-sharding-long.txt
│   │   ├── auto-sharding-rang-mod.txt
│   │   ├── cacheservice.properties
│   │   ├── ehcache.xml
│   │   ├── index_to_charset.properties
│   │   ├── partition-hash-int.txt
│   │   ├── partition-range-mod.txt
│   │   ├── rule.xml
│   │   ├── schema.xml
│   │   ├── sequence_conf.properties
│   │   ├── sequence_db_conf.properties
│   │   ├── sequence_distributed_conf-mycat_fz_01.properties
│   │   ├── sequence_distributed_conf.properties
│   │   ├── sequence_time_conf-mycat_fz_01.properties
│   │   ├── sequence_time_conf.properties
│   │   ├── server-mycat_fz_01.xml
│   │   ├── server.xml
│   │   └── sharding-by-enum.txt
│   └── zkdownload
│       └── auto-sharding-long.txt
├── lib
│   ├── asm-4.0.jar
│   ├── commons-collections-3.2.1.jar
│   ├── commons-lang-2.6.jar
│   ├── curator-client-2.11.0.jar
│   ├── curator-framework-2.11.0.jar
│   ├── curator-recipes-2.11.0.jar
│   ├── disruptor-3.3.4.jar
│   ├── dom4j-1.6.1.jar
│   ├── druid-1.0.26.jar
│   ├── ehcache-core-2.6.11.jar
│   ├── fastjson-1.2.12.jar
│   ├── guava-19.0.jar
│   ├── hamcrest-core-1.3.jar
│   ├── hamcrest-library-1.3.jar
│   ├── jline-0.9.94.jar
│   ├── joda-time-2.9.3.jar
│   ├── jsr305-2.0.3.jar
│   ├── kryo-2.10.jar
│   ├── leveldb-0.7.jar
│   ├── leveldb-api-0.7.jar
│   ├── libwrapper-linux-ppc-64.so
│   ├── libwrapper-linux-x86-32.so
│   ├── libwrapper-linux-x86-64.so
│   ├── log4j-1.2.17.jar
│   ├── log4j-1.2-api-2.5.jar
│   ├── log4j-api-2.5.jar
│   ├── log4j-core-2.5.jar
│   ├── log4j-slf4j-impl-2.5.jar
│   ├── mapdb-1.0.7.jar
│   ├── minlog-1.2.jar
│   ├── mongo-java-driver-2.11.4.jar
│   ├── Mycat-server-1.6.5-release.jar
│   ├── mysql-binlog-connector-java-0.6.0.jar
│   ├── mysql-connector-java-5.1.35.jar
│   ├── netty-3.7.0.Final.jar
│   ├── netty-buffer-4.1.9.Final.jar
│   ├── netty-common-4.1.9.Final.jar
│   ├── objenesis-1.2.jar
│   ├── reflectasm-1.03.jar
│   ├── sequoiadb-driver-1.12.jar
│   ├── slf4j-api-1.6.1.jar
│   ├── univocity-parsers-2.2.1.jar
│   ├── velocity-1.7.jar
│   ├── wrapper.jar
│   └── zookeeper-3.4.6.jar
├── logs
│   └── wrapper.log
└── version.txt

7 directories, 96 files
  • 设置环境变量
[root@gzsd-ks01-101110214 download]# vim /etc/profile
MYCAT_HOME=/usr/local/mycat
[root@gzsd-ks01-101110214 download]# source /etc/profile
  • 修改server.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/server.xml 
 


<mycat:server xmlns:mycat="http://io.mycat/">
    <system>
    <property name="nonePasswordLogin">0property> 
    <property name="useHandshakeV10">1property>
    <property name="useSqlStat">1property>  
    <property name="useGlobleTableCheck">0property>  

        <property name="sequnceHandlerType">2property>
    <property name="subqueryRelationshipCheck">falseproperty> 
       
         
    
    
        
        <property name="processorBufferPoolType">0property>
        
        <property name="maxStringLiteralLength">65535property>
        <property name="sequnceHandlerType">0property>
        <property name="backSocketNoDelay">1property>
        <property name="frontSocketNoDelay">1property>
        
        
        
        <property name="handleDistributedTransactions">0property>

            
        <property name="useOffHeapForMerge">1property>

        
        <property name="memoryPageSize">64kproperty>

        
        <property name="spillsFileBufferSize">1kproperty>

        <property name="useStreamOutput">0property>

        
        <property name="systemReserveMemorySize">384mproperty>


        
        <property name="useZKSwitch">falseproperty>

        
        

        
        

    system>

    
    
    
    
    
    
    
    

    <user name="root" defaultAccount="true">
        <property name="password">123456property>
        <property name="schemas">wms_output_0000property>

        
        
    user>

    <user name="user">
        <property name="password">userproperty>
        <property name="schemas">wms_output_0000property>
        <property name="readOnly">trueproperty>
    user>

mycat:server>
  • 修改schema.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/schema.xml 


<mycat:schema xmlns:mycat="http://io.mycat/">

    <schema name="wms_output_0000" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
            <table name="wmp_so_package" primaryKey="id" autoIncrement="true" subTables="wmp_so_package$1-128" type="global" dataNode="dn1" rule="mod-long" />
            <table name="wmp_sale_order" primaryKey="id" autoIncrement="true" subTables="wmp_sale_order$1-128" type="global" dataNode="dn1" rule="mod-long" />
    schema>
    <dataNode name="dn1" dataHost="cluster1" database="wms_output_0000" />
    <dataHost name="cluster1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()heartbeat>
        <writeHost host="hostM1" url="10.11.10.215:3306" user="gz_mycat_account"  password="alo!7TTg@123">
        <readHost host="hostS1" url="10.11.10.216:3306" user="gz_mycat_account" password="alo!7TTg@123" />
        writeHost>
    dataHost>
mycat:schema>
  • 修改rule.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/rule.xml 



<mycat:rule xmlns:mycat="http://io.mycat/">
    <tableRule name="mod-long">
        <rule>
            <columns>idcolumns>
            <algorithm>mod-longalgorithm>
        rule>
    tableRule>

    <function name="mod-long" class="io.mycat.route.function.PartitionByMod">
        
        <property name="count">128property>
    function>

mycat:rule>

  • 启动
[root@gzsd-ks01-101110214 download]# cd $MYCAT_HOME 
[root@gzsd-ks01-101110214 mycat]# ./bin/mycat start
Starting Mycat-server...
  • 查看端口
[root@gzsd-ks01-101110214 mycat]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      878/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1349/master         
tcp        0      0 127.0.0.1:32000         0.0.0.0:*               LISTEN      12104/java          
tcp6       0      0 :::9066                 :::*                    LISTEN      12104/java          
tcp6       0      0 :::16305                :::*                    LISTEN      12104/java          
tcp6       0      0 :::22                   :::*                    LISTEN      878/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1349/master         
tcp6       0      0 :::42620                :::*                    LISTEN      12104/java          
tcp6       0      0 :::1984                 :::*                    LISTEN      12104/java          
tcp6       0      0 :::8066                 :::*                    LISTEN      12104/java   

配置完成后,即可使用客户端工具连接进行操作。
启动之前,需要明确的一个点就是,指定的库和指定的分表个数,一定要先在DB上创建了先。schema.xml和rule分别对应,在这里,有两个分表,分表均为128张表,即

分表 数目 说明
wmp_so_package wms_output_0000 128 schema.xml配置
wmp_sale_order wms_output_0000 128 schema.xml配置

启动的时候,可能会碰到如下问题

FATAL  | wrapper  | 2017/12/05 17:21:16 | There were 5 failed launches in a row, each lasting less than 300 seconds.  Giving up.
FATAL  | wrapper  | 2017/12/05 17:21:16 |   There may be a configuration problem: please check the logs.
STATUS | wrapper  | 2017/12/05 17:21:16 | <-- Wrapper Stopped

出现这种问题的解决办法是在hosts中加入对应的信息
中间件mycat入门(一):部署与介绍_第1张图片
如果还有其他问题,则可以打开debug进行查证
中间件mycat入门(一):部署与介绍_第2张图片

你可能感兴趣的:(MySQL中间件)