方法一:
- 使用TiUP Playground快速部署本地测试环境
#下载并安装TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
#声明全局变量
source ~/.bash_profile
#在当前session执行以下命令启动集群
tiup playground --默认监听本地服务,若开通外网访问权限,可以通过指定--host 0.0.0.0
##也可以指定TiDB版本以及各组件实例个数
##tiup playground v4.0.0 --db 2 --kv 3 --monitor #monitor表示同时部署监控组件
结果输出访问方式
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --host 127.0.0.1 --port 4000 -u root
To view the dashboard: http://127.0.0.1:2379/dashboard
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000
在不指定host的情况下,也可使用nginx做端口转发
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:9090;
}
location /dashboard {
proxy_pass http://127.0.0.1:2379/dashboard;
}
方法二:
2. 使用TiUP cluster在单机上模拟生产环境部署
2.1 基本架构
实例 个数 ip 配置
TiKV 3 127.0.0.1 避免端口冲突和目录冲突
TiDB 1 127.0.0.1 默认端口全局目录配置
PD 1 127.0.0.1 默认端口全局目录配置
TiFlash 1 127.0.0.1 默认端口全局目录配置
Monitor 1 127.0.0.1 默认端口全局目录配置
2.2 安装组件
#安装TiUP
curl --porto '=https' --tlsv1.2 --sSf https://tiup-mirrors.pingcap.com/install.sh | sh
#安装TiUP的cluster组件
tiup cluster
#修改/etc/ssh/sshd_config ,将MaxSessions 调至20
service sshd restart
2.3 创建并启动集群
配置模板
user: 表示通过tidb这系统用户作为集群的内部管理
replication.enable-placement-rules: 设置这个PD参数来确保TiFlash正常运行
host: 设置为本部署主机的ip
hostip:设为本机ip
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/tidb-deploy"
data_dir: "/tidb-data"
# # Monitored variables are applied to all the machines.
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
server_configs:
tidb:
log.slow-threshold: 300
tikv:
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
replication.enable-placement-rules: true
replication.location-labels: ["host"]
tiflash:
logger.level: "info"
pd_servers:
- host: hostip
tidb_servers:
- host: hostip
tikv_servers:
- host: hostip
port: 20160
status_port: 20180
config:
server.labels: { host: "logic-host-1" }
- host: hostip
port: 20161
status_port: 20181
config:
server.labels: { host: "logic-host-2" }
- host: hostip
port: 20162
status_port: 20182
config:
server.labels: { host: "logic-host-3" }
tiflash_servers:
- host: hostip
monitoring_servers:
- host: hostip
grafana_servers:
- host: hostip
执行集群部署命令
##user root -p --tidb-version可通过tiup list tidb查看支持部署的版本
tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml
启动集群
tiup cluster start <cluster-name>
访问方式同方法一
详情请参考PingCap官方文档
https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb