Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions op-guide/clustering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Clustering

## Overview

A complete TiDB project contains PD, TiKV, TiDB. The start-up sequence is PD -> TiKV -> TiDB.

## A standalone cluster

1. Start PD.

```bash
pd-server --cluster-id=1 \
--data-dir=pd
```

2. Start TiKV.

```bash
tikv-server -I 1 \
-S raftkv \
--pd 127.0.0.1:2379 \
-s tikv
```

3. Start TiDB.

```bash
tidb-server --store=tikv \
--path="127.0.0.1:2379?cluster=1"
```

4. Use the official `mysql` client to connect to TiDB and enjoy it.

```sh
mysql -h 127.0.0.1 -P 4000 -u root -D test
```

## A 3-node multi-machine cluster

Assume we have three machines with the following details:

|Name|Host IP|
|----|-------|
|node1|192.168.199.113|
|node2|192.168.199.114|
|node3|192.168.199.115|

We run PD and TiKV on every node and TiDB on node1 only.

1. Start PD on every node.

```bash
pd-server --cluster-id=1 \
--name=pd1 \
--data-dir=pd1 \
--addr="192.168.199.113:1234" \
--client-urls="http://192.168.199.113:2379" \
--peer-urls="http://192.168.199.113:2380" \
--initial-cluster="pd1=http://192.168.199.113:2380,pd2=http://192.168.199.114:2380,pd3=http://192.168.199.115:2380"

pd-server --cluster-id=1 \
--name=pd2 \
--data-dir=pd2 \
--addr="192.168.199.114:1234" \
--client-urls="http://192.168.199.114:2379" \
--peer-urls="http://192.168.199.114:2380" \
--initial-cluster="pd1=http://192.168.199.113:2380,pd2=http://192.168.199.114:2380,pd3=http://192.168.199.115:2380"

pd-server --cluster-id=1 \
--name=pd3 \
--data-dir=pd3 \
--addr="192.168.199.115:1234" \
--client-urls="http://192.168.199.115:2379" \
--peer-urls="http://192.168.199.115:2380" \
--initial-cluster="pd1=http://192.168.199.113:2380,pd2=http://192.168.199.114:2380,pd3=http://192.168.199.115:2380"
```

2. Start TiKV on every node.

```bash
tikv-server -S raftkv \
-I 1 \
--pd 192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379 \
--addr 192.168.199.113:20160 \
-s tikv1

tikv-server -S raftkv \
-I 1 \
--pd 192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379 \
--addr 192.168.199.114:20160 \
-s tikv2

tikv-server -S raftkv \
-I 1 \
--pd 192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379 \
--addr 192.168.199.115:20160 \
-s tikv3
```

3. Start TiDB on node1.

```bash
tidb-server --store=tikv \
--path="192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379?cluster=1"
```

4. Use the official `mysql` client to connect to TiDB and enjoy it.

```sh
mysql -h 192.168.199.113 -P 4000 -u root -D test
```
162 changes: 162 additions & 0 deletions op-guide/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Docker

## Run with `docker-compose`

A simple `docker-compose.yml`:


```bash
version: '2'

services:
pd1:
image: pingcap/pd
ports:
- "1234"
- "9090"
- "2379"
- "2380"

command:
- --cluster-id=1
- --name=pd1
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://pd1:2379
- --advertise-peer-urls=http://pd1:2380
- --initial-cluster=pd1=http://pd1:2380,pd2=http://pd2:2380,pd3=http://pd3:2380
- --addr=0.0.0.0:1234
- --advertise-addr=pd1:1234

privileged: true

pd2:
image: pingcap/pd
ports:
- "1234"
- "9090"
- "2379"
- "2380"

command:
- --cluster-id=1
- --name=pd2
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://pd2:2379
- --advertise-peer-urls=http://pd2:2380
- --initial-cluster=pd1=http://pd1:2380,pd2=http://pd2:2380,pd3=http://pd3:2380
- --addr=0.0.0.0:1234
- --advertise-addr=pd2:1234

privileged: true

pd3:
image: pingcap/pd
ports:
- "1234"
- "9090"
- "2379"
- "2380"

command:
- --cluster-id=1
- --name=pd3
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://pd3:2379
- --advertise-peer-urls=http://pd3:2380
- --initial-cluster=pd1=http://pd1:2380,pd2=http://pd2:2380,pd3=http://pd3:2380
- --addr=0.0.0.0:1234
- --advertise-addr=pd3:1234

privileged: true

tikv1:
image: pingcap/tikv
ports:
- "20160"

command:
- --cluster-id=1
- --addr=0.0.0.0:20160
- --advertise-addr=tikv1:20160
- --dsn=raftkv
- --store=/var/tikv
- --pd=pd1:2379,pd2:2379,pd3:2379

depends_on:
- "pd1"
- "pd2"
- "pd3"

entrypoint: /tikv-server

privileged: true

tikv2:
image: pingcap/tikv
ports:
- "20160"

command:
- --cluster-id=1
- --addr=0.0.0.0:20160
- --advertise-addr=tikv2:20160
- --dsn=raftkv
- --store=/var/tikv
- --pd=pd1:2379,pd2:2379,pd3:2379

depends_on:
- "pd1"
- "pd2"
- "pd3"

entrypoint: /tikv-server

privileged: true

tikv3:
image: pingcap/tikv
ports:
- "20160"

command:
- --cluster-id=1
- --addr=0.0.0.0:20160
- --advertise-addr=tikv3:20160
- --dsn=raftkv
- --store=/var/tikv
- --pd=pd1:2379,pd2:2379,pd3:2379

depends_on:
- "pd1"
- "pd2"
- "pd3"

entrypoint: /tikv-server

privileged: true

tidb:
image: pingcap/tidb
ports:
- "4000"

command:
- --store=tikv
- --path=pd1:2379,pd2:2379,pd3:2379?cluster=1
- -L=warn

depends_on:
- "tikv1"
- "tikv2"
- "tikv3"

privileged: true
```

+ Use `docker-compose up -d` to create and start the cluster.
+ Use `docker-compose port tidb 4000` to print the TiDB public port. For example, if the output is `0.0.0.0:32966`, the TiDB public port is `32966`.
+ Use `mysql -h 127.0.0.1 -P 32966 -u root -D test` to connect to TiDB and enjoy it.
+ Use `docker-compose down` to stop and remove the cluster.
4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

# Use current path for building and installing TiDB.
TIDB_PATH=`PWD`
TIDB_PATH=`pwd`
echo "building TiDB components in $TIDB_PATH"

# All the binaries are installed in the `bin` directory.
Expand All @@ -25,7 +25,7 @@ rustc -V
# GOPATH should be set correctly.
export GOPATH=$TIDB_PATH/deps/go

build TiDB
# build TiDB
echo "building TiDB..."
rm -rf $GOPATH/src/github.com/pingcap/tidb
git clone --depth=1 https://github.com/pingcap/tidb.git $GOPATH/src/github.com/pingcap/tidb
Expand Down