-
Notifications
You must be signed in to change notification settings - Fork 1.2k
op-guide: Add document for deploying TiDB with docker #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8244828
op-guide: Add document for deploying TiDB with docker
shenli aaa45b8
*: Address comment
shenli 39f587e
*: Address comment
shenli 1af1d33
op-guide: update docker.
siddontang 8c52713
Merge pull request #2 from pingcap/siddontang/fix-docker
shenli f5f2783
*: Address comment
shenli d705b35
*: Address comment
shenli 4bc629d
*: Address comment
shenli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # 使用 Docker 构建和运行 TiDB | ||
|
|
||
| 本文档用于说明如何使用 Docker 部署 TiDB 服务。 | ||
|
|
||
| ## Docker 安装和环境准备 | ||
|
|
||
| #### 安装 Docker | ||
| 使用 Docker 可以非常快速搭建起一套 TiDB 环境。Docker 可以方便地在 Linux / Mac OS X / Windows 环境上安装,安装过程可参考 Docker 官网 https://docs.docker.com/ 。 | ||
|
|
||
| #### 准备环境 | ||
| 完整的 TiDB 运行需要三个组件,TiDB, TiKV 和 PD。 | ||
| * tidb-server 是 TiDB 的执行进程,负责客户端的接入,对用户的 SQL 进行解析、优化和执行,分解成下层的 KV 操作,并将执行结果进行聚合返回给客户端。TiDB 对外兼容 MySQL 协议,可以直接使用 MySQL Client 进行测试。 | ||
| * tikv-server,作为 TiDB 的分布式 KV 存储引擎,可以在网络互通的多机环境部署,使用 Raft 协议实现强一致性的数据复制,当多数派节点存活时 TiKV 保持可用状态。 | ||
| * pd-server,负责 TiKV 的 Region 路由信息的维护和存储,并协调处理 Region 的 rebalance 以及 merge 和 split 等操作。每个集群需要部署奇数个 PD 实例。 | ||
|
|
||
| 获取 TiDB, TiKV, PD 的 Docker 镜像可以直接拉 Docker Hub 发布的 latest 镜像。 | ||
|
|
||
| ``` | ||
| docker pull pingcap/tidb | ||
| docker pull pingcap/tikv | ||
| docker pull pingcap/pd | ||
| ``` | ||
|
|
||
| github.com/pingcap 中的 repo 都包含 Dockerfile,也可以自行 build 镜像 | ||
|
|
||
| ``` | ||
| git clone https://github.com/pingcap/tidb.git | ||
| cd tidb && docker build -t pingcap/tidb . | ||
|
|
||
| git clone https://github.com/pingcap/tikv.git | ||
| cd tikv && docker build -t pingcap/tikv . | ||
|
|
||
| git clone https://github.com/pingcap/pd.git | ||
| cd pd && docker build -t pingcap/pd . | ||
| ``` | ||
|
|
||
| ## 使用单机存储引擎 | ||
| tidb-server 默认运行在单机存储引擎,使用本机的 goleveldb 作为存储引擎,不依赖 TiKV。 | ||
| 使用 docker 可以直接启动: | ||
| ``` | ||
| docker run -d --name tidb-server \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
| -p 4000:4000 \ | ||
| -p 10080:10080 \ | ||
| pingcap/tidb:latest \ | ||
| -L info --path /tmp/tidb | ||
| ``` | ||
|
|
||
| 这样就在 4000 端口上启动了 tidb-server,可以使用 mysql client 连接 tidb-server: | ||
| ``` | ||
| mysql -h 127.0.0.1 -P 4000 -u root -D test | ||
| ``` | ||
|
|
||
| ## 使用 TiKV 存储引擎 | ||
| 使用 TiKV 作为存储引擎可以构建分布式数据库。集群环境下多机部署 TiDB,可以使用端口映射,例如在三台机器上部署 1个 PD,3个 TiKV,1个 TiDB: | ||
|
|
||
| #### 定义 host 机器 ip | ||
| ``` | ||
| host_ip1=192.168.1.100 | ||
| host_ip2=192.168.1.101 | ||
| host_ip3=192.168.1.102 | ||
| ``` | ||
|
|
||
| #### 启动一个仅作为数据存储的 Docker 容器 | ||
| 三台机器上个启动一个存储用容器 | ||
| ``` | ||
| docker run -d --name ti-storage \ | ||
| -v /ti-data \ | ||
| busybox:latest | ||
| ``` | ||
|
|
||
| #### 启动 pd-server | ||
| ``` | ||
| docker run -d --name pd \ | ||
| -p 1234:1234 \ | ||
| -p 9090:9090 \ | ||
| -p 2379:2379 \ | ||
| -p 2380:2380 \ | ||
| -v /usr/share/ca-certificates/:/etc/ssl/certs \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
| --volumes-from ti-storage \ | ||
| pingcap/pd:latest \ | ||
| --addr=0.0.0.0:1234 \ | ||
| --advertise-addr=${host_ip1}:1234 \ | ||
| --http-addr=0.0.0.0:9090 \ | ||
| --name=pd \ | ||
| --data-dir=/tidata/pd \ | ||
| --advertise-client-urls=http://${host_ip1}:2379 \ | ||
| --advertise-peer-urls=http://${host_ip1}:2380 \ | ||
| --initial-cluster=pd=http://${host_ip1}:2380 \ | ||
| --peer-urls=http://0.0.0.0:2380 \ | ||
| --client-urls=http://0.0.0.0:2379 \ | ||
| -L info \ | ||
| --cluster-id=1 | ||
| ``` | ||
|
|
||
| #### 启动 tikv-server | ||
| 在三台机器上分别启动 TiKV 服务 | ||
| ``` | ||
| # 机器1 | ||
| docker run -d --name tikv1 \ | ||
| -p 20160:20160 \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alignment
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @qiuyesuifeng PTAL |
||
| --volumes-from ti-storage \ | ||
| pingcap/tikv:latest \ | ||
| -S raftkv \ | ||
| --addr=0.0.0.0:20160 \ | ||
| --advertise-addr=${host_ip1}:20160\ | ||
| --pd=${host_ip1}:2379 \ | ||
| --store=/ti-data/tikv \ | ||
| --cluster-id=1 | ||
|
|
||
| # 机器2 | ||
| docker run -d --name tikv2 \ | ||
| -p 20160:20160 \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
| --volumes-from ti-storage \ | ||
| pingcap/tikv:latest \ | ||
| -S raftkv \ | ||
| --addr=0.0.0.0:20160 \ | ||
| --advertise-addr=${host_ip2}:20160\ | ||
| --pd=${host_ip1}:2379 \ | ||
| --store=/ti-data/tikv \ | ||
| --cluster-id=1 | ||
|
|
||
| # 机器3 | ||
| docker run -d --name tikv3 \ | ||
| -p 20160:20160 \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
| --volumes-from ti-storage \ | ||
| pingcap/tikv:latest \ | ||
| -S raftkv \ | ||
| --addr=0.0.0.0:20160 \ | ||
| --advertise-addr=${host_ip3}:20160\ | ||
| --pd=${host_ip1}:2379 \ | ||
| --store=/ti-data/tikv \ | ||
| --cluster-id=1 | ||
| ``` | ||
|
|
||
| #### 启动 tidb-server | ||
| ``` | ||
| docker run -d --name tidb \ | ||
| -p 4000:4000 \ | ||
| -v /etc/localtime:/etc/localtime:ro \ | ||
| pingcap/tidb:latest \ | ||
| -L info \ | ||
| --store=tikv \ | ||
| --path="${host_ip1}:2379?cluster=1" \ | ||
| -P 4000 | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this volume used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure. @iamxy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-v /etc/localtime:/etc/localtime:ro, this set timezone in docker as same as in host.