首页 > 课堂 > 基础知识 > 正文

Cento7.4安置mycat和mycat-eye

2024-09-12 20:30:01
字体:
来源:转载
供稿:网友
       前提:
       环境要求已安装JDK1.7+版本
       已安装mysql客户端(yum install mysql)
       操作系统IP:192.168.75.48
       安装mycat
       下载解压
 
wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
tar -zxvf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz -C /usr/local/
cd /usr/local/mycat/conf
根据实际情况修改schema.xml,server.xml
例如:
schema.xml:
 
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
     <!-- phapp 是mycat的逻辑库名称,链接需要用的 -->
    <schema name="xx_app" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>
    <schema name="xx_data" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn2"></schema>
    <schema name="xx_dubbo_monitor" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn3"></schema>
    <schema name="xx_log" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn4"></schema>
    <schema name="xx_mis" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn5"></schema>
    <schema name="xx_task" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn6"></schema>
        <!-- database 是MySQL数据库的库名 -->
 
    <dataNode name="dn1" dataHost="192.168.75.94" database="xx_app" />
    <dataNode name="dn2" dataHost="192.168.75.94" database="xx_data" />
    <dataNode name="dn3" dataHost="192.168.75.94" database="xx_dubbo_monitor" />
    <dataNode name="dn4" dataHost="192.168.75.94" database="xx_log" />
    <dataNode name="dn5" dataHost="192.168.75.94" database="xx_mis" />
    <dataNode name="dn6" dataHost="192.168.75.94" database="xx_task" />
    <!--
    dataNode节点中各属性说明:
    name:指定逻辑数据节点名称;
    dataHost:指定逻辑数据节点物理主机节点名称;
    database:指定物理主机节点上。如果一个节点上有多个库,可使用表达式db$0-99,     表示指定0-99这100个数据库;
 
    dataHost 节点中各属性说明:
        name:物理主机节点名称;
        maxCon:指定物理主机服务最大支持1000个连接;
        minCon:指定物理主机服务最小保持10个连接;
        writeType:指定写入类型;
            0,只在writeHost节点写入;
            1,在所有节点都写入。慎重开启,多节点写入顺序为默认写入根据配置顺序,第一个挂掉切换另一个;
        dbType:指定数据库类型;
        dbDriver:指定数据库驱动;
        balance:指定物理主机服务的负载模式。
            0,不开启读写分离机制;
            1,全部的readHost与stand by writeHost参与select语句的负载均衡,简单的说,当双主双从模式(M1->S1,M2->S2,并且M1与 M2互为主备),正常情况下,M2,S1,S2都参与select语句的负载均衡;
            2,所有的readHost与writeHost都参与select语句的负载均衡,也就是说,当系统的写操作压力不大的情况下,所有主机都可以承担负载均衡;
-->
    <dataHost name="192.168.75.94" maxCon="1000" minCon="10" balance="3" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>show slave status</heartbeat>
        <!-- 可以配置多个主从 -->
        <writeHost host="hostM1" url="192.168.75.94:3306" user="xx_Corn_User" password="xxxxxxxx">
            <!-- 可以配置多个从库 -->
            <readHost host="hostS1" url="192.168.75.95:3306" user="xx_Corn_User" password="xxxxxxxx" />
        </writeHost>
    </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>
    <property name="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->
    <property name="useHandshakeV10">1</property>
    <property name="useSqlStat">1</property>  <!-- 1为开启实时统计、0为关闭 -->
    <property name="useGlobleTableCheck">0</property>  <!-- 1为开启全加班一致性检测、0为关闭 -->
 
        <property name="sequnceHandlerType">2</property>
    <property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->
      <!--  <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 | type 2 NettyBufferPool -->
        <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">64k</property>
        <!--
            单位为k
        -->
        <property name="spillsFileBufferSize">1k</property>
        <property name="useStreamOutput">0</property>
        <!--
            单位为m
        -->
        <property name="systemReserveMemorySize">384m</property>
 
        <!--是否采用zookeeper协调切换  -->
        <property name="useZKSwitch">false</property>
        <!-- XA Recovery Log日志路径 -->
        <!--<property name="XARecoveryLogBaseDir">./</property>-->
        <!-- XA Recovery Log日志名称 -->
        <!--<property name="XARecoveryLogBaseName">tmlog</property>-->
 
    </system>
 
    <!-- 全局SQL防火墙设置 -->
    <!--白名单可以使用通配符%或着*-->
    <!--例如<host host="127.0.0.*" user="root"/>-->
    <!--例如<host host="127.0.*" user="root"/>-->
    <!--例如<host host="127.*" user="root"/>-->
    <!--例如<host host="1*7.*" user="root"/>-->
    <!--这些配置情况下对于127.0.0.1都能以root账户登录-->
    <!--
    <firewall>
       <whitehost>
          <host host="1*7.0.0.*" user="root"/>
       </whitehost>
       <blacklist check="false">
       </blacklist>
    </firewall>
    -->
 
    <user name="xx_Corn_User" defaultAccount="true">
        <property name="password">xxxxxxxx</property>
        <property name="schemas">xx_app,xx_data,xx_dubbo_monitor,xx_log,xx_mis,xx_data,xx_task</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">xx_app</property>
        <property name="readOnly">true</property>
    </user>
 
</mycat:server>
修改环境变量
 
echo export PATH=$PATH:/usr/local/mycat/bin >>/etc/profile
echo export MYCAT_HOME=/usr/local/mycat >> /etc/profile
source /etc/profile
创建mycat用户
 
groupadd mycat -g 910
useradd  mycat -g 910
chown -R mycat:mycat /usr/local/mycat
启动mycat
 
cd /usr/local/mycat/bin
./mycat start
命令行登陆
mysql -u xx_Corn_User -pxxxxxx -P8066 -h 127.0.0.1
 
安装zookeeper
下载解压
 
wget  http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
tar -zxvf zookeeper-3.4.6.tar.gz -C /usr/local/
cd /usr/local/zookeeper-3.4.6/conf
cp zoo_sample.cfg zoo.cfg
启动zookeeper
 
cd /usr/local/zookeeper-3.4.6/bin/
./zkServer.sh start
安装mycat-eye
下载解压
 
wget https://raw.githubusercontent.com/MyCATApache/Mycat-download/master/mycat-web-1.0/Mycat-web-1.0-SNAPSHOT-20160617163048-linux.tar.gz
tar -zxvf Mycat-web-1.0-SNAPSHOT-20160617163048-linux.tar.gz  -C /usr/local/
修改zookeeper地址
 
cd /usr/local/mycat-web/mycat-web/WEB-INF/classes
vi mycat.properties
zookeeper=localhost:2181 ->zookeeper=127.0.0.1:2181
启动mycat-eye
 
cd /usr/local/mycat-web
./start.sh &

(编辑:武林网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表