分布式数据库TiDB的部署(一)

为什么80%的码农都做不了架构师?>>>   hot3.png

前段时间DBGeek有一篇推文,是关于分布式数据库TiDB的介绍,吸引我的是他的口号,喊得震天响:水平线性扩展高可用、分布式事务、跨数据中心的一致性保证。虽然还没出GA版本,好奇之下翻了下文档,照着官方文档简单安装一下。

一、环境
CentOS Linux release 7.3.1611 (Core)

二、架构
摘自官方文档,主要是三个模块,PD模块、TiDB模块和TiKV模块,三个模块的各自功能:
TiDB Server
TiDB Server 负责接收 SQL 请求,处理 SQL 相关的逻辑,并通过 PD 找到存储计算所需数据的 TiKV 地址,与 TiKV 交互获取数据,最终返回结果。 TiDB Server 是无状态的,其本身并不存储数据,只负责计算,可以无限水平扩展,可以通过负载均衡组件(如 LVS、HAProxy 或 F5)对外提供统一的接入地址。

PD Server
Placement Driver (简称 PD) 是整个集群的管理模块,其主要工作有三个: 一是存储集群的元信息(某个 Key 存储在哪个 TiKV 节点);二是对 TiKV 集群进行调度和负载均衡(如数据的迁移、Raft group leader 的迁移等);三是分配全局唯一且递增的事务 ID。
PD 是一个集群,需要部署奇数个节点,一般线上推荐至少部署 3 个节点。

TiKV Server
TiKV Server 负责存储数据,从外部看 TiKV 是一个分布式的提供事务的 Key-Value 存储引擎。存储数据的基本单位是 Region,每个 Region 负责存储一个 Key Range (从 StartKey 到 EndKey 的左闭右开区间)的数据,每个 TiKV 节点会负责多个 Region 。TiKV 使用 Raft 协议做复制,保持数据的一致性和容灾。副本以 Region 为单位进行管理,不同节点上的多个 Region 构成一个 Raft Group,互为副本。数据在多个 TiKV 之间的负载均衡由 PD 调度,这里也是以 Region 为单位进行调度。


分布式数据库TiDB的部署(一)_第1张图片

三、安装
用了简易安装,就一台服务器

1.下载安装包
wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
wget http://download.pingcap.org/tidb-latest-linux-amd64.sha256

2.检查完整性
[root@temp TiDB]# ls -l
total 67408
-rw-r--r-- 1 root root          97 May  4 10:15 tidb-latest-linux-amd64.sha256
-rw-r--r-- 1 root root    69019625 May  4 10:15 tidb-latest-linux-amd64.tar.gz
[root@temp TiDB]# sha256sum -c tidb-latest-linux-amd64.sha256
tidb-latest-linux-amd64.tar.gz: OK

3.解压安装
tar -xzf tidb-latest-linux-amd64.tar.gz
cd tidb-latest-linux-amd64
mkdir -p /data/tidb
ln -s /root/software/tidb/tidb-latest-linux-amd64/bin/pd-tso-bench /usr/bin
ln -s /root/software/tidb/tidb-latest-linux-amd64/bin/tikv-server  /usr/bin/
ln -s /root/software/tidb/tidb-latest-linux-amd64/bin/tidb-server  /usr/bin/
ln -s /root/software/tidb/tidb-latest-linux-amd64/bin/pd-server    /usr/bin/
ln -s /root/software/tidb/tidb-latest-linux-amd64/bin/pd-ctl       /usr/bin/


四、启动

1.启动PD
[root@temp bin]# ./pd-server -data-dir=/data/tidb/pd  -log-file=/data/tidb/log/pd.log -name=pd1 &

