TiDB quick start


使用 TiUP 部署 TiDB 集群

  • TiUP 是 TiDB 4.0 版本引入的集群运维工具,TiUP cluster 是 TiUP 提供的使用 Golang 编写的集群管理组件
  • 基本架构:TiDB, TiKV, PD, 监控
  • TiDB 是一个分布式系统。最基础的 TiDB 测试集群通常由 2 个 TiDB 实例、3 个 TiKV 实例、3 个 PD 实例和可选的 TiFlash 实例构成。
  • 通过 TiUP Playground,可以快速搭建出上述的一套基础测试集群。

TiUP playground 部署本地测试环境

yum install -y net-tools.x86_64
yum install -y wget
wget https://tiup-mirrors.pingcap.com/install.sh
sh install.sh
# curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source .bash_profile
source /root/.bash_profile
# tiup playground
tiup playground v4.0.16 --db 2 --pd 3 --kv 3 --monitor --host 192.168.249.100
# tiup playground v5.0.1 --db 2 --pd 3 --kv 3 --monitor --host 192.168.249.100

# tiup client
yum search mysql
yum install -y mysql # yum install -y mariadb
mysql --host 127.0.0.1 --port 4000 -u root
# http://ip:9090 # prometheus 界面()
# http://ip:2379/dashboard # tidb dashboard 界面(root/密码为 root的密码)
# http://ip:3000 # Grafana 界面(admin/admin)

# To connect TiDB: mysql --comments --host 192.168.249.100 --port 4000 -u root -p (no password)
#To connect TiDB: mysql --comments --host 192.168.249.100 --port 4001 -u root -p (no password)
# To view the dashboard: http://192.168.249.100:2379/dashboard
# PD client endpoints: [192.168.249.100:2379 192.168.249.100:2382 192.168.249.100:2384]
# To view the Prometheus: http://192.168.249.100:9090
# To view the Grafana: http://192.168.249.100:3000

tiup clean --all

>> select tidb_version() \G
>> alter user 'root'@% identified by '123456';

错误

  • TiFlash 192.168.249.100:3930 failed to start: no endpoint available, the last err was: error requesting http://192.168.249.100:2384/pd/api/v1/config/replicate, response: { "code": "input", "msg": "unexpected end of JSON input", "data": { "Offset": 0 } } , code 400
  • 没关防火墙;连接不上端口;
  • systemctl stop firewalld,systemctl disable firewalld;

TiUP cluster 单机模拟生成环境部署

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source .bash_profile
tiup cluster # 安装 TiUP 的 cluster 组件
tiup update --self && tiup update cluster # 如果机器已经安装 TiUP cluster,需要更新软件版本
# 由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制
  # 修改 /etc/ssh/sshd_config 将 MaxSessions 调至 20
  service sshd restart # 重启 sshd 服务:

# 创建并启动集群
  #按下面的[配置模板],编辑配置文件,命名为 topo.yaml,其中:
  #user: "tidb":表示通过 tidb 系统用户(部署会自动创建)来做集群的内部管理,默认使用 22 端口通过 ssh 登录目标机器
  #replication.enable-placement-rules:设置这个 PD 参数来确保 TiFlash 正常运行
  #host:设置为本部署主机的 IP  

# 执行集群部署命令
tiup cluster deploy tidb_cluster_single_host v5.0.1 ./topo.yaml --user root -p
#tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml --user root -p
  # 参数 <cluster-name> 表示设置集群名称
  # 参数 <tidb-version> 表示设置集群版本,可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本
#按照引导,输入 y 及 root 密码,来完成部署:
Do you want to continue? [y/N]:  y
Input SSH password:

# 启动集群: tiup cluster start <cluster-name>
tiup cluster start tidb_cluster_single_host

访问集群

# 访问集群:使用起来和单机无区别
yum -y install mysql # 安装 MySQL 客户端。如果已安装 MySQL 客户端则可跳过这一步骤。
mysql -h 192.168.249.100 -P 4000 -u root  # 访问 TiDB 数据库,密码为空:
  # 访问 TiDB 的 Grafana 监控:
  # 通过 http://{grafana-ip}:3000 访问集群 Grafana 监控页面,默认用户名和密码均为 admin。
  # 访问 TiDB 的 Dashboard:
  # 通过 http://{pd-ip}:2379/dashboard 访问集群 TiDB Dashboard 监控页面,默认用户名为 root,密码为空。

# 执行以下命令确认当前已经部署的集群列表:
tiup cluster list
# 执行以下命令查看集群的拓扑结构和状态:
#tiup cluster display <cluster-name>
tiup cluster display  tidb_cluster_single_host

报错

[ERROR] [server.rs:854] ["failed to init io snooper"] 
[err_code=KV:Unknown] [err="\"IO snooper is not started due to not compiling with BCC\""]
  • 这个错误具体原因未知;我在磁盘扩容后解决了。(增大内存不能解决)

附录

  • topo.yaml 模板

topo.yaml

# # 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: "/opt/app_dir/tidb/tidb-deploy"
 data_dir: "/opt/app_dir/tidb/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: 192.168.249.100

tidb_servers:
 - host: 192.168.249.100

tikv_servers:
 - host: 192.168.249.100
   port: 20160
   status_port: 20180
   config:
     server.labels: { host: "logic-host-1" }

 - host: 192.168.249.100
   port: 20161
   status_port: 20181
   config:
     server.labels: { host: "logic-host-2" }

 - host: 192.168.249.100
   port: 20162
   status_port: 20182
   config:
     server.labels: { host: "logic-host-3" }

tiflash_servers:
 - host: 192.168.249.100

monitoring_servers:
 - host: 192.168.249.100

grafana_servers:
 - host: 192.168.249.100

网卡配置模板

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=8946a17f-a597-4b85-8a4c-4094fd8d5503
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.249.134
NETMASK=255.255.255.0
DNS1=192.168.249.1
DNS2=8.8.8.8
GATEWAY=192.168.249.2
ZONE=public

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值