(二)TIDB搭建正式集群

需要在linux系统各种搭建,集群或者单结点。

一:准备环境

linux环境,关闭防火墙。安装盘大于30G,否则会失败。

二、下载包

官网:https://pingkai.cn/download#tidb-community

部署手册:https://pingkai.cn/docs/pingkaidb/stable/production-deployment-using-tiup/

三、在线安装TIUP

tiup默认的安装路径~/.tiup,即/root/.tiup ,所有的组件都在这个下面,如果我们安装到指定的目录下:

1、指定目录

复制代码
export TIUP_HOME=/data/tidb/tiup

2、下载TIUP

复制代码
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh 

3、声明全局环境变量

复制代码
source /root/.bash_profile

4、查看环境变量

复制代码
[root@localhost ~]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

export PATH=/data/tidb/tiup/bin:$PATH

如果第一次默认安装,第二次在修改了路径,此时.bash_profile文件中的路径没有删除,请手动修改,否则 which tiup 的时候无法查看。

5、验证tiup

复制代码
 which  tiup 

tiup --version

此时我们的tiup就安装好了,下面就可以使用 tiup cluster 命令安装各个组件了。

四、使用tiup cluster 搭建正式集群

1、创建拓扑文件,

复制代码
tiup cluster template > /data/tidb/topology.yaml

2、topology.yaml文件中文件路径和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:
  # # The user who runs the tidb cluster.
  user: "tidb"
  # # group is used to specify the group name the user belong to if it's not the same as user.
  # group: "tidb"
  # # SSH port of servers in the managed cluster.
  ssh_port: 22
  # # Storage directory for cluster deployment files, startup scripts, and configuration files.
  deploy_dir: "/data/tidb/tidb-deploy"
  # # TiDB Cluster data storage directory
  data_dir: "/data/tidb/tidb-data"
  # # default listen_host for all components
  listen_host: 192.168.50.20
  # # Supported values: "amd64", "arm64" (default: "amd64")
  arch: "amd64" 

# # Monitored variables are applied to all the machines.
monitored:
  # # The communication port for reporting system information of each node in the TiDB cluster.
  node_exporter_port: 9100
  # # Blackbox_exporter communication port, used for TiDB cluster port monitoring.
  blackbox_exporter_port: 9115


# # Server configs are used to specify the configuration of PD Servers.
pd_servers:
  # # The ip address of the PD Server.
  - host: 192.168.50.20
    

# # Server configs are used to specify the configuration of TiDB Servers.
tidb_servers:
  # # The ip address of the TiDB Server.
  - host: 192.168.50.20
   

# # Server configs are used to specify the configuration of TiKV Servers.
tikv_servers:
  # # The ip address of the TiKV Server.
  - host: 192.168.50.20
   

# # Server configs are used to specify the configuration of TiFlash Servers.
tiflash_servers:
  # # The ip address of the TiFlash Server.
  - host: 192.168.50.20
   

# # Server configs are used to specify the configuration of Prometheus Server.  
monitoring_servers:
  # # The ip address of the Monitoring Server.
  - host: 192.168.50.20
  

# # Server configs are used to specify the configuration of Grafana Servers.  
grafana_servers:
  # # The ip address of the Grafana Server.
  - host: 192.168.50.20
   

# # Server configs are used to specify the configuration of Alertmanager Servers.  
alertmanager_servers:
  # # The ip address of the Alertmanager Server.
  - host: 192.168.50.20

3、从拓扑文件中部署一个名字为demo_tidb 版本为v8.5.5的集群

复制代码
tiup cluster deploy demo_tidb v8.5.5 /data/tidb/topology.yaml --user root -p

比较慢,静静地等待就可以了。

4、成功标志

5、启动集群

复制代码
--初始化启动,初始化了密码,优先使用
 tiup cluster start ontology_tidb --init

--普通启动,tidb密码为空
tiup cluster start ontology_tidb 

成功了提示:started  cluster 'demo_tidb'  successfully

6、集群的其他操作

复制代码
1、停止集群
tiup cluster stop demo_tidb

2、查看集群状态
tiup cluster display demo_tidb

3、销毁集群
tiup cluster destroy  demo_tidb

4.卸载tiup
   --卸载 tiup 组件
    tiup uninstall --all
   --卸载自己
   tiup uninstall --self

5、最后删除掉创建的目录文件

7、访问控制台

http://192.168.50.20:2379/

8、使用客户端连接

mysql 8.0以上驱动均可。

相关推荐
笃行35021 分钟前
MySQL 的 JSON 字段迁到金仓还能用吗?——KingbaseES V9R3C18 JSON 操作符与函数兼容实测
数据库
IpdataCloud1 小时前
跨境AI金融风险怎么防?IP风险画像的实战应用指南
数据库·tcp/ip·金融·ip
悦儿遥遥雨12 小时前
PXE + Kickstart 无人值守批量部署系统
linux·javascript·nginx
Imagine Miracle3 小时前
【WSL】让WSL2后台持久运行不自动关闭的解决方案
linux·windows·wsl
兔C3 小时前
Linux 命令行入门学习资料 day_2
linux·运维·服务器
Alan_753 小时前
API 接口慢调用根因定位:从 TCP 建连到数据库 IO 的全栈排查实战
数据库
eggcode4 小时前
Linux命令基础与操作技巧
linux
多巴胺梦想家4 小时前
事务与并发控制:当多人同时操作数据库
服务器·数据库·oracle
二宝哥4 小时前
VMware Workstation 实战:CentOS 7.9 安装、桥接网络配置与克隆管理详解
linux·centos·vmware
howard20055 小时前
PostgreSQL起步
数据库·postgresql