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 ~]#
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341