• Stars
    star
    339
  • Rank 120,087 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TiDB docker-compose

Build Status

WARNING: This is for testing only, DO NOT USE IN PRODUCTION!

Requirements

  • Docker >= 17.03
  • Docker Compose >= 1.6.0

Note: Legacy Docker Toolbox users must migrate to Docker for Mac, since it is tested that tidb-docker-compose cannot be started on Docker Toolbox and Docker Machine. Note: It is recommended to disable SELinux.

Quick start

$ git clone https://github.com/pingcap/tidb-docker-compose.git
$ cd tidb-docker-compose && docker-compose pull # Get the latest Docker images
$ sudo setenforce 0 # Only on Linux
$ docker-compose up -d
$ mysql -h 127.0.0.1 -P 4000 -u root

Docker Swarm

You can also use Docker Swarm to deploy a TiDB Platform cluster, and then you can scale the service using docker stack commands.

$ docker swarm init # if your docker daemon is not already part of a swarm
$ mkdir -p data logs
$ docker stack deploy tidb -c docker-swarm.yml
$ mysql -h 127.0.0.1 -P 4000 -u root

After deploying the stack, you can scale the number of TiDB Server instances in the cluster like this:

$ docker service scale tidb_tidb=2

Docker Swarm automatically load-balances across the containers that implement a scaled service, which you can see if you execute select @@hostname several times:

$ mysql -h 127.0.0.1 -P 4000 -u root -te 'select @@hostname'
+--------------+
| @@hostname   |
+--------------+
| 340092e0ec9e |
+--------------+
$ mysql -h 127.0.0.1 -P 4000 -u root -te 'select @@hostname'
+--------------+
| @@hostname   |
+--------------+
| e6f05ffe6274 |
+--------------+
$ mysql -h 127.0.0.1 -P 4000 -u root -te 'select @@hostname'
+--------------+
| @@hostname   |
+--------------+
| 340092e0ec9e |
+--------------+

If you want to connect to specific backend instances, for example to test concurrency by ensuring that you are connecting to distinct instances of tidb-server, you can use the docker service ps command to assemble a hostname for each container:

$ docker service ps --no-trunc --format '{{.Name}}.{{.ID}}' tidb_tidb
tidb_tidb.1.x3sc2sd66a88phsj103ohr6qq
tidb_tidb.2.lk53apndq394cega46at853zw

To be able to resolve those hostnames, it's easiest to run the MySQL client in a container that has access to the swarm network:

$ docker run --rm --network=tidb_default arey/mysql-client -h tidb_tidb.1.x3sc2sd66a88phsj103ohr6qq -P 4000 -u root -t -e 'select @@version'
+-----------------------------------------+
| @@version                               |
+-----------------------------------------+
| 5.7.25-TiDB-v3.0.0-beta.1-40-g873d9514b |
+-----------------------------------------+

To loop through all instances of TiDB Server, you can use a bash loop like this:

for host in $(docker service ps --no-trunc --format '{{.Name}}.{{.ID}}' tidb_tidb)
    do docker run --rm --network tidb_default arey/mysql-client \
        -h "$host" -P 4000 -u root -te "select @@hostname"
done

To stop all services and remove all containers in the TiDB stack, execute docker stack rm tidb.

Customize TiDB Cluster

Configuration

If you find these configuration files outdated or mismatch with TiDB version, you can copy these files from their upstream repos and change their metrics addr with pushgateway:9091. Also max-open-files are configured to 1024 in tikv.toml to simplify quick start on Linux, because setting up ulimit on Linux with docker is quite tedious.

