We are currently refactoring our documentation. Please excuse any problems you may find and report them here.

This guide describes how to deploy a multi-node TiKV cluster using Docker.

The TiKV team strongly recommends you use the Ansible Deployment method. It is the method our team uses when we assist with deployment.

Other methods are documented for informational purposes. We strongly recommend consulting with our contributors before depending on a cluster deployed without the Ansible scripts.

Prerequisites

Make sure that Docker is installed on each machine.

For more details about prerequisites, see Hardware and Software Requirements.

Deploy the TiKV cluster on multiple nodes

Assume that you have 6 machines with the following details:

NameHost IPServicesData Path
Node1192.168.1.101PD1/data
Node2192.168.1.102PD2/data
Node3192.168.1.103PD3/data
Node4192.168.1.104TiKV1/data
Node5192.168.1.105TiKV2/data
Node6192.168.1.106TiKV3/data

If you want to test TiKV with a limited number of nodes, you can also use one PD instance to test the entire cluster.

Step 1: Pull the latest images of TiKV and PD from Docker Hub

Start Docker and pull the latest images of TiKV and PD from Docker Hub using the following command:

  1. docker pull pingcap/tikv:latest
  2. docker pull pingcap/pd:latest

Step 2: Log in and start PD

Log in to the three PD machines and start PD respectively:

Start PD1 on Node1:

  1. docker run -d --name pd1 \
  2. -p 2379:2379 \
  3. -p 2380:2380 \
  4. -v /etc/localtime:/etc/localtime:ro \
  5. -v /data:/data \
  6. pingcap/pd:latest \
  7. --name="pd1" \
  8. --data-dir="/data/pd1" \
  9. --client-urls="http://0.0.0.0:2379" \
  10. --advertise-client-urls="http://192.168.1.101:2379" \
  11. --peer-urls="http://0.0.0.0:2380" \
  12. --advertise-peer-urls="http://192.168.1.101:2380" \
  13. --initial-cluster="pd1=http://192.168.1.101:2380,pd2=http://192.168.1.102:2380,pd3=http://192.168.1.103:2380"

Start PD2 on Node2:

  1. docker run -d --name pd2 \
  2. -p 2379:2379 \
  3. -p 2380:2380 \
  4. -v /etc/localtime:/etc/localtime:ro \
  5. -v /data:/data \
  6. pingcap/pd:latest \
  7. --name="pd2" \
  8. --data-dir="/data/pd2" \
  9. --client-urls="http://0.0.0.0:2379" \
  10. --advertise-client-urls="http://192.168.1.102:2379" \
  11. --peer-urls="http://0.0.0.0:2380" \
  12. --advertise-peer-urls="http://192.168.1.102:2380" \
  13. --initial-cluster="pd1=http://192.168.1.101:2380,pd2=http://192.168.1.102:2380,pd3=http://192.168.1.103:2380"

Start PD3 on Node3:

  1. docker run -d --name pd3 \
  2. -p 2379:2379 \
  3. -p 2380:2380 \
  4. -v /etc/localtime:/etc/localtime:ro \
  5. -v /data:/data \
  6. pingcap/pd:latest \
  7. --name="pd3" \
  8. --data-dir="/data/pd3" \
  9. --client-urls="http://0.0.0.0:2379" \
  10. --advertise-client-urls="http://192.168.1.103:2379" \
  11. --peer-urls="http://0.0.0.0:2380" \
  12. --advertise-peer-urls="http://192.168.1.103:2380" \
  13. --initial-cluster="pd1=http://192.168.1.101:2380,pd2=http://192.168.1.102:2380,pd3=http://192.168.1.103:2380"

Step 3: Log in and start TiKV

Log in to the three TiKV machines and start TiKV respectively:

Start TiKV1 on Node4:

  1. docker run -d --name tikv1 \
  2. -p 20160:20160 \
  3. -v /etc/localtime:/etc/localtime:ro \
  4. -v /data:/data \
  5. pingcap/tikv:latest \
  6. --addr="0.0.0.0:20160" \
  7. --advertise-addr="192.168.1.104:20160" \
  8. --data-dir="/data/tikv1" \
  9. --pd="192.168.1.101:2379,192.168.1.102:2379,192.168.1.103:2379"

Start TiKV2 on Node5:

  1. docker run -d --name tikv2 \
  2. -p 20160:20160 \
  3. -v /etc/localtime:/etc/localtime:ro \
  4. -v /data:/data \
  5. pingcap/tikv:latest \
  6. --addr="0.0.0.0:20160" \
  7. --advertise-addr="192.168.1.105:20160" \
  8. --data-dir="/data/tikv2" \
  9. --pd="192.168.1.101:2379,192.168.1.102:2379,192.168.1.103:2379"

Start TiKV3 on Node6:

  1. docker run -d --name tikv3 \
  2. -p 20160:20160 \
  3. -v /etc/localtime:/etc/localtime:ro \
  4. -v /data:/data \
  5. pingcap/tikv:latest \
  6. --addr="0.0.0.0:20160" \
  7. --advertise-addr="192.168.1.106:20160" \
  8. --data-dir="/data/tikv3" \
  9. --pd="192.168.1.101:2379,192.168.1.102:2379,192.168.1.103:2379"

You can check whether the TiKV cluster has been successfully deployed using the following command:

  1. curl 192.168.1.101:2379/pd/api/v1/stores

If the state of all the TiKV instances is “Up”, you have successfully deployed a TiKV cluster.

What’s next?

If you want to try the Go client, see Try Two Types of APIs.