1 mycat 安装部署

1 下载解压Mycat-server-1.6-RELEASE-20161010173036-linux.tar.gz 到/usr/local/mycat

2 下载解压jdk-8u101-linux-x64.tar.gz,拷贝dk-8u101 到/usr/local/mycat/

3 修改/usr/local/mycat/mycat/conf/wrapper.conf 修改wrapper.Java.command=java为上一步存放路径

wrapper.java.command=/usr/local/mycat/jdk1.8.0_101/bin/java

[mysql@hongquan conf]$ ls /usr/local/mycat/mycat/conf/wrapper.conf

/usr/local/mycat/mycat/conf/wrapper.conf

4 创建mycat 用户,改变目录权限为mycat

useradd mycat

chown -R mycat.mycat /usr/local/mycat

连接mysql的用户名:密码=system:mysql

5 修改conf/schema.xml,URL、用户名、密码修改,其余不变

[mysql@hongquan conf]$ ls /usr/local/mycat/mycat/conf/schema.xml

/usr/local/mycat/mycat/conf/schema.xml

[mysql@hongquan conf]$ vim schema.xml

<writeHost host="hostM1" url="10.0.1.134:3306" user="system"

password="www.com.workssys">

6 修改/conf/server.xml 文件

[mysql@hongquan conf]$ ls /usr/local/mycat/mycat/conf/server.xml

/usr/local/mycat/mycat/conf/server.xml

(1) 用命令行工具或图形化客户端,连接MYSQL,创建DEMO所用三个分片数据库;

CREATE database db1;

CREATE database db2;

CREATE database db3;

(2) 修改my.inf新增以下语句,my.inf 一般会放在/etc/my.cnf 或 /etc/mysql/my.cnf,设置为Mysql大小写不敏感,否则可能会发生表找不到的问题。

lower_case_table_names = 1

(3) 解压Mycat-server-1.6-RELEASE-20161010173036-linux.tar.gz 到/usr/local/mycat

[root@hqmysql1 soft]# tar xvf Mycat-server-1.6-RELEASE-20161028204710-linux_.tar.gz

[root@hqmysql1 soft]# mv mycat/ /usr/local/

(4) 解压jdk-8u101-linux-x64.tar.gz,拷贝dk-8u101 到/usr/local/mycat/

[root@hqmysql1 soft]# tar xvf jdk-8u101-linux-x64.tar.gz

[root@hqmysql1 soft]# mv jdk1.8.0_101/ /usr/local/

[root@hqmysql1 soft]# ll /usr/local/jdk1.8.0_101

# vim /etc/profile  添加如下内容

export JAVA_HOME=/usr/local/jdk1.8.0_101

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

[root@hqmysql1 soft]# source /etc/profile

[root@hqmysql1 soft]# java -version

java version "1.8.0_101"

Java(TM) SE Runtime Environment (build 1.8.0_101-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

(5) 修改/usr/local/mycat/conf/wrapper.conf 修改wrapper.Java.command=java为上一步存放路径

wrapper.java.command=/usr/local/mycat/jdk1.8.0_101/bin/java

(6) 创建mycat 用户,改变目录权限为mycat

useradd mycat

chown -R mycat.mycat /usr/local/mycat

(8) 修改/usr/local/conf/schema.xml,URL、用户名、密码修改,其余不变,server.xml

<writeHost host="hostM1" url="10.0.1.134:3306" user="system"

password="mysql">

[root@hqmysql1 conf]# vim server.xml

<user name="system">

<property name="password">mysql</property>

<property name="schemas">TESTDB</property>

[root@hongquan conf]# vim wrapper.conf

[root@hongquan bin]# pwd

/usr/local/mycat/mycat/bin

(1) 进入 /usr/local/mycat/bin (默认数据端口为8066,管理端口为9066)

执行./mycat start

[root@hongquan bin]# ./mycat start

查看mycat服务是否启动

# ps -ef |grep mycat

[root@hqmysql1 bin]# netstat -nltp | grep 8066

tcp        0      0 :::8066                     :::*                        LISTEN      24720/java

[root@hqmysql1 logs]# tail -f -n 300 wrapper.log

Starting Mycat-server...

STATUS | wrapper  | 2017/07/10 15:44:17 | Launching a JVM...

ERROR  | wrapper  | 2017/07/10 15:44:17 | Unable to start JVM: No such file or directory (2)

ERROR  | wrapper  | 2017/07/10 15:44:17 | JVM exited while loading the application.

--修改wrapper.java.command=/usr/local/jdk1.8.0_101/bin/java

Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: hqmysql1: hqmysql1: unknown error

-----[root@hqmysql1 bin]# vim /etc/hosts

127.0.0.1 hqmysql1

(2) 进入logs目录,查看日志,如果wrapper.log 报错 java.NET.BindException: Address already in use 杀掉正在执行的相关java进程

ps -ef|grep java

kill -9 xxx

[root@hongquan bin]# ps -ef|grep java

[mysql@hqmysql1 scripts]$ mysql -usystem -pmysql -h127.0.0.1 -P8066 -DTESTDB

(mycat的用户账号和授权信息是在conf/server.xml文件中配置)

[root@hongquan bin]# tail -f -n 300 /usr/local/mycat/mycat/logs/wrapper.log

[INFO ][$_NIOREACTOR-0-RW] can't get connection for sql :select user()  (io.mycat.sqlengine.SQLJob:SQLJob.java:114)

[mycat@hongquan logs]$ tail -f mycat.log

[root@hongquan logs]# netstat -nltp | grep 8066

tcp        0      0 :::8066                     :::*                        LISTEN      34255/java

[mysql@hongquan scripts]$ mysql -usystem -pmysql -P8066 -h10.0.1.134  -DTESTDB

mysql> show databases;

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

| DATABASE |

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

| TESTDB   |

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

1 row in set (0.00 sec)

mysql> show tables;

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

| Tables in TESTDB |

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

| company          |

| customer         |

| customer_addr    |

| employee         |

| goods            |

| hotnews          |

| orders           |

| order_items      |

| travelrecord     |

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

9 rows in set (0.00 sec)

mysql> create table employee (id int not null primary key,name varchar(100),sharding_id int not null);

Query OK, 0 rows affected (0.16 sec)

mysql> explain create table employee (id int not null primary key,name varchar(100),sharding_id int not null);

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

| DATA_NODE | SQL                                                                                            |

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

| dn1       | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) |