日志输出
2017/05/04 13:43:23 util.go:58: [info] Welcome to Placement Driver (PD).
2017/05/04 13:43:23 util.go:59: [info] Version:
2017/05/04 13:43:23 util.go:60: [info] Git Commit Hash: cced626b9477a028a8fdc1c81f75f11f8f214752
2017/05/04 13:43:23 util.go:61: [info] UTC Build Time: 2017-05-03 01:29:53
2017/05/04 13:43:23 metricutil.go:83: [info] disable Prometheus push client
2017/05/04 13:43:23 server.go:109: [info] PD config - Config({FlagSet:0xc4202020c0 Version:false 
...
172.23.195.23:2379, this is strongly discouraged!]
2017/05/04 13:43:23 server.go:194: [info] init cluster id 6416151155803689316
2017/05/04 13:43:23 tso.go:106: [info] sync and save timestamp: last 0001-01-01 00:00:00 +0000 UTC save 2017-05-04 13:43:26.769379123 +0800 CST
2017/05/04 13:43:23 leader.go:209: [info] PD cluster leader pd1 is ready to serve

2.启动TiKV
[root@temp bin]#./tikv-server --pd="127.0.0.1:2379" --data-dir=/data/tidb/tikv --log-file=/data/tidb/log/tikv.log  &

日志输出
2017/05/04 15:01:00.532 mod.rs:403: [INFO] Welcome to TiKV.
2017/05/04 15:01:00.532 mod.rs:404: [INFO] Version:
2017/05/04 15:01:00.532 mod.rs:405: [INFO] Git Commit Hash: d16f69898c04be729775291c936df290b54c79d9
2017/05/04 15:01:00.532 mod.rs:406: [INFO] UTC Build Time:  2017-05-04 03:35:37
2017/05/04 15:01:00.532 mod.rs:407: [INFO] Rustc Version:   1.17.0-nightly (7846dbe0c 2017-03-26)
...
2017/05/04 15:01:10.437 tikv-server.rs:179: [INFO] metric.interval use default Some(0)
2017/05/04 15:01:10.437 tikv-server.rs:836: [INFO] start storage
2017/05/04 15:01:10.438 tikv-server.rs:841: [INFO] Start listening on 127.0.0.1:20160...
2017/05/04 15:01:10.445 mod.rs:198: [INFO] starting working thread: end-point-worker
2017/05/04 15:01:10.445 mod.rs:198: [INFO] starting working thread: snap-handler
2017/05/04 15:01:10.445 server.rs:153: [INFO] TiKV is ready to serve

3.启动TiDB
[root@test04 bin]# ./tidb-server -L info -store=tikv --path=/data/tidb/tidb --path=127.0.0.1:2379 -log-file=/data/tidb/log/tidb.log  &

日志输出
2017/05/04 15:13:43 printer.go:31: [info] Welcome to TiDB.
2017/05/04 15:13:43 printer.go:32: [info] Version:
2017/05/04 15:13:43 printer.go:33: [info] Git Commit Hash: c8e674e6d45e16e66367b508b0b94e6f1b788e24
2017/05/04 15:13:43 printer.go:34: [info] UTC Build Time:  2017-05-04 02:35:50
2017/05/04 15:13:43 client.go:96: [info] [pd] create pd client with endpoints [172.23.195.23:2379]
2017/05/04 15:13:43 client.go:186: [info] [pd] leader switches to: http://172.23.195.23:2379, previous: 
2017/05/04 15:13:43 client.go:114: [info] [pd] init cluster id 6416151155803689316
2017/05/04 15:13:43 gc_worker.go:104: [info] [gc worker] 56f493abb540002 start.
2017/05/04 15:13:43 tidb.go:68: [info] store tikv-6416151155803689316 new domain, lease 1s
2017/05/04 15:13:43 ddl.go:229: [info] start DDL:ff4a4105-6c2a-44ec-ad68-cb7f94e707ca
2017/05/04 15:13:43 domain.go:95: [info] [ddl] full load InfoSchema from version 0 to 12, in 10.561365ms
2017/05/04 15:13:43 server.go:152: [info] Server run MySQL Protocol Listen at [0.0.0.0:4000]
2017/05/04 15:13:43 main.go:204: [info] disable Prometheus push client 
2017/05/04 15:13:43 client.go:96: [info] [pd] create pd client with endpoints [172.23.195.23:2379]
2017/05/04 15:13:43 systime_mon.go:11: [info] start system time monitor 
2017/05/04 15:13:43 client.go:186: [info] [pd] leader switches to: http://172.23.195.23:2379, previous: 
2017/05/04 15:13:43 client.go:114: [info] [pd] init cluster id 6416151155803689316
2017/05/04 15:13:43 http_status.go:78: [info] Listening on :10080 for status and metrics report.


五、登陆
因为是用的mysql的协议和兼容语法,可以用mysql的登陆方式登陆

[root@test04 ~]# mysql  -h 127.0.0.1 -P 4000 -u root -D test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.1-TiDB-1.0 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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 databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> create database db_kenyon;
Query OK, 0 rows affected (2.04 sec)

mysql> use db_kenyon;
Database changed
mysql> show tables;
Empty set (0.00 sec)

六、总结
暂时只是了解了一下他的框架和代码实现,和一款叫小强的数据库比较相近,功能上结合传统RDBMS和缓存KV的实现,又比较像PostgreSQL,这个产品目前还只是RC版本,新出世也没多久,上生产慎重,安装操作很简单,对于习惯了Mysql的人来说比较方便,后续再测试一下它的性能和扩展功能。

七、参考:
1.https://www.pingcap.com/doc-binary-deployment-zh#
2.https://www.pingcap.com/doc-recommendation-zh

转载于:https://my.oschina.net/Kenyon/blog/898482

你可能感兴趣的:(分布式数据库TiDB的部署(一))