And config/*-dashboard.json are copied from TiDB-Ansible repo

You can customize TiDB cluster configuration by editing docker-compose.yml and the above config files if you know what you're doing.

But edit these files manually is tedious and error-prone, a template engine is strongly recommended. See the following steps

Install Helm

Helm is used as a template render engine

curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash

Or if you use Mac, you can use homebrew to install Helm by brew install kubernetes-helm

Bring up TiDB cluster

$ git clone https://github.com/pingcap/tidb-docker-compose.git
$ cd tidb-docker-compose
$ vi compose/values.yaml # custom cluster size, docker image, port mapping etc
$ helm template compose > generated-docker-compose.yaml
$ docker-compose -f generated-docker-compose.yaml pull # Get the latest Docker images
$ docker-compose -f generated-docker-compose.yaml up -d

# If you want to Bring up TiDB cluster with Binlog support
$ vi compose/values.yaml # set tidb.enableBinlog to true
$ helm template compose > generated-docker-compose-binlog.yaml
$ docker-compose -f generated-docker-compose-binlog.yaml up -d  # or you can use 'docker-compose-binlog.yml' file directly

# Note: If the value of drainer.destDBType is "kafka" and 
# you want to consume the kafka messages outside the docker containers,
# please update the kafka.advertisedHostName with your docker host IP in compose/values.yaml and 
# regenerate the 'generated-docker-compose-binlog.yaml' file

You can build docker image yourself for development test.

  • Build from binary

    For pd, tikv, tidb, pump and drainer comment their image and buildPath fields out. And then copy their binary files to pd/bin/pd-server, tikv/bin/tikv-server, tidb/bin/tidb-server, tidb-binlog/bin/pump and tidb-binlog/bin/drainer.

    These binary files can be built locally or downloaded from https://download.pingcap.org/tidb-latest-linux-amd64.tar.gz

    For tidbVision, comment its image and buildPath fields out. And then copy tidb-vision repo to tidb-vision/tidb-vision.

  • Build from source

    Leave pd, tikv, tidb and tidbVision image field empty and set their buildPath field to their source directory.

    For example, if your local tikv source directory is $GOPATH/src/github.com/pingcap/tikv, just set tikv buildPath to $GOPATH/src/github.com/pingcap/tikv

    Note: Compiling tikv from source consumes lots of memory, memory of Docker for Mac needs to be adjusted to greater than 6GB

tidb-vision is a visiualization page of TiDB Cluster, it's WIP project and can be disabled by commenting tidbVision out.

TiSpark is a thin layer built for running Apache Spark on top of TiDB/TiKV to answer the complex OLAP queries.

Host network mode (Linux)

Note: Docker for Mac uses a Linux virtual machine, host network mode will not expose any services to host machine. So it's useless to use this mode.

When using TiKV directly without TiDB, host network mode must be enabled. This way all services use host network without isolation. So you can access all services on the host machine.

You can enable this mode by setting networkMode: host in compose/values.yaml and regenerate docker-compose.yml. When in this mode, prometheus address in configuration files should be changed from prometheus:9090 to 127.0.0.1:9090, and pushgateway address should be changed from pushgateway:9091 to 127.0.0.1:9091.

These modification can be done by:

# Note: this only needed when networkMode is `host`
sed -i 's/pushgateway:9091/127.0.0.1:9091/g' config/*
sed -i 's/prometheus:9090/127.0.0.1:9090/g' config/*

After all the above is done, you can start tidb-cluster as usual by docker-compose -f generated-docker-compose.yml up -d

Debug TiDB/TiKV/PD instances

Prerequisites:

Pprof: This is a tool for visualization and analysis of profiling data. Follow these instructions to install pprof.

Graphviz: http://www.graphviz.org/, used to generate graphic visualizations of profiles.

  • debug TiDB or PD instances
### Use the following command to starts a web server for graphic visualizations of golang program profiles
$ ./tool/container_debug -s pd0 -p /pd-server -w

The above command will produce graphic visualizations of profiles of pd0 that can be accessed through the browser.

  • debug TiKV instances
### step 1: select a tikv instance(here is tikv0) and specify the binary path in container to enter debug container
$ ./tool/container_debug -s tikv0 -p /tikv-server

### after step 1, we can generate flame graph for tikv0 in debug container
$ ./run_flamegraph.sh 1  # 1 is the tikv0's process id

### also can fetch tikv0's stack informations with GDB in debug container
$ gdb /tikv-server 1 -batch -ex "thread apply all bt" -ex "info threads"

Access TiDB cluster

TiDB uses ports: 4000(mysql) and 10080(status) by default

$ mysql -h 127.0.0.1 -P 4000 -u root --comments

And Grafana uses port 3000 by default, so open your browser at http://localhost:3000 to view monitor dashboard

If you enabled tidb-vision, you can view it at http://localhost:8010

Access Spark shell and load TiSpark

Insert some sample data to the TiDB cluster:

$ docker-compose exec tispark-master bash
$ cd /opt/spark/data/tispark-sample-data
$ mysql --local-infile=1 -h tidb -P 4000 -u root --comments < dss.ddl

After the sample data is loaded into the TiDB cluster, you can access Spark Shell by docker-compose exec tispark-master /opt/spark/bin/spark-shell.

$ docker-compose exec tispark-master /opt/spark/bin/spark-shell
...
Spark context available as 'sc' (master = local[*], app id = local-1527045927617).
Spark session available as 'spark'.
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.1.1
      /_/

Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_172)
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.apache.spark.sql.TiContext
...
scala> val ti = new TiContext(spark)
...
scala> ti.tidbMapDatabase("TPCH_001")
...
scala> spark.sql("select count(*) from lineitem").show
+--------+
|count(1)|
+--------+
|   60175|
+--------+

You can also access Spark with Python or R using the following commands:

docker-compose exec tispark-master /opt/spark/bin/pyspark
docker-compose exec tispark-master /opt/spark/bin/sparkR

More documents about TiSpark can be found here.

More Repositories

1

tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://tidbcloud.com/free-trial
Go
36,134
star
2

talent-plan

open source training courses about distributed database and distributed systems
Rust
9,808
star
3

awesome-database-learning

A list of learning materials to understand databases internals
8,721
star
4

docs-cn

TiDB/TiKV/PD δΈ­ζ–‡ζ–‡ζ‘£
Shell
1,802
star
5

ossinsight

Analysis, Comparison, Trends, Rankings of Open Source Software, you can also get insight from more than 6 billion with natural language (powered by OpenAI). Follow us on Twitter: https://twitter.com/ossinsight
TypeScript
1,585
star
6

parser

A MySQL Compatible SQL Parser
Go
1,395
star
7

tidb-operator

TiDB operator creates and manages TiDB clusters running in Kubernetes.
Go
1,180
star
8

tiflash

The analytical engine for TiDB and TiDB Cloud. Try free: https://tidbcloud.com/free-trial
C++
929
star
9

tispark

TiSpark is built for running Apache Spark on top of TiDB/TiKV
Scala
878
star
10

failpoint

An implementation of failpoints for Golang.
Go
800
star
11

docs

TiDB database documentation.
Python
572
star
12

go-ycsb

A Go port of Yahoo! Cloud Serving Benchmark (YCSB)
Go
568
star
13

dm

Data Migration Platform
Go
455
star
14

tiflow

This repo maintains DM (a data migration platform) and TiCDC (change data capture for TiDB)
Go
411
star
15

tiup

A component manager for TiDB
Go
399
star
16

ossinsight-lite

🚧[WIP] Yet another customizable free GitHub stats dashboard based on TiDB Serverless: https://ossinsight-lite.vercel.app, hand-drawn style.
TypeScript
375
star
17

presentations

362
star
18

tidb-ansible

Python
326
star
19

tidb-binlog

A tool used to collect and merge tidb's binlog for real-time data backup and synchronization.
Go
289
star
20

tla-plus

TLA
289
star
21

dumpling

Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).
Go
280
star
22

tidb-tools

tidb-tools are some useful tool collections for TiDB.
Go
279
star
23

community

TiDB community content
258
star
24

chaos

A test framework for linearizability check with Go
Go
203
star
25

tidb-dashboard

A Web UI for monitoring, diagnosing and managing the TiDB cluster.
TypeScript
170
star
26

go-tpc

A toolbox to benchmark TPC workloads in Go
Go
162
star
27

kvproto

Protocol buffer files for TiKV
CMake
149
star
28

tidb-lightning

This repository has been moved to https://github.com/pingcap/br
Go
142
star
29

tipocket

A toolkit for testing TiDB
Go
135
star
30

blog-cn

Shell
126
star
31

br

A command-line tool for distributed backup and restoration of the TiDB cluster data
Go
123
star
32

tidb-dev-guide

A comprehensive development guide to help you be more and more familiar with the TiDB community and become an expert finally.
116
star
33

tidb-bench

A Simple Benchmark For TiDB
C
108
star
34

gdocwiki

A wiki based on Google Doc / Drive
TypeScript
97
star
35

tipb

TiDB protobuf
CMake
92
star
36

tidb-map

A series of maps to help users and contributors
91
star
37

style-guide

Style guide for PingCAP and TiKV code
78
star
38

go-randgen

a QA tool to random generate sql by bnf pattern
Go
74
star
39

benchmarksql

Unofficial mirror of benchmarksql on github
Java
70
star
40

mysql-tester

A Golang implementation of MySQL Test Framework
Go
60
star
41

weekly

57
star
42

tidb-prisma-vercel-demo

Virtual online bookstore application demo which you can find books of various categories and rate the books.
TypeScript
52
star
43

advanced-statefulset

Go
52
star
44

tiproxy

Go
50
star
45

blog

Python
48
star
46

docs-tidb-operator

Documentation for TiDB on Kubernetes in both English and Chinese.
Python
45
star
47

tikv-client-lib-java

TiKV Java client library
Java
44
star
48

tidiff

A toolset to improve efficiency
Go
41
star
49

meetup

36
star
50

fn

Go
32
star
51

thirdparty-ops

This repo is used for the operation and maintenance of third party tools.
Python
32
star
52

dead-mans-switch

A bypass monitoring prober
Go
32
star
53

tiunimanager

TiUniManager
Go
32
star
54

ng-monitoring

Go
30
star
55

tidb-inspect-tools

Python
28
star
56

tidb-vision

TiDB data visualization
JavaScript
28
star
57

django-tidb

TiDB dialect for Django
Python
26
star
58

tidb-course-201-lab

Lab scripts for the PingCAP training course: TiDB SQL for Developers.
Shell
26
star
59

activerecord-tidb-adapter

TiDB adapter for ActiveRecord, allows the use of TiDB as a backend for ActiveRecord and Rails apps.
Ruby
24
star
60

docs-dm

Documentation for the TiDB Data Migration (DM) tool in both English and Chinese.
Python
23
star
61

monitoring

Shell
23
star
62

diag

A tool to collect diagnostic data from TiDB Clusters
Go
23
star
63

website-docs

The next generation of PingCAP Docs. Powered by Gatsby βš›οΈ.
TypeScript
22
star
64

book.tidb.net

JavaScript
21
star
65

kdt

Kernel Debug Toolkit
Shell
20
star
66

log

Go
16
star
67

tidb.ai

This is an out-of-the-box conversational search tool that leverages the vector storage capabilities of TiDB Serverless. It provides a seamless way to embed a powerful question-answering (QA) bot directly on your website, requiring only a simple copy-and-paste of a JavaScript snippet. Demo: https://tidb.ai
TypeScript
16
star
68

octopus

A toolkit including many powerful distributed test tools
Go
15
star
69

Auto-GPT-TiDB-Serverless-Plugin

Python
15
star
70

errcode

Go
14
star
71

dbt-tidb

A dbt adapter for TiDB
Python
13
star
72

tidb_workload_analysis

Go
13
star
73

tidb-loadbalance

Java
11
star
74

k8s-fluent-bit-stackdriver

Shell
11
star
75

website

The website of PingCAP. Powered by Gatsby βš›οΈ and Rocket πŸš€.
JavaScript
11
star
76

tpcc-mysql

forked from https://code.launchpad.net/~percona-dev/perconatools/tpcc-mysql
C
11
star
77

tidb-insight

Python
11
star
78

tiunimanager-ui

A web UI for TiUniManager
TypeScript
9
star
79

tidb-ctl

TiDB Controller
Go
9
star
80

askdb

Chat to query Hacker News database, based on Auto-GPT and TiDB Cloud Serverless Database
TypeScript
9
star
81

tso

Timestamp Oracle
Go
8
star
82

tidb-cloud-backup

Go
8
star
83

docs-appdev

Python
7
star
84

LinguFlow

Python
7
star
85

sqlalchemy-tidb

Python
6
star
86

etcdv3-gateway

Gateway for etcdv3
Go
6
star
87

tidb-academy-labs

6
star
88

tispark-test

C
6
star
89

oasis

Python
5
star
90

homebrew-brew

Homebrew taps for TiDB
Ruby
5
star
91

wordpress-tidb-docker

WordPress x TiDB Serverless Tier Cluster
Shell
5
star
92

sysutil

sysutil is a library which implementats the gRPC service Diagnostics and shares the diagnostics functions between TiDB and PD.
Go
5
star
93

mysqlrelay

Go
4
star
94

tidb-lmdb

lmdb as storage engine for tidb
Go
4
star
95

cloud-assets-utils

Cloud assets utils by PingCAP FE.
OCaml
4
star
96

mpdriver

MySQL Protocol Driver, used to record MySQL query commands..
Go
4
star
97

wordpress-tidb-plugin

PHP
4
star
98

tidb-helper

Shell
3
star
99

vldb-boss-2018

Slides and links for VLDB BOSS 2018
3
star
100

sqlgram

TiDB SQL
HTML
3
star