| dn2       | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) |

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

2 rows in set (0.01 sec)

mysql> explain insert into employee(id,name,sharding_id) values(1,'leader us',10000);

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

| DATA_NODE | SQL                                                                   |

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

| dn1       | insert into employee(id,name,sharding_id) values(1,'leader us',10000) |

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

1 row in set (0.10 sec)

mysql> explain create table company(id int not null primary key,name varchar(100));

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

| DATA_NODE | SQL                                                                 |

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

| dn1       | create table company(id int not null primary key,name varchar(100)) |

| dn2       | create table company(id int not null primary key,name varchar(100)) |

| dn3       | create table company(id int not null primary key,name varchar(100)) |

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

3 rows in set (0.00 sec)

mysql> create table company(id int not null primary key,name varchar(100));

Query OK, 0 rows affected (0.10 sec)

mysql> insert into company(id,name) values(1,'hp');

Query OK, 1 row affected (0.01 sec)

mysql> select * from employee;

Empty set (0.14 sec)

mysql> insert into employee(id,name,sharding_id) values(1,'leader us',10000);

Query OK, 1 row affected (0.00 sec)

mysql> select * from employee;

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

| id | name      | sharding_id |

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

|  1 | leader us |       10000 |

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

1 row in set (0.00 sec)

mysql> explain select * from employee;

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

| DATA_NODE | SQL                              |

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

| dn1       | SELECT * FROM employee LIMIT 100 |

| dn2       | SELECT * FROM employee LIMIT 100 |

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

2 rows in set (0.00 sec)

mysql>insert into employee(id,name,sharding_id) values(2,'me',10010);

Query OK, 1 row affected (0.01 sec)

mysql>insert into employee(id,name,sharding_id) values(3,'mycat',10000);

Query OK, 1 row affected (0.00 sec)

mysql>insert into employee(id,name,sharding_id) values(4,'mycat1',10010);

Query OK, 1 row affected (0.01 sec)

mysql> select * from employee;

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

| id | name      | sharding_id |

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

|  2 | me        |       10010 |

|  4 | mycat1    |       10010 |

|  1 | leader us |       10000 |

|  3 | mycat     |       10000 |

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

4 rows in set (0.01 sec)

explain  create table travelrecord (id bigint not null primary key,user_id varchar(100),traveldate DATE, fee decimal,days int);

explain insert into travelrecord (id,user_id,traveldate,fee,days) values(1,'wang','2014-01-05',510.5,3);

explain insert into travelrecord (id,user_id,traveldate,fee,days) values(7000001,'wang','2014-01-05',510.5,3);

insert into company(id,name) values(1,'hp');

insert into company(id,name) values(2,'ibm');

insert into company(id,name) values(3,'oracle');

创建客户表:

create customer:    create table customer(id int not null primary key,name varchar(100),company_id int not null,sharding_id int not null);

插入数据:

insert into customer (id,name,company_id,sharding_id )values(1,'wang',1,10000);  //stored in db1;

insert into customer (id,name,company_id,sharding_id )values(2,'xue',2,10010);  //stored in db2;

insert into customer (id,name,company_id,sharding_id )values(3,'feng',3,10000); //stored in db1;

创建表格orders,并插入数据:

create table orders (id int not null primary key ,customer_id int not null,sataus int ,note varchar(100) );

insert into orders(id,customer_id) values(1,1); //stored in db1 because customer table with id=1 stored in db1

insert into orders(id,customer_id) values(2,2); //stored in db2 because customer table with id=1 stored in db2

explain insert into orders(id,customer_id) values(2,2);

select customer.name ,orders.* from customer ,orders where customer.id=orders.customer_id;

热点新闻,用取摸的方式随机分配到dn1,dn2,dn3上

create table hotnews(id int  not null primary key ,title varchar(400) ,created_time datetime);

