Add environment configuration and documentation for various services
- Created .env.example files for Kafka, Kibana, KodBox, Kong, Langfuse, Logstash, n8n, Nginx, OceanBase, OpenCoze, RocketMQ, TiDB, and TiKV. - Added README.md and README.zh.md files for OceanBase, RocketMQ, TiDB, and TiKV, detailing usage, configuration, and access instructions. - Implemented docker-compose.yaml files for OceanBase, RocketMQ, TiDB, and TiKV, defining service configurations, health checks, and resource limits. - Included broker.conf for RocketMQ to specify broker settings. - Established a consistent timezone (UTC) across all services. - Provided optional port overrides in .env.example files for flexibility in deployment.
This commit is contained in:
11
src/tidb/.env.example
Normal file
11
src/tidb/.env.example
Normal file
@@ -0,0 +1,11 @@
|
||||
# TiDB version (applies to PD, TiKV, and TiDB)
|
||||
TIDB_VERSION=v8.5.0
|
||||
|
||||
# Timezone
|
||||
TZ=UTC
|
||||
|
||||
# Port overrides (optional)
|
||||
# TIDB_PD_PORT_OVERRIDE=2379
|
||||
# TIDB_TIKV_PORT_OVERRIDE=20160
|
||||
# TIDB_PORT_OVERRIDE=4000
|
||||
# TIDB_STATUS_PORT_OVERRIDE=10080
|
||||
95
src/tidb/README.md
Normal file
95
src/tidb/README.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# TiDB
|
||||
|
||||
TiDB is an open-source, cloud-native, distributed SQL database designed for modern applications. It is MySQL compatible and provides horizontal scalability, strong consistency, and high availability.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## Components
|
||||
|
||||
This setup includes:
|
||||
|
||||
- **PD (Placement Driver)**: Manages and schedules TiKV
|
||||
- **TiKV**: Distributed transactional key-value storage
|
||||
- **TiDB**: Stateless SQL layer
|
||||
|
||||
## Ports
|
||||
|
||||
- `4000`: TiDB MySQL protocol port
|
||||
- `10080`: TiDB status and metrics port
|
||||
- `2379`: PD client port
|
||||
- `20160`: TiKV port
|
||||
|
||||
## Access
|
||||
|
||||
### MySQL Client
|
||||
|
||||
TiDB is compatible with MySQL protocol:
|
||||
|
||||
```bash
|
||||
mysql -h127.0.0.1 -P4000 -uroot
|
||||
```
|
||||
|
||||
### Example Usage
|
||||
|
||||
```sql
|
||||
-- Create database
|
||||
CREATE DATABASE test;
|
||||
USE test;
|
||||
|
||||
-- Create table
|
||||
CREATE TABLE users (
|
||||
id INT PRIMARY KEY,
|
||||
name VARCHAR(50),
|
||||
email VARCHAR(100)
|
||||
);
|
||||
|
||||
-- Insert data
|
||||
INSERT INTO users VALUES (1, 'Alice', 'alice@example.com');
|
||||
|
||||
-- Query data
|
||||
SELECT * FROM users;
|
||||
```
|
||||
|
||||
### Status and Metrics
|
||||
|
||||
Check TiDB status:
|
||||
|
||||
```bash
|
||||
curl http://localhost:10080/status
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- **MySQL Compatible**: Drop-in replacement for MySQL
|
||||
- **Horizontal Scalability**: Scale out by adding more nodes
|
||||
- **Strong Consistency**: ACID transactions across distributed data
|
||||
- **High Availability**: Automatic failover with no data loss
|
||||
- **Hybrid Transactional/Analytical Processing (HTAP)**: Both OLTP and OLAP workloads
|
||||
|
||||
## Notes
|
||||
|
||||
- This is a minimal single-node setup for development
|
||||
- For production, deploy multiple PD, TiKV, and TiDB nodes
|
||||
- Consider adding TiFlash for analytical workloads
|
||||
- Monitor using Prometheus and Grafana for production deployments
|
||||
- Data is persisted in named volumes
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
For production deployments, consider:
|
||||
|
||||
- Using separate machines for PD, TiKV, and TiDB
|
||||
- Deploying at least 3 PD nodes for high availability
|
||||
- Deploying at least 3 TiKV nodes for data replication
|
||||
- Adding TiFlash for columnar storage and faster analytical queries
|
||||
- Setting up monitoring with TiDB Dashboard, Prometheus, and Grafana
|
||||
|
||||
## References
|
||||
|
||||
- [TiDB Official Documentation](https://docs.pingcap.com/tidb/stable)
|
||||
- [TiDB Quick Start](https://docs.pingcap.com/tidb/stable/quick-start-with-tidb)
|
||||
- [TiDB Docker Images](https://hub.docker.com/u/pingcap)
|
||||
95
src/tidb/README.zh.md
Normal file
95
src/tidb/README.zh.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# TiDB
|
||||
|
||||
TiDB 是一个开源、云原生、分布式 SQL 数据库,专为现代应用程序设计。它兼容 MySQL 协议,提供水平扩展能力、强一致性和高可用性。
|
||||
|
||||
## 使用方法
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
## 组件说明
|
||||
|
||||
此配置包含:
|
||||
|
||||
- **PD (Placement Driver)**:管理和调度 TiKV
|
||||
- **TiKV**:分布式事务键值存储
|
||||
- **TiDB**:无状态 SQL 层
|
||||
|
||||
## 端口说明
|
||||
|
||||
- `4000`:TiDB MySQL 协议端口
|
||||
- `10080`:TiDB 状态和指标端口
|
||||
- `2379`:PD 客户端端口
|
||||
- `20160`:TiKV 端口
|
||||
|
||||
## 访问方式
|
||||
|
||||
### MySQL 客户端
|
||||
|
||||
TiDB 兼容 MySQL 协议:
|
||||
|
||||
```bash
|
||||
mysql -h127.0.0.1 -P4000 -uroot
|
||||
```
|
||||
|
||||
### 使用示例
|
||||
|
||||
```sql
|
||||
-- 创建数据库
|
||||
CREATE DATABASE test;
|
||||
USE test;
|
||||
|
||||
-- 创建表
|
||||
CREATE TABLE users (
|
||||
id INT PRIMARY KEY,
|
||||
name VARCHAR(50),
|
||||
email VARCHAR(100)
|
||||
);
|
||||
|
||||
-- 插入数据
|
||||
INSERT INTO users VALUES (1, 'Alice', 'alice@example.com');
|
||||
|
||||
-- 查询数据
|
||||
SELECT * FROM users;
|
||||
```
|
||||
|
||||
### 状态和指标
|
||||
|
||||
检查 TiDB 状态:
|
||||
|
||||
```bash
|
||||
curl http://localhost:10080/status
|
||||
```
|
||||
|
||||
## 特性
|
||||
|
||||
- **MySQL 兼容**:可作为 MySQL 的直接替代品
|
||||
- **水平扩展**:通过添加更多节点进行扩展
|
||||
- **强一致性**:分布式数据的 ACID 事务
|
||||
- **高可用性**:自动故障转移,无数据丢失
|
||||
- **混合事务/分析处理(HTAP)**:同时支持 OLTP 和 OLAP 工作负载
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 这是一个最小的单节点配置,适合开发环境
|
||||
- 生产环境需要部署多个 PD、TiKV 和 TiDB 节点
|
||||
- 考虑添加 TiFlash 以支持分析工作负载
|
||||
- 生产部署使用 Prometheus 和 Grafana 进行监控
|
||||
- 数据持久化在命名卷中
|
||||
|
||||
## 高级配置
|
||||
|
||||
生产部署建议:
|
||||
|
||||
- 为 PD、TiKV 和 TiDB 使用独立的机器
|
||||
- 部署至少 3 个 PD 节点以实现高可用
|
||||
- 部署至少 3 个 TiKV 节点以实现数据复制
|
||||
- 添加 TiFlash 以提供列式存储和更快的分析查询
|
||||
- 使用 TiDB Dashboard、Prometheus 和 Grafana 设置监控
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [TiDB 官方文档](https://docs.pingcap.com/zh/tidb/stable)
|
||||
- [TiDB 快速开始](https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb)
|
||||
- [TiDB Docker 镜像](https://hub.docker.com/u/pingcap)
|
||||
105
src/tidb/docker-compose.yaml
Normal file
105
src/tidb/docker-compose.yaml
Normal file
@@ -0,0 +1,105 @@
|
||||
x-default: &default
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 100m
|
||||
max-file: "3"
|
||||
|
||||
services:
|
||||
pd:
|
||||
<<: *default
|
||||
image: pingcap/pd:${TIDB_VERSION:-v8.5.0}
|
||||
command:
|
||||
- --name=pd
|
||||
- --client-urls=http://0.0.0.0:2379
|
||||
- --peer-urls=http://0.0.0.0:2380
|
||||
- --advertise-client-urls=http://pd:2379
|
||||
- --advertise-peer-urls=http://pd:2380
|
||||
- --data-dir=/data
|
||||
environment:
|
||||
TZ: ${TZ:-UTC}
|
||||
volumes:
|
||||
- pd_data:/data
|
||||
ports:
|
||||
- "${TIDB_PD_PORT_OVERRIDE:-2379}:2379"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '1.0'
|
||||
memory: 1G
|
||||
reservations:
|
||||
cpus: '0.25'
|
||||
memory: 512M
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O - http://localhost:2379/health || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
|
||||
tikv:
|
||||
<<: *default
|
||||
image: pingcap/tikv:${TIDB_VERSION:-v8.5.0}
|
||||
command:
|
||||
- --addr=0.0.0.0:20160
|
||||
- --advertise-addr=tikv:20160
|
||||
- --pd=http://pd:2379
|
||||
- --data-dir=/data
|
||||
environment:
|
||||
TZ: ${TZ:-UTC}
|
||||
volumes:
|
||||
- tikv_data:/data
|
||||
ports:
|
||||
- "${TIDB_TIKV_PORT_OVERRIDE:-20160}:20160"
|
||||
depends_on:
|
||||
pd:
|
||||
condition: service_healthy
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2.0'
|
||||
memory: 2G
|
||||
reservations:
|
||||
cpus: '0.5'
|
||||
memory: 1G
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O - http://localhost:20180/status || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 5
|
||||
start_period: 60s
|
||||
|
||||
tidb:
|
||||
<<: *default
|
||||
image: pingcap/tidb:${TIDB_VERSION:-v8.5.0}
|
||||
command:
|
||||
- --store=tikv
|
||||
- --path=pd:2379
|
||||
- --advertise-address=tidb
|
||||
environment:
|
||||
TZ: ${TZ:-UTC}
|
||||
ports:
|
||||
- "${TIDB_PORT_OVERRIDE:-4000}:4000"
|
||||
- "${TIDB_STATUS_PORT_OVERRIDE:-10080}:10080"
|
||||
depends_on:
|
||||
tikv:
|
||||
condition: service_healthy
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2.0'
|
||||
memory: 2G
|
||||
reservations:
|
||||
cpus: '0.5'
|
||||
memory: 512M
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "wget -q -O - http://localhost:10080/status || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
|
||||
volumes:
|
||||
pd_data:
|
||||
tikv_data:
|
||||
Reference in New Issue
Block a user