diff --git a/op-guide/clustering.md b/op-guide/clustering.md new file mode 100644 index 0000000000000..401f5bc64b835 --- /dev/null +++ b/op-guide/clustering.md @@ -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 + ``` diff --git a/op-guide/docker.md b/op-guide/docker.md new file mode 100644 index 0000000000000..e6f76a54957d7 --- /dev/null +++ b/op-guide/docker.md @@ -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. \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index cb07fb74edcb6..7e441660581ec 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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. @@ -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