mycat主从复制读写分离

mycat主从复制读写分离

一、安装jdk环境

创建目录

mkdir /usr/local/java
cd /usr/local/java
#解压
tar -zxvf jdk-8u144-linux-x64.tar.gz

修改环境变量

vi /etc/profile
#添加
export JAVA_HOME=/usr/local/jdk1.8.0_144
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

生效

source /etc/profile

使用javac
java -version

[root@localhost java]# javac
用法: javac <options> <source files>
其中, 可能的选项包括:
  -g                         生成所有调试信息
  -g:none                    不生成任何调试信息
  -g:{lines,vars,source}     只生成某些调试信息
  ....

二、mycat

官网下载选择版本下载http://www.mycat.org.cn/
要注意对应jdk版本,这里演示版本Mycat-server-1.4-beta-20150604171601-linux.tar.gz
下载至opt目录解压

/opt/mycat/conf目录下 配置
schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">
	<!-- 定义MyCat的逻辑库,逻辑库的概念与MySQL中的 database 概念相同 -->
	<schema name="mytest" checkSQLschema="false" sqlMaxLimit="100"dataNode="testNode"></schema> 
	
	<!-- 定义MyCat的数据节点 -->  
    <dataNode name="testNode" dataHost="dtHost" database="dada" />  
  
      
    <!-- 定义数据主机dtHost,连接到MySQL读写分离集群 ,schema中的每一个dataHost中的host属性值必须唯一-->  
    <!-- dataHost实际上配置就是后台的数据库集群,一个datahost代表一个数据库集群 -->  
    <!-- balance="1",全部的readHost与stand by writeHost参与select语句的负载均衡-->   
	<dataHost name="dtHost" maxCon="500" minCon="20" balance="1" dbType="mysql" dbDriver="native">  
        <!--心跳检测 -->  
        <heartbeat>select user()</heartbeat>  
          
        <!--配置后台数据库的IP地址和端口号,还有账号密码 -->  
        <writeHost host="hostM1" url="192.168.218.130:3306" user="root" password="root">
		    <readHost host="hostS1" url="192.168.218.132:3306" user="root" password="root"></readHost>  
		</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://org.opencloudb/">
	<system>
	<property name="defaultSqlParser">druidparser</property>
      <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
	<!-- <property name="processorBufferChunk">40960</property> -->
	<!-- 
	<property name="processors">1</property> 
	<property name="processorExecutor">32</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="mutiNodeLimitType">1</property> 0:开启小数量级(默认) ;1:开启亿级数据排序
	    	<property name="mutiNodePatchSize">100</property> 亿级数量排序批量
			<property name="processors">32</property> <property name="processorExecutor">32</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> -->
	</system>
	<!--<user name="test">
		<property name="password">test</property>
		<property name="schemas">TESTDB</property>
	</user>-->
	<!-- 8066 -->
	<user name="root">
		<property name="password">123</property>
		<property name="schemas">mytest</property>
	</user>
	
	<!--<user name="user">
		<property name="password">user</property>
		<property name="schemas">TESTDB</property>
		<property name="readOnly">true</property>
	</user>-->
	<!-- <cluster> <node name="cobar1"> <property name="host">127.0.0.1</property> 
		<property name="weight">1</property> </node> </cluster> -->
	<!-- <quarantine> <host name="1.2.3.4"> <property name="user">test</property> 
		</host> </quarantine> -->

</mycat:server>

启动
/opt/mycat/bin 目录下执行

./mycat status
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值