溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

TiDB 分布式數(shù)據(jù)庫(二)

發(fā)布時(shí)間:2020-07-07 16:37:51 來源:網(wǎng)絡(luò) 閱讀:885 作者:chaunceyjiang 欄目:數(shù)據(jù)庫


#

# TiDB :A Distributed SQL Database

# github :https://github.com/pingcap/tidb

# doc : https://github.com/pingcap/docs-cn 

#


#架構(gòu)

Name
Host IPServices
node1192.168.174.134
PD, TiDB
node2192.168.174.136TiKV1
node3192.168.174.137TiKV2
node4192.168.174.138TiKV3


#軟件下載(每臺(tái)都需操作)

[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


#開啟服務(wù)(注:集群的啟動(dòng)順序不能錯(cuò))

#在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 &


參數(shù)解釋: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 &


參數(shù)解釋: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 &


#登陸數(shù)據(jù)庫

[root@node1 ~]# yum install -y mariadb                        #安裝mariadb數(shù)據(jù)庫客戶端
[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



#集群狀態(tài)


TiDB 對(duì)外暴露的 HTTP 接口是 http://host:port/status,默認(rèn)的端口號(hào)是 10080 (可以通過 --status 參數(shù)設(shè)置),

可以通過訪問這個(gè)接口獲取當(dāng)前 TiDB Server 的狀態(tài),以及判斷是否存活。返回結(jié)果是 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 默認(rèn)為 2379,各類 api_name 詳細(xì)信息參見 

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 ~]#










向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI