mycat读写分离

一、mycat安装mysql

mycat安装依赖jdk,因此要先安装jdk。linux

mycat官网:http://www.mycat.io/sql

下载:http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz数据库

下载到/usr/local/src/目录express

wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gzapache

解压:tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gzapp

解压后的目录移动到/usr/local/: mv mycat   /usr/local/负载均衡

二、配置less

进入/usr/local/mycat/conf/目录测试

备份schema.xml和server.xml

cp schema.xml schema.xml.bak

cp server.xml server.xml.bak

schema.xml配置后内容以下:

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

   <!-- 定义MyCat的逻辑库 -->
   <schema name="pcx_schema" checkSQLschema="false" sqlMaxLimit="100" dataNode="pcxNode"></schema>

   <!-- 定义MyCat的数据节点 -->
   <dataNode name="pcxNode" dataHost="dtHost" database="foo"/>

   <!-- 定义数据主机dtHost,连接到MySQL读写分离集群,schema中的每个dataHost中的host属性值必须惟一
        dataHost实际上配置的就是后台的数据库集群,一个dataHost表明一个数据库集群
        balance=“1”,所有的readHost与stand by writeHost参与select语句的负载均衡
        writeType=“0”,全部写操做发送到配置的第一个writeHost,这里就是咱们的hostmaster, 第一个挂了切到还生存的第二个writeHost -->

   <dataHost name="dtHost" maxCon="500" minCon="20" balance="3" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
      <!-- 心跳检测 -->
      <heartbeat>show slave status</heartbeat>

      <!-- 配置后台数据库的IP地址和端口号,还有帐号密码-->
      <writeHost host="hostMaster" url="172.16.125.133:3306" user="foo" password="foo123" >
         <readHost host="hostSlave" url="172.16.125.134:3306" user="foo" password="foo123"/>
      </writeHost>
      <!-- <writeHost host="hostSlave" url="172.16.125.134:3306" user="foo" password="foo123" /> -->
   </dataHost>
</mycat:schema>

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>
      <!-- 这里配置的都是一些系统属性,能够本身查看mycat文档 -->
      <!-- <property name="defaultSqlParser">druidparser</property>
      <property name="charset">utf8mb4</property> -->
   </system>


   <!-- 用户1,对应的MyCat逻辑库链接到的数据节点对应的主机为主从复制集群 -->
    <user name="user1">
        <property name="password">root</property>
        <property name="schemas">pcx_schema</property>
    </user>

    <!-- 用户2,只读权限 -->
    <user name="user2">
        <property name="password">root</property>
        <property name="schemas">pcx_schema</property>
        <property name="readOnly">true</property>
    </user>
</mycat:server>

三、测试

启动mycat, 进入目录/usr/local/mycat/bin

./mycat start

查看是否启动成功 lsof -i:8066

相关文章
相关标签/搜索