insert into hotnews(id,title,created_time) values(1,'first',now()); 在分片1上

而Id为5,则到dn3上,5%3=2 ,即对应dn3的 index

其他:

goods表

create table goods(id int not null primary key,name varchar(200),good_type tinyint,

good_img_url  varchar(200),good_created date,good_desc varchar(500), price double);

部分schema.xml

<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">

<!-- auto sharding by id (long) -->

<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />

<!-- global table is auto cloned to all defined data nodes ,so can join

with any table whose sharding node is in the same data node -->

<table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />

<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />

<!-- random sharding using mod sharind rule -->

<table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3"

   rule="mod-long" />

<!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"

needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3"

rule="mod-long" /> -->

<table name="employee" primaryKey="ID" dataNode="dn1,dn2"

   rule="sharding-by-intfile" />

<table name="customer" primaryKey="ID" dataNode="dn1,dn2"

   rule="sharding-by-intfile">

<childTable name="orders" primaryKey="ID" joinKey="customer_id"

parentKey="id">

<childTable name="order_items" joinKey="order_id"

parentKey="id" />

</childTable>

<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"

parentKey="id" />

</table>

MyCAT 1.6 安装部署的更多相关文章

  1. centos7 Mycat/MySQL/MariaDB安装部署

    使用yum安装MySQL详细步骤 安装mysql源 centos系统中不包含mysql的源,需要先安装mysql源 1.官网下载源.使用图形界面操作系统进入mysql官网,进入以下界面. 2.在Cen ...

  2. MyCat 安装部署,实现数据库分片存储

    一.安装MySQL或MariaDB(本文以MariaDB为例) MySQL手动安装方法:点击查看 MariaDB安装: 1.下载MariaDB的repo $ vi /etc/yum.repos.d/M ...

  3. 数据库中间件之mycat安装部署(一)

    在学习数据库中间件前,我们先抛出三个问题 1.数据库数据量不大,但并发读写操作很大,应该怎么办? 此时我们首先考虑使用缓存中间件来减轻读压力,如果不能满足则考虑数据库读写分离,此时就会引入新的问题,这 ...

  4. Oracle安装部署,版本升级,应用补丁快速参考

    一.Oracle安装部署 1.1 单机环境 1.2 Oracle RAC环境 1.3 Oracle DataGuard环境 1.4 主机双机 1.5 客户端部署 二.Oracle版本升级 2.1 单机 ...

  5. KVM安装部署

    KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...

  6. Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考

    操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...

  7. 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署

    少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...

  8. C# winform安装部署(转载)

    c# winform 程序打包部署 核心总结: 1.建议在完成的要打包的项目外,另建解决方案建立安装部署项目(而不是在同一个解决方案内新建),在解决方案上右击-〉添加-〉现有项目-〉选择你要打包的项目 ...

  9. Ubuntu14.04 Django Mysql安装部署全过程

    Ubuntu14.04 Django Mysql安装部署全过程   一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便 ...

随机推荐

  1. java中的特殊有用类

    1.MessageDigest:类似与md5加密算法应用的功能类

  2. linux基础(1)-yum源配置

    用linux将近一年了,开始学的东西因为没经常用都忘记了,现在将笔记的东西慢慢整理成自己的博客,也算是看着自己进步.有些东西从他人博客笔记学的,有些是从视频学的,有些是自己填坑积累的. 在linux下 ...

  3. PAT1027. Colors in Mars (20)

    #include <iostream> using namespace std; string tbl="0123456789ABC"; int main() { in ...

  4. poj 1061 青蛙的约会 扩展欧几里德

    青蛙的约会 Time Limit: 1000MS   Memory Limit: 10000K       Description 两 只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们 ...

  5. 04-dotnetCore博客后台基本功能实现

    今天继续上篇博客的内容,在上一篇的时候,已经基本实现了博客列表内容的显示,继续进行添加.编辑.删除等功能.添加和编辑界面共用一个界面,添加界面如图所示: 同样我这里使用的还是layui里面的表单内容, ...

  6. 解决:git warning: LF will be replaced by CRLF in xxxx

    一. git add -A报错 在利用git add -A添加文件时,意外的发现报错了 报错信息中: LF:Line Feed 换行 CRLF:Carriage Return Line Feed  回 ...

  7. poj2942 点-双联通+二分图染色

    题意:有一群骑士要坐在一个圆形的桌子上,他们之间有些人相互讨厌,所以不能挨着,要求算出一次也不能坐在桌子上的人,每次会议桌子必须奇数个人,一个人不能开会 题解:可以先建一个补图,要满足题目条件我们只要 ...

  8. NSObject头文件解析 / 消息机制 / Runtime解读 (二)

    本章接着NSObject头文件解析 / 消息机制 / Runtime解读(一)写 给类添加属性: BOOL class_addProperty(Class cls, const char *name, ...

  9. linux下安装Java se和Eclipse

    首先要去下载好JDK,Java SE 8的官方网址是http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213 ...

  10. javascript常用的数组操作

    数组的定义 var arr=new Array(); var arr=[]; var arr=new Array(10);//定义一个长度为10的数组 数组元素的访问 var temp=arr[1]; ...