TiDB分布式数据库(二)
#
公司主营业务:成都做网站、成都网站制作、成都外贸网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出相城免费做网站回馈大家。
# TiDB :A Distributed SQL Database
# github :https://github.com/pingcap/tidb
# doc : https://github.com/pingcap/docs-cn
#
#架构
Name | Host IP | Services |
node1 | 192.168.174.134 | PD, TiDB |
node2 | 192.168.174.136 | TiKV1 |
node3 | 192.168.174.137 | TiKV2 |
node4 | 192.168.174.138 | TiKV3 |
#软件下载(每台都需操作)
[root@node1 ~]# wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz [root@node1 ~]# tar -xf tidb-latest-linux-amd64.tar.gz -C /usr/local/ [root@node1 ~]# mkdir /data/tidb/{data,log} -p
#开启服务(注:集群的启动顺序不能错)
#在node1开启PD
[root@node1 ~]# /usr/local/tidb-latest-linux-amd64/bin/pd-server --name=pd1 \ --data-dir=/data/tidb/data --client-urls="http://192.168.174.134:2379" \ --peer-urls="http://192.168.174.134:2380" --initial-cluster="pd1=http://192.168.174.134:2380" \ --log-file=/data/tidb/log/pd.log &
参数解释:https://github.com/pingcap/docs-cn/blob/master/op-guide/configuration.md#tidb
#在node2 node3 node4 上开启 TiKV
[root@node2 ~]# /usr/local/tidb-latest-linux-amd64/bin/tikv-server --pd="192.168.174.134:2379" --addr="192.168.174.136:20160" --data-dir=/data/tidb/data --log-file=/data/tidb/log/tikv.log & [root@node3 ~]# /usr/local/tidb-latest-linux-amd64/bin/tikv-server --pd="192.168.174.134:2379" --addr="192.168.174.137:20160" --data-dir=/data/tidb/data --log-file=/data/tidb/log/tikv.log & [root@node4 ~]# /usr/local/tidb-latest-linux-amd64/bin/tikv-server --pd="192.168.174.134:2379" --addr="192.168.174.138:20160" --data-dir=/data/tidb/data --log-file=/data/tidb/log/tikv.log &
参数解释:https://github.com/pingcap/docs-cn/blob/master/op-guide/configuration.md#tidb
#在node1 上开启TiDB
[root@node1 ~]# /usr/local/tidb-latest-linux-amd64/bin/tidb-server --store=tikv --path="192.168.174.134:2379" --log-file=/data/tidb/log/tidb.log &
#登陆数据库
[root@node1 ~]# yum install -y mariadb #安装mariadb数据库客户端 [root@node1 ~]# MySQL -uroot -h 192.168.174.134 -P 4000 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.1-TiDB-1.0 MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | INFORMATION_SCHEMA | | PERFORMANCE_SCHEMA | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) MySQL [(none)]> select host,user from mysql.user ; +------+------+ | host | user | +------+------+ | % | root | +------+------+ 1 row in set (0.00 sec) MySQL [(none)]> exit Bye
#集群状态
TiDB 对外暴露的 HTTP 接口是 http://host:port/status,默认的端口号是 10080 (可以通过 --status 参数设置),
可以通过访问这个接口获取当前 TiDB Server 的状态,以及判断是否存活。返回结果是 Json 格式:
[root@node1 ~]# curl 192.168.174.134:10080/status {"connections":0,"version":"5.7.1-TiDB-1.0","git_hash":"d6ec37bb4219e95babce41bd0400d04d84b1fb88"}
PD Server
PD API 地址: http://${host}:${port}/pd/api/v1/${api_name}
其中 port 默认为 2379,各类 api_name 详细信息参见
https://cdn.rawgit.com/pingcap/docs/master/op-guide/pd-api-v1.html
[root@node1 ~]# curl 192.168.174.134:2379/pd/api/v1/stores { "count": 3, "stores": [ { "store": { "id": 1, "address": "192.168.174.138:20160", "state": 0, "state_name": "Up" }, "status": { "store_id": 1, "capacity": "19 GB", "available": "17 GB", "leader_count": 1, "region_count": 1, "sending_snap_count": 0, "receiving_snap_count": 0, "applying_snap_count": 0, "is_busy": false, "start_ts": "2017-05-13T03:16:51+08:00", "last_heartbeat_ts": "2017-05-13T03:23:58.709890548+08:00", "uptime": "7m7.709890548s" } }, { "store": { "id": 4, "address": "192.168.174.137:20160", "state": 0, "state_name": "Up" }, "status": { "store_id": 4, "capacity": "19 GB", "available": "16 GB", "leader_count": 0, "region_count": 1, "sending_snap_count": 0, "receiving_snap_count": 0, "applying_snap_count": 0, "is_busy": false, "start_ts": "2017-05-12T18:17:02+08:00", "last_heartbeat_ts": "2017-05-13T03:24:00.555315502+08:00", "uptime": "9h7m58.555315502s" } }, { "store": { "id": 5, "address": "192.168.174.136:20160", "state": 0, "state_name": "Up" }, "status": { "store_id": 5, "capacity": "16 GB", "available": "13 GB", "leader_count": 0, "region_count": 1, "sending_snap_count": 0, "receiving_snap_count": 0, "applying_snap_count": 0, "is_busy": false, "start_ts": "2017-05-12T18:17:02+08:00", "last_heartbeat_ts": "2017-05-13T03:23:56.955220422+08:00", "uptime": "9h7m54.955220422s" } } ] } [root@node1 ~]#
分享题目:TiDB分布式数据库(二)
网页URL:http://scyanting.com/article/jossos.html