- About TiDB
- Quick Start
- Deploy
- Software and Hardware Requirements
- Environment Configuration Checklist
- Plan Cluster Topology
- Install and Start
- Verify Cluster Status
- Test Cluster Performance
- Migrate
- Maintain
- Upgrade
- Scale
- Backup and Restore
- Use BR Tool (Recommended)
- Read Historical Data
- Configure Time Zone
- Daily Checklist
- Maintain TiFlash
- Maintain TiDB Using TiUP
- Modify Configuration Online
- Monitor and Alert
- Troubleshoot
- TiDB Troubleshooting Map
- Identify Slow Queries
- Analyze Slow Queries
- SQL Diagnostics
- Identify Expensive Queries
- Statement Summary Tables
- Troubleshoot Hotspot Issues
- Troubleshoot Increased Read and Write Latency
- Troubleshoot Cluster Setup
- Troubleshoot High Disk I/O Usage
- Troubleshoot Lock Conflicts
- Troubleshoot TiFlash
- Troubleshoot Write Conflicts in Optimistic Transactions
- Performance Tuning
- System Tuning
- Software Tuning
- SQL Tuning
- Overview
- Understanding the Query Execution Plan
- SQL Optimization Process
- Overview
- Logic Optimization
- Physical Optimization
- Prepare Execution Plan Cache
- Control Execution Plans
- Tutorials
- TiDB Ecosystem Tools
- Reference
- Cluster Architecture
- Key Monitoring Metrics
- Secure
- Privileges
- SQL
- SQL Language Structure and Syntax
- SQL Statements
ADD COLUMN
ADD INDEX
ADMIN
ADMIN CANCEL DDL
ADMIN CHECKSUM TABLE
ADMIN CHECK [TABLE|INDEX]
ADMIN SHOW DDL [JOBS|QUERIES]
ALTER DATABASE
ALTER INDEX
ALTER INSTANCE
ALTER TABLE
ALTER USER
ANALYZE TABLE
BACKUP
BEGIN
CHANGE COLUMN
COMMIT
CHANGE DRAINER
CHANGE PUMP
CREATE [GLOBAL|SESSION] BINDING
CREATE DATABASE
CREATE INDEX
CREATE ROLE
CREATE SEQUENCE
CREATE TABLE LIKE
CREATE TABLE
CREATE USER
CREATE VIEW
DEALLOCATE
DELETE
DESC
DESCRIBE
DO
DROP [GLOBAL|SESSION] BINDING
DROP COLUMN
DROP DATABASE
DROP INDEX
DROP ROLE
DROP SEQUENCE
DROP STATS
DROP TABLE
DROP USER
DROP VIEW
EXECUTE
EXPLAIN ANALYZE
EXPLAIN
FLASHBACK TABLE
FLUSH PRIVILEGES
FLUSH STATUS
FLUSH TABLES
GRANT <privileges>
GRANT <role>
INSERT
KILL [TIDB]
LOAD DATA
LOAD STATS
MODIFY COLUMN
PREPARE
RECOVER TABLE
RENAME INDEX
RENAME TABLE
REPLACE
RESTORE
REVOKE <privileges>
REVOKE <role>
ROLLBACK
SELECT
SET DEFAULT ROLE
SET [NAMES|CHARACTER SET]
SET PASSWORD
SET ROLE
SET TRANSACTION
SET [GLOBAL|SESSION] <variable>
SHOW ANALYZE STATUS
SHOW [BACKUPS|RESTORES]
SHOW [GLOBAL|SESSION] BINDINGS
SHOW BUILTINS
SHOW CHARACTER SET
SHOW COLLATION
SHOW [FULL] COLUMNS FROM
SHOW CONFIG
SHOW CREATE SEQUENCE
SHOW CREATE TABLE
SHOW CREATE USER
SHOW DATABASES
SHOW DRAINER STATUS
SHOW ENGINES
SHOW ERRORS
SHOW [FULL] FIELDS FROM
SHOW GRANTS
SHOW INDEX [FROM|IN]
SHOW INDEXES [FROM|IN]
SHOW KEYS [FROM|IN]
SHOW MASTER STATUS
SHOW PLUGINS
SHOW PRIVILEGES
SHOW [FULL] PROCESSSLIST
SHOW PROFILES
SHOW PUMP STATUS
SHOW SCHEMAS
SHOW STATS_HEALTHY
SHOW STATS_HISTOGRAMS
SHOW STATS_META
SHOW STATUS
SHOW TABLE NEXT_ROW_ID
SHOW TABLE REGIONS
SHOW TABLE STATUS
SHOW [FULL] TABLES
SHOW [GLOBAL|SESSION] VARIABLES
SHOW WARNINGS
SHUTDOWN
SPLIT REGION
START TRANSACTION
TABLE
TRACE
TRUNCATE
UPDATE
USE
- Data Types
- Functions and Operators
- Overview
- Type Conversion in Expression Evaluation
- Operators
- Control Flow Functions
- String Functions
- Numeric Functions and Operators
- Date and Time Functions
- Bit Functions and Operators
- Cast Functions and Operators
- Encryption and Compression Functions
- Information Functions
- JSON Functions
- Aggregate (GROUP BY) Functions
- Window Functions
- Miscellaneous Functions
- Precision Math
- Set Operations
- List of Expressions for Pushdown
- Clustered Indexes
- Constraints
- Generated Columns
- SQL Mode
- Transactions
- Garbage Collection (GC)
- Views
- Partitioning
- Character Set and Collation
- System Tables
mysql
- INFORMATION_SCHEMA
- Overview
ANALYZE_STATUS
CLIENT_ERRORS_SUMMARY_BY_HOST
CLIENT_ERRORS_SUMMARY_BY_USER
CLIENT_ERRORS_SUMMARY_GLOBAL
CHARACTER_SETS
CLUSTER_CONFIG
CLUSTER_HARDWARE
CLUSTER_INFO
CLUSTER_LOAD
CLUSTER_LOG
CLUSTER_SYSTEMINFO
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
COLUMNS
DDL_JOBS
ENGINES
INSPECTION_RESULT
INSPECTION_RULES
INSPECTION_SUMMARY
KEY_COLUMN_USAGE
METRICS_SUMMARY
METRICS_TABLES
PARTITIONS
PROCESSLIST
SCHEMATA
SEQUENCES
SESSION_VARIABLES
SLOW_QUERY
STATISTICS
TABLES
TABLE_CONSTRAINTS
TABLE_STORAGE_STATS
TIDB_HOT_REGIONS
TIDB_INDEXES
TIDB_SERVERS_INFO
TIFLASH_REPLICA
TIKV_REGION_PEERS
TIKV_REGION_STATUS
TIKV_STORE_STATUS
USER_PRIVILEGES
VIEWS
METRICS_SCHEMA
- UI
- TiDB Dashboard
- Overview
- Maintain
- Access
- Overview Page
- Cluster Info Page
- Key Visualizer Page
- Metrics Relation Graph
- SQL Statements Analysis
- Slow Queries Page
- Cluster Diagnostics
- Search Logs Page
- Profile Instances Page
- FAQ
- TiDB Dashboard
- CLI
- Command Line Flags
- Configuration File Parameters
- System Variables
- Storage Engines
- TiUP
- Telemetry
- Errors Codes
- Table Filter
- Schedule Replicas by Topology Labels
- FAQs
- Glossary
- Release Notes
- All Releases
- v5.0
- v4.0
- v3.1
- v3.0
- v2.1
- v2.0
- v1.0
Production Deployment from Binary Tarball
This guide provides installation instructions from a binary tarball on Linux. A complete TiDB cluster contains PD, TiKV, and TiDB. To start the database service, follow the order of PD -> TiKV -> TiDB. To stop the database service, follow the order of stopping TiDB -> TiKV -> PD.
See also local deployment and testing environment deployment.
Prepare
Before you start, see TiDB architecture and Software and Hardware Recommendations. Make sure the following requirements are satisfied:
Operating system
For the operating system, it is recommended to use RHEL/CentOS 7.3 or higher. The following additional requirements are recommended:
Configuration | Description |
---|---|
Supported Platform | RHEL/CentOS 7.3+ (more details) |
File System | ext4 is recommended |
Swap Space | Should be disabled |
Disk Block Size | Set the system disk Block size to 4096 |
Network and firewall
Configuration | Description |
---|---|
Firewall/Port | Check whether the ports required by TiDB are accessible between the nodes |
Operating system parameters
Configuration | Description |
---|---|
Nice Limits | For system users, set the default value of nice in TiDB to 0 |
min_free_kbytes | The setting for vm.min_free_kbytes in sysctl.conf needs to be high enough |
User Open Files Limit | For database administrators, set the number of TiDB open files to 1000000 |
System Open File Limits | Set the number of system open files to 1000000 |
User Process Limits | For TiDB users, set the nproc value to 4096 in limits.conf |
Address Space Limits | For TiDB users, set the space to unlimited in limits.conf |
File Size Limits | For TiDB users, set the fsize value to unlimited in limits.conf |
Disk Readahead | Set the value of the readahead data disk to 4096 at a minimum |
NTP service | Configure the NTP time synchronization service for each node |
SELinux | Turn off the SELinux service for each node |
CPU Frequency Scaling | It is recommended to turn on CPU overclocking |
Transparent Hugepages | For Red Hat 7+ and CentOS 7+ systems, it is required to set the Transparent Hugepages to always |
I/O Scheduler | Set the I/O Scheduler of data disks to the deadline mode |
vm.swappiness | Set vm.swappiness = 0 in sysctl.conf |
net.core.somaxconn | Set net.core.somaxconn = 32768 in sysctl.conf |
net.ipv4.tcp_syncookies | Set net.ipv4.tcp_syncookies = 0 in sysctl.conf |
Database running user settings
Configuration | Description |
---|---|
LANG environment | Set LANG = en_US.UTF8 |
TZ time zone | Set the TZ time zone of all nodes to the same value |
TiDB components and default ports
Before you deploy a TiDB cluster, see the required components and optional components.
TiDB database components (required)
See the following table for the default ports for the TiDB components:
Component | Default Port | Protocol | Description |
---|---|---|---|
ssh | 22 | TCP | the sshd service |
TiDB | 4000 | TCP | the communication port for the application and DBA tools |
TiDB | 10080 | TCP | the communication port to report TiDB status |
TiKV | 20160 | TCP | the TiKV communication port |
PD | 2379 | TCP | the communication port between TiDB and PD |
PD | 2380 | TCP | the inter-node communication port within the PD cluster |
TiDB database components (optional)
See the following table for the default ports for the optional TiDB components:
Component | Default Port | Protocol | Description |
---|---|---|---|
Prometheus | 9090 | TCP | the communication port for the Prometheus service |
Pushgateway | 9091 | TCP | the aggregation and report port for TiDB, TiKV, and PD monitor |
Node_exporter | 9100 | TCP | the communication port to report the system information of every TiDB cluster node |
Grafana | 3000 | TCP | the port for the external Web monitoring service and client (Browser) access |
alertmanager | 9093 | TCP | the port for the alert service |
Create a database running user account
Log in to the machine using the
root
user account and create a database running user account (tidb
) using the following command:# useradd tidb -m
Switch the user from
root
totidb
by using the following command. You can use thistidb
user account to deploy your TiDB cluster.# su - tidb
Download the official binary package
# Download the package.
$ wget https://download.pingcap.org/tidb-v5.0.0-rc-linux-amd64.tar.gz
$ wget https://download.pingcap.org/tidb-v5.0.0-rc-linux-amd64.sha256
# Check the file integrity. If the result is OK, the file is correct.
$ sha256sum -c tidb-v5.0.0-rc-linux-amd64.sha256
# Extract the package.
$ tar -xzf tidb-v5.0.0-rc-linux-amd64.tar.gz
$ cd tidb-v5.0.0-rc-linux-amd64
Multiple nodes cluster deployment
For the production environment, multiple nodes cluster deployment is recommended. Before you begin, see Software and Hardware Recommendations.
Assuming that you have six nodes, you can deploy 3 PD instances, 3 TiKV instances, and 1 TiDB instance. See the following table for details:
Name | Host IP | Services |
---|---|---|
Node1 | 192.168.199.113 | PD1, TiDB |
Node2 | 192.168.199.114 | PD2 |
Node3 | 192.168.199.115 | PD3 |
Node4 | 192.168.199.116 | TiKV1 |
Node5 | 192.168.199.117 | TiKV2 |
Node6 | 192.168.199.118 | TiKV3 |
Follow the steps below to start PD, TiKV, and TiDB:
Start PD on Node1, Node2, and Node3 in sequence.
$ ./bin/pd-server --name=pd1 \ --data-dir=pd \ --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" \ -L "info" \ --log-file=pd.log & $ ./bin/pd-server --name=pd2 \ --data-dir=pd \ --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" \ -L "info" \ --log-file=pd.log & $ ./bin/pd-server --name=pd3 \ --data-dir=pd \ --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" \ -L "info" \ --log-file=pd.log &
Start TiKV on Node4, Node5 and Node6.
$ ./bin/tikv-server --pd="192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379" \ --addr="192.168.199.116:20160" \ --status-addr="192.168.199.116:20180" \ --data-dir=tikv \ --log-file=tikv.log & $ ./bin/tikv-server --pd="192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379" \ --addr="192.168.199.117:20160" \ --status-addr="192.168.199.117:20180" \ --data-dir=tikv \ --log-file=tikv.log & $ ./bin/tikv-server --pd="192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379" \ --addr="192.168.199.118:20160" \ --status-addr="192.168.199.118:20180" \ --data-dir=tikv \ --log-file=tikv.log &
Start TiDB on Node1.
$ ./bin/tidb-server --store=tikv \ --path="192.168.199.113:2379,192.168.199.114:2379,192.168.199.115:2379" \ --log-file=tidb.log &
Use the MySQL client to connect to TiDB.
$ mysql -h 192.168.199.113 -P 4000 -u root -D test
Note:
- If you start TiKV or deploy PD in the production environment, it is highly recommended to specify the path for the configuration file using the
--config
parameter. If the parameter is not set, TiKV or PD does not read the configuration file.- To tune TiKV, see Performance Tuning for TiKV.
- If you use
nohup
to start the cluster in the production environment, write the startup commands in a script and then run the script. If not, thenohup
process might abort because it receives exceptions when the Shell command exits. For more information, see The TiDB/TiKV/PD process aborts unexpectedly.
For the deployment and use of TiDB monitoring services, see Deploy Monitoring Services for the TiDB Cluster and TiDB Monitoring API.