centos6.x安装mycat(简单的安装)

前端之家收集整理的这篇文章主要介绍了centos6.x安装mycat(简单的安装)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

准备工作:

1、安装jdk1.7(因为MyCAT 是使用 JAVA 语言进行编写开发,使用前需要先安装 JAVA 运行环境(JRE),由于 MyCAT 中使用)点击下载jdk

也可以参考我之前的文章: centos 安装jdk/tomcat

下载 tar.gz压缩包

解压到指定位置(你也可以解压到你喜欢的目录里):tar zxvf xxx.tar.gz -C /usr/local/

设置jdk环境变量:

vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.7
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar


source /etc/profile文件修改后立即生效

2、安装mycat(本文使用的1.6) 点击下载mycat

加压到指定目录(自己喜欢的目录) tar zxvf xxxx.tar.gz -C /usr/local/

设置mycat环境变量:

vim /etc/profile

在末尾添加:

export MYCAT_HOME=/usr/local/mycat

source /etc/profile文件修改后立即生效

3、修改myslq 的配置文件 my.cnf

[MysqLd]下面添加

lower_case_table_names = 1 【忽略大小写】

重启MysqL

4、修改mycat配置文件:

Mycat/conf 下有三个文件

1、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="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="mycat_centos">
		<property name="password">mycat123</property>
		<property name="schemas">yrok</property>
	</user>

	<user name="mycat_windows">
		<property name="password">mycat123</property>
		<property name="schemas">yrok</property>
		<property name="readOnly">true</property>
	</user>
	<!-- 
	<quarantine> 
	   <whitehost>
	      <host host="127.0.0.1" user="mycat"/>
	      <host host="127.0.0.2" user="mycat"/>
	   </whitehost>
       <blacklist check="false"></blacklist>
	</quarantine>
	-->

</mycat:server>


2、schema.xml 【定义逻辑库、表、分片节点】

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

	<schema name="shenyi" checksqlschema="false" sqlMaxLimit="100">
		<!-- auto sharding by id (long) -->
		<!--<table name="travelrecord" datanode="dn1" rule="auto-sharding-long" />-->
 
		 <table name="users" primaryKey="news_id"  type="global" datanode="dn1,dn2" />
		 
		 
	</schema> 
	 
	<datanode name="dn1" dataHost="localhost1" database="yrok_database" />
	<datanode name="dn2" dataHost="localhost2" database="yrok_database" />


	<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
		writeType="0" dbType="MysqL" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.31.5:3306" user="root"
			password="123456">
		</writeHost>
 
	</dataHost>
	<dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"
		writeType="0" dbType="MysqL" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<!-- can have multi write hosts -->
		<writeHost host="hostM1" url="192.168.200.25:3306" user="root"
			password="123456">
		</writeHost>
		 
	</dataHost>
	 
</mycat:schema>


3、rule.xml 【定义分片规则等】暂时未使用

5、启动mycat:

执行:

/usr/local/mycat/bin/mycat start

查看启动状态:

ps -ef | grep mycat 或者 netstat -ntpl | grep 8066 【8066是mycat数据库的访问端口,记住此处不是3306】

6、启动没有问题,使用MysqL连接工具连接:

连接过程就不贴图了

7、连接容易产生的问题

1、MysqL 没有开启远程访问权限:

grant all privileges on *.* to root@'%' identified by 'xxxxx';

flush privileges;

2、没有开启8066端口访问权限:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8066 -j ACCEPT

8、成功连接mycat

谢谢大家的支持评论一下点个赞呗,后续呢还会更新~~~~

猜你在找的CentOS相关文章