ITPub博客

首页 > Linux操作系统 > Linux操作系统 > cobar续2-工具使用篇

cobar续2-工具使用篇

原创 Linux操作系统 作者:a3zi 时间:2015-01-16 23:10:43 0 删除 编辑

cobar已经简单配置好,又如何来使用呢?

主要是通过9066端口和8066端品,一个是管理另一个是调用。

1,Cobar通过9066端口向用户提供了一些管理和监控命令:

mysql -h172.16.88.131 -utest -ptest -P9066 -Ddbtest

# 通过show @@help可以查看9066端口支持的所有命令,以及简单解释

mysql> show @@help;

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

| STATEMENT                            | DESCRIPTION                       |

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

| clear @@slow where datanode = ?      | Clear slow sql by datanode        |

| clear @@slow where schema = ?        | Clear slow sql by schema          |

| kill @@connection id1,id2,...        | Kill the specified connections    |

| offline                              | Change Cobar status to OFF        |

| online                               | Change Cobar status to ON         |

| reload @@config                      | Reload all config from file       |

| reload @@route                       | Reload route config from file     |

| reload @@user                        | Reload user config from file      |

| rollback @@config                    | Rollback all config from memory   |

| rollback @@route                     | Rollback route config from memory |

| rollback @@user                      | Rollback user config from memory  |

| show @@backend                       | Report backend connection status  |

| show @@command                       | Report commands status            |

| show @@connection                    | Report connection status          |

| show @@connection.sql                | Report connection sql             |

| show @@database                      | Report databases                  |

| show @@datanode                      | Report dataNodes                  |

| show @@datanode where schema = ?     | Report dataNodes                  |

| show @@datasource                    | Report dataSources                |

| show @@datasource where dataNode = ? | Report dataSources                |

| show @@heartbeat                     | Report heartbeat status           |

| show @@parser                        | Report parser status              |

| show @@processor                     | Report processor status           |

| show @@router                        | Report router status              |

| show @@server                        | Report server status              |

| show @@slow where datanode = ?       | Report datanode slow sql          |

| show @@slow where schema = ?         | Report schema slow sql            |

| show @@sql where id = ?              | Report specify SQL                |

| show @@sql.detail where id = ?       | Report execute detail status      |

| show @@sql.execute                   | Report execute status             |

| show @@sql.slow                      | Report slow SQL                   |

| show @@threadpool                    | Report threadPool status          |

| show @@time.current                  | Report current timestamp          |

| show @@time.startup                  | Report startup timestamp          |

| show @@version                       | Report Cobar Server version       |

| stop @@heartbeat name:time           | Pause dataNode heartbeat          |

| switch @@datasource name:index       | Switch dataSource                 |

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

37 rows in set (0.04 sec)

数据源、数据节点查看:

mysql> show @@datanode;

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

| NAME    | DATASOURCES | INDEX | TYPE  | ACTIVE | IDLE | SIZE | EXECUTE | TOTAL_TIME | MAX_TIME | MAX_SQL | RECOVERY_TIME |

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

| dnTest1 | dsTest[0]   |     0 | mysql |      0 |    0 |  128 |       3 |          0 |        0 |       0 |            -1 |

| dnTest2 | dsTest[1]   |     0 | mysql |      0 |    0 |  128 |       9 |          0 |        0 |       0 |            -1 |

| dnTest3 | dsTest[2]   |     0 | mysql |      0 |    0 |  128 |       6 |          0 |        0 |       0 |            -1 |

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

3 rows in set (0.07 sec)

# NAME: datanode名称。

# DATASOURCES: datanode对应的主备datasource

# INDEX: 指示datanode正在使用的数据源

 

show @@datasource [where schema = ? ] ------ 查看系统中配置的数据源

show @@database ------在8066端口的show databases语句。

sql执行状况查询

show @@sql.slow ------ 慢sql查询

show @@slow where datanode = ? /clear @@slow where datanode = ? ------利用clear清除该datanode当前的慢sql

show @@slow where schema = ? / clear @@slow where schema= ? ------ 根据schema查询慢sql,

利用clear清除该schema当前慢sql

show @@sql where id = ?

show @@sql.detail where id = ?

show @@sql.execute

内部状态查询

show @@command ------ Cobar执行语句的个数统计

show @@processor ------ Cobar处理器状态查询

show @@threadpool ------ Cobar内部线程池状态查询

show @@connection ------ cobar前端连接状态查询

show @@heartbeat ------ 心跳状态查询,心跳包括Cobar之间的心跳,Cobar到MySQL数据库的心跳

show @@server ------ 查询server信息

reload @@config ------ 配置文件热加载,用户配置文件不需要重启cobar,只需运行reload命令即可。

注意:当用户如果修改server.xml中标签下的配置时,需要重启cobar才能生效,其余配置均可热加载。

reload@@config这个命令经常在线上用到。

2,通过8066端口访问cobar:

mysql -h172.16.88.131 -utest -ptest -P8066 -Ddbtest

mysql> show databases;

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

| DATABASE |

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

| dbtest   |

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

1 row in set (0.01 sec)

查看表tb1

mysql> select * from tb1;

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

| id | gmt                 |

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

|  1 | 2015-01-12 11:50:13 |

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

1 row in set (0.17 sec)

查看表tb2

mysql> select * from tb2;

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

| id | val   |

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

|  1 | user1 |

|  2 | user1 |

|  6 | user2 |

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

3 rows in set (0.10 sec)

通过8066端口访问cobar,我们看到“只有一个dbtest数据库,tb1,tb2两表都在dbtest里面”,实际后端是分库分表存储的。

3,举一线上的例子

比如,开发要求线上的数据库要新建一个表,并且要加入到正在运行的cobar中

一般都是在对内的环境中测试一下,通过后才正式上线

Create table if not exists `user_home ` (

`user_home_id` tinyint(1) not null auto_increment,

......

primary key (`user_home_id`),

index type(`type`)

) engine=innodb default charset=utf8;

然后修改cobar的配置文件schema.xml和rule.xml,添加分表规则等设置

再通过9066端口进入管理端加载配置文件使之生效:

mysql -h172.16.88.131 -utest -ptest -P9066 -Ddbtest

reload@@config

并检查是否OK,一切没问题了,再改线上cobar.

 

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29806344/viewspace-1404712/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-08-15

  • 博文量
    45
  • 访问量
    228899