MyCAT 1.6 安装部署
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 安装部署的更多相关文章
- centos7 Mycat/MySQL/MariaDB安装部署
使用yum安装MySQL详细步骤 安装mysql源 centos系统中不包含mysql的源,需要先安装mysql源 1.官网下载源.使用图形界面操作系统进入mysql官网,进入以下界面. 2.在Cen ...
- MyCat 安装部署,实现数据库分片存储
一.安装MySQL或MariaDB(本文以MariaDB为例) MySQL手动安装方法:点击查看 MariaDB安装: 1.下载MariaDB的repo $ vi /etc/yum.repos.d/M ...
- 数据库中间件之mycat安装部署(一)
在学习数据库中间件前,我们先抛出三个问题 1.数据库数据量不大,但并发读写操作很大,应该怎么办? 此时我们首先考虑使用缓存中间件来减轻读压力,如果不能满足则考虑数据库读写分离,此时就会引入新的问题,这 ...
- Oracle安装部署,版本升级,应用补丁快速参考
一.Oracle安装部署 1.1 单机环境 1.2 Oracle RAC环境 1.3 Oracle DataGuard环境 1.4 主机双机 1.5 客户端部署 二.Oracle版本升级 2.1 单机 ...
- KVM安装部署
KVM安装部署 公司开始部署KVM,KVM的全称是kernel base virtual machine,对KVM虚拟化技术研究了一段时间, KVM是基于硬件的完全虚拟化,跟vmware.xen.hy ...
- Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考
操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...
- 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署
少啰嗦,直接装 看过上一篇分布式文件系统 - FastDFS 简单了解一下的朋友应该知道,本次安装是使用目前余庆老师开源的最新 V5.05 版本,是余庆老师放在 Github 上的,和目前你能在网络上 ...
- C# winform安装部署(转载)
c# winform 程序打包部署 核心总结: 1.建议在完成的要打包的项目外,另建解决方案建立安装部署项目(而不是在同一个解决方案内新建),在解决方案上右击-〉添加-〉现有项目-〉选择你要打包的项目 ...
- Ubuntu14.04 Django Mysql安装部署全过程
Ubuntu14.04 Django Mysql安装部署全过程 一.简要步骤.(阿里云Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便 ...
随机推荐
- WebUploader API文档
Web Uploader内部类的详细说明,以下提及的功能类,都可以在WebUploader这个变量中访问到. As you know, Web Uploader的每个文件都是用过AMD规范中的defi ...
- 使用Navicat连接oracle时出现unsupported server character set ZHS16GBK的解决之道
原文网址http://blog.mn886.net/chenjianhua/show/ba1dc6f835be403ea159b0a5e2685ff2/index.html ORA-12737:Ins ...
- spark学习2-1(hive1.2安装)
由于前面安装版本过老,导致学习过程中出现了很多问题,今天安装了一个新一点的版本.安装结束启动时遇到一点问题,记录在这里. 第一步:hive-1.2安装 通过WinSCP将apache-hive-1.2 ...
- nodejs 语法很特别的地方
1. 不过我们之前说过了有 this 和没 this 的时候作用域不同,那个参数只是作用于构造函数中,而加了 this 的那个则是成员变量.用一个 this 就马上区分开来他们了,所以即使同名也没关系 ...
- 虚拟机CentOS7网络配置
*关于查看IP信息 window中是 ipconfig Linux一般都是 ifconfig 不过CentOS7中 这个命令发生了更改 :ip addr 设置网络 再新建虚拟机向导过程中,有一步[网 ...
- Django---model基础(单表)
ORM 一.映射关系: 表名<--------------->类名 字段<-------------->属性 表记录& ...
- R语言可视化
R语言基础(一) 可视化基础 ##数据获取 x1=round(runif(100,min=80,max=100)) x2=round(rnorm(100,mean=80, sd=7)) x3=ro ...
- php特级课---1、网站大访问量如何解决
php特级课---1.网站大访问量如何解决 一.总结 一句话总结: 负载均衡和冗余技术 1.负载均衡和冗余技术是一回事么? 并不是:负载均衡是用户分流:冗余技术是避免出现单点故障 负载均衡:将不同的用 ...
- 2017-03-05 CentOS中配置守护服务(Supervisor)监听dotnet core web程序的运行
我们继续解决上篇博客的问题,我这个人有个毛病,不喜欢遗留什么问题,也不喜欢问题说不明白,具体要怎么解决一定要详尽,因为经常自己遇到问题的时候,去翻别人的博客,就会遇到这样的问题,很苦恼,又说废话了. ...
- CodeForces 444C 线段树
想分块想了很久一点思路都没有,结果一看都是写的线段树= = ...完全忘记了还有线段树这种操作 题意:给一个数组,一种操作是改变l到r为c,还有一种操作是查询l到r的总和差 线段树记得+lazy标记 ...