码迷,mamicode.com
首页 > 系统相关 > 详细

Linux下部署ali cobar server

时间:2015-03-02 21:03:50      阅读:365      评论:0      收藏:0      [点我收藏+]

标签:数据库   迁移   水平扩展   垂直扩展   cobar-serv   

1,cobar项目

官方网站,已经迁移到github上面了。
https://github.com/alibaba/cobar
下载:
https://github.com/alibaba/cobar/wiki/%E4%B8%8B%E8%BD%BD

Cobar是关系型数据的分布式处理系统,它可以在分布式的环境下看上去像传统数据库一样为您提供海量数据服 务。

技术分享

2,Cobar解决的问题

分布式:Cobar的分布式主要是通过将表放入不同的库来实现:
1. Cobar支持将一张表水平拆分成多份分别放入不同的库来实现表的水平拆分
2. Cobar也支持将不同的表放入不同的库
3. 多数情况下,用户会将以上两种方式混合使用 这里需要强调的是,Cobar不支持将一张表,例如test表拆分成test_1, test_2, test_3…..放在同一个库中, 必须将拆分后的表分别放入不同的库来实现分布式。

HA: 在用户配置了MySQL心跳的情况下,Cobar可以自动向后端连接的MySQL发送心跳,判断MySQL运行状 况,一旦运行出现异常,Cobar可以自动切换到备机工作。但需要强调的是:

1. Cobar的主备切换有两种触发方式,一种是用户手动触发,一种是Cobar的心跳语句检测到异常后自动触 发。那么,当心跳检测到主机异常,切换到备机,如果主机恢复了,需要用户手动切回主机工作,Cobar不 会在主机恢复时自动切换回主机,除非备机的心跳也返回异常。
2. Cobar只检查MySQL主备异常,不关心主备之间的数据同步,因此用户需要在使用Cobar之前在MySQL主 备上配置双向同步,详情可以参阅MySQL参考手册。

技术分享

dataSource:数据源,表示一个具体的数据库连接,与一个物理存在的schema一一对应。 
dataNode:数据节点,由主、备数据源,数据源的HA以及连接池共同组成,可以将一个dataNode理解为一 个分库。
table:表,包括拆分表(如tb1,tb2)和非拆分表。 
tableRule:路由规则,用于判断SQL语句被路由到具体哪些datanode执行。 schema:cobar可以定义包含拆分表的schema(如schema1),也可以定义无拆分表的schema(如 schema2)。 
以上层次关系具有较强的灵活性,用户可以将表自由放置不同的datanode,也可将不同的datasource放置在 同一MySQL实例上。

3,服务目录

解压后,进入cobar-server-1.2.4 目录,可以看到Cobar的主要目录如下:

bin #包含Cobar的启动、重启、停止等脚本文件 
conf #包含Cobar所有配置文件
lib #包含Cobar及其依赖的jar文件
logs #包含Cobar所有日志文件

?????????启动脚本 Cobar的所有启动停止脚本全部放在bin目录中,进入bin目录,可以看到:

startup.sh #Linux环境启动脚本 
restart.sh #Linux环境重启脚本 
shutdown.sh #Linux环境停止脚本

配置文件 Cobar的所有配置文件全部放在conf目录中,进入conf目录,可以看到:

server.xml #Cobar系统、用户、集群等相关配置 
schema.xml #schema,dataNode,dataSource相关配置 
rule.xml #分布式规则定义
log4j.xml #日志相关配置

更多详细参考文档:
http://blog.csdn.net/shagoo/article/details/8191346

4,cobar admin按照

https://github.com/alibaba/cobar/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E7%AD%94
写在常见问题里面了:

1.修改WEB-INF/或者源码src/main/resource/中log4j日志输出路径,日志级别调整为INFO及以上
  2.将WEB-INF/或者源码src/main/resource/中的cluster.xml, cobar.xml, user.xml,property.xml拷贝到某个固定目录,比如/home/admin/xml/
  3.修改WEB-INF/xmlpath.properties中文件内容为xmlpath=/home/admin/xml/
  4.源码打包,将war包放入web容器执行
  5.user.xml记录的初始用户名和密码为root/123456

重启tomcat,进入登陆界面:
技术分享
输入密码root,123456
技术分享
进入系统。可以查看配置,访问情况。

同时可以增加cobar节点,节点的密码配置在conf/server.xml里面。

<!-- 用户访问定义,用户名、密码、schema等信息。 -->
  <user name="test">
    <property name="password">test</property>
    <property name="schemas">dbtest</property>
  </user>

(http://img.blog.csdn.net/20150302194710221)
增加成功之后在节点管理里面就可以看到了。
技术分享

5,启动cobar-server

修改conf/schema.xml数据库连接地址。
然后启动报错:

#!Cobar#dnTest2 init failure

数据表没有创建。

#创建dbtest1
drop database if exists dbtest1;
create database dbtest1;
use dbtest1;
#在dbtest1上创建tb1
create table tb1(
id    int not null,
gmt   datetime);

#创建dbtest2
drop database if exists dbtest2;
create database dbtest2;
use dbtest2;
#在dbtest2上创建tb2
create table tb2(
id    int not null,
val   varchar(256));

#创建dbtest3
drop database if exists dbtest3;
create database dbtest3;
use dbtest3;
#在dbtest3上创建tb2
create table tb2(
id    int not null,
val   varchar(256));

**其中发现一个问题,如果使用Mariadb 5.5 查询不到数据表。
必须使用mysq数据库。我在centos6 上面安装的数据库可以(mysql 5.1.73),在centos7上面的mariaDB数据库就不行(MariaDB 5.5.40)。**

测试数据成功了。

# mysql -h127.0.0.1 -utest -ptest -P8066 -Ddbtest
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.48-cobar-1.2.7 Cobar Server (ALIBABA)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> show tables;
+------------------+
| Tables_in_dbtest |
+------------------+
| tb1              |
| tb2              |
+------------------+
2 rows in set (0.00 sec)

mysql> insert into tb1 (id, gmt) values (1, now());
Query OK, 1 row affected (0.02 sec)

mysql> insert into tb2 (id, val) values (1, "part1");
Query OK, 1 row affected (0.01 sec)

mysql> insert into tb2 (id, val) values (2, "part1"), (513, "part2");
Query OK, 2 rows affected (0.03 sec)

mysql> select * from tb1;
+----+---------------------+
| id | gmt                 |
+----+---------------------+
|  1 | 2015-03-02 19:36:18 |
+----+---------------------+
1 row in set (0.01 sec)

mysql> select * from tb2;
+-----+-------+
| id  | val   |
+-----+-------+
|   1 | part1 |
|   2 | part1 |
| 513 | part2 |
+-----+-------+
3 rows in set (0.00 sec)

5,总结

cobar 初步测试已经完成了。已经很好的解决了水平扩展和垂直扩展。
而且只需要修改配置就可以实现。完全可以平滑的切换过去。
下一步研究集群方案。

Linux下部署ali cobar server

标签:数据库   迁移   水平扩展   垂直扩展   cobar-serv   

原文地址:http://blog.csdn.net/freewebsys/article/details/44022421

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!