mycat部署安装配置

Mycat关键特性

关键特性

支持SQL92标准支持MySQL、Oracle、DB2、SQL Server、PostgreSQL等DB的常见SQL语法遵守Mysql原生协议,跨语言,跨平台,跨数据库的通用中间件代理。基于心跳的自动故障切换,支持读写分离,支持MySQL主从,以及galera cluster集群。支持Galera for MySQL集群,Percona Cluster或者MariaDB cluster基于Nio实现,有效管理线程,解决高并发问题。支持数据的多片自动路由与聚合,支持sum,count,max等常用的聚合函数,支持跨库分页。支持单库内部任意join,支持跨库2表join,甚至基于caltlet的多表join。支持通过全局表,ER关系的分片策略,实现了高效的多表join查询。支持多租户方案。支持分布式事务(弱xa)。支持XA分布式事务(1.6.5)。支持全局序列号,解决分布式下的主键生成问题。分片规则丰富,插件化开发,易于扩展。强大的web,命令行监控。支持前端作为MySQL通用代理,后端JDBC方式支持Oracle、DB2、SQL Server 、 mongodb 、巨杉。支持密码加密支持服务降级支持IP白名单支持SQL黑名单、sql注入攻击拦截支持prepare预编译指令(1.6)支持非堆内存(Direct Memory)聚合计算(1.6)支持PostgreSQL的native协议(1.6)支持mysql和oracle存储过程,out参数、多结果集返回(1.6)支持zookeeper协调主从切换、zk序列、配置zk化(1.6)支持库内分表(1.6)集群基于ZooKeeper管理,在线升级,扩容,智能优化,大数据处理(2.0开发版)。

什么是MYCAT

一个彻底开源的,面向企业应用开发的大数据库集群支持事务、ACID、可以替代MySQL的加强版数据库一个可以视为MySQL集群的企业级数据库,用来替代昂贵的Oracle集群一个融合内存缓存技术、NoSQL技术、HDFS大数据的新型SQL Server结合传统数据库和新型分布式数据仓库的新一代企业级数据库产品一个新颖的数据库中间件产品

MYCAT监控

支持对Mycat、Mysql性能监控支持对Mycat的JVM内存提供监控服务支持对线程的监控支持对操作系统的CPU、内存、磁盘、网络的监控


1. mycat是怎样实现分库分表的?

mycat里面通过定义路由规则来实现分片表(路由规则里面会定义分片字段,以及分片算法)。分片算法有多种,你所说的hash是其中一种,还有取模、按范围分片等等。在mycat里面,会对所有传递的sql语句做路由处理(路由处理的依据就是表是否分片,如果分片,那么需要依据分片字段和对应的分片算法来判断sql应该传递到哪一个、或者哪几个、又或者全部节点去执行)

2. mycat适用于哪些场景?相对于海量存储的Nosql的适用场景又如何?

数据量大到单机hold不住,而又不希望调整架构切换为NoSQL数据库,这个场景下可以考虑适用mycat。当然,使用前也应该做规划,哪些表需要分片等等。另外mycat对跨库join的支持不是很好,在使用mycat的时候要注意规避这种场景。


安装 java-1.8.0-openjdk-devel 下载解压Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-mac.tar.gz    //这里可以下载

[root@mhaserver30 ~]# vim /usr/local/mycat/conf/schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">


    <schema name="mydb" checkSQLschema="false" sqlMaxLimit="100" 


dataNode="dn1">
        </schema>
        <dataNode dataHost="localhost1" database="mydb" name="dn1"/>
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="3"
              writeType="0" dbType="mysql" dbDriver="native" 


switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <!-- can have multi write hosts -->
        <writeHost host="hostMaster" url="192.168.1.20:3306"
user="tom" 


password="123123">
            <!-- can have multi read hosts -->


            <readHost host="hostS2" url="192.168.1.22:3306" user="read" 


password="123123" />


            <readHost host="hostS2" url="192.168.1.23:3306" user="read" 


password="123123" />
        </writeHost>
    </dataHost>

</mycat:schema>

-------

[root@mhaserver30 ~]# vim /usr/local/mycat/conf/server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
    - you may not use this file except in compliance with the License. - You 
    may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
    - - Unless required by applicable law or agreed to in writing, software - 
    distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
    License for the specific language governing permissions and - limitations 
    under the License. -->
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
    <system>
    <property name="useSqlStat">0</property>  <!-- 1为开启实时统计、0为关闭 -->
    <property name="useGlobleTableCheck">0</property>  <!-- 1为开启全加班一致性检测、0为关闭 -->


        <property name="sequnceHandlerType">2</property>
      <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
        <!--  <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
    <!-- <property name="processorBufferChunk">40960</property> -->
    <!-- 
    <property name="processors">1</property> 
    <property name="processorExecutor">32</property> 
     -->
        <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
        <property name="processorBufferPoolType">0</property>
        <!--默认是65535 64K 用于sql解析时最大文本长度 -->
        <!--<property name="maxStringLiteralLength">65535</property>-->
        <!--<property name="sequnceHandlerType">0</property>-->
        <!--<property name="backSocketNoDelay">1</property>-->
        <!--<property name="frontSocketNoDelay">1</property>-->
        <!--<property name="processorExecutor">16</property>-->
        <!--
            <property name="serverPort">8066</property> <property name="managerPort">9066</property> 
            <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property> 
            <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
        <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
        <property name="handleDistributedTransactions">0</property>


            <!--
            off heap for merge/order/group/limit      1开启   0关闭
        -->
        <property name="useOffHeapForMerge">1</property>


        <!--
            单位为m
        -->
        <property name="memoryPageSize">1m</property>


        <!--
            单位为k
        -->
        <property name="spillsFileBufferSize">1k</property>


        <property name="useStreamOutput">0</property>


        <!--
            单位为m
        -->
        <property name="systemReserveMemorySize">384m</property>
        <!--是否采用zookeeper协调切换  -->
        <property name="useZKSwitch">true</property>
    </system>
    <!-- 全局SQL防火墙设置 -->
    <!-- 
    <firewall> 
       <whitehost>
          <host host="127.0.0.1" user="mycat"/>
          <host host="127.0.0.2" user="mycat"/>
       </whitehost>
       <blacklist check="false">
       </blacklist>
    </firewall>
    -->


    <user name="root">
        <property name="password">123456</property>
        <property name="schemas">mydb</property>


        <!-- 表级 DML 权限设置 -->
        <!--        
        <privileges check="false">
            <schema name="TESTDB" dml="0110" >
                <table name="tb01" dml="0000"></table>
                <table name="tb02" dml="1111"></table>
            </schema>
        </privileges>       
         -->
    </user>
    <user name="user">
        <property name="password">user</property>
        <property name="schemas">mydb</property>
        <property name="readOnly">true</property>
    </user>

</mycat:server>

~                       

-------

[root@mhaserver30 ~]# /usr/local/mycat/bin/mycat --help

Usage: /usr/local/mycat/bin/mycat { console | start | stop | restart | status | dump }

[root@mhaserver30 ~]# /usr/local/mycat/bin/mycat start

[root@mhaserver30 ~]# ss -anplut | grep :
Netid  State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
udp    UNCONN     0      0      127.0.0.1:323                   *:*                   users:(("chronyd",pid=482,fd=1))
tcp    LISTEN     0      1      127.0.0.1:32000                 *:*                   users:(("java",pid=1698,fd=4))
tcp    LISTEN     0      128       *:10022                 *:*                   users:(("sshd",pid=647,fd=3))
tcp    LISTEN     0      50       :::32924                :::*                   users:(("java",pid=1698,fd=58))
tcp    LISTEN     0      50       :::1984                 :::*                   users:(("java",pid=1698,fd=55))
tcp    LISTEN     0      100      :::8066                 :::*                   users:(("java",pid=1698,fd=78))
tcp    LISTEN     0      50       :::43074                :::*                   users:(("java",pid=1698,fd=54))

tcp    LISTEN     0      100      :::9066                 :::*                   users:(("java",pid=1698,fd=74))

-----在另一台机上测试

mhaserver30 :192.168.1.30

pc1:192.168.1.254

[root@pc1 ~]# mysql -h192.168.1.30 -P8066 -uroot -p123456 -e 'use mydb;insert into bb values(32);'

[root@room9pc01 ~]# mysql -h192.168.1.30 -P8066 -uroot -p123456 -e 'use mydb;show tables;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+----------------+
| Tables_in_mydb |
+----------------+
| aaaa           |
| bb             |
| myscript       |
| myusers        |

+----------------+

-----完成 ,要测试,可以在/etc/my.cnf上开启log日志,然后分别写和读看在哪台机上运行了。

猜你喜欢

转载自blog.csdn.net/cbuy888/article/details/81042235
今日推荐