tidb集群单机部署

使用 TiUP cluster 在单机上模拟生产环境部署步骤
适用场景:希望用单台 Linux 服务器,体验 TiDB 最小的完整拓扑的集群,并模拟生产的部署步骤。
耗时:10 分钟
本节介绍如何参照 TiUP 最小拓扑的一个 YAML 文件部署 TiDB 集群。

准备环境
准备一台部署主机,确保其软件满足需求:

推荐安装 CentOS 7.3 及以上版本
这里使用centos7.6版本
CentOS Linux release 7.6.1810 (Core)
Linux 操作系统开放外网访问,用于下载 TiDB 及相关软件安装包
最小规模的 TiDB 集群拓扑:

注意:

下表中拓扑实例的 IP 为示例 IP。在实际部署时,请替换为实际的 IP。

| 在这里插入图片描述

部署需要使用部署主机的 root 用户及密码
部署主机关闭防火墙或者开放 TiDB 集群的节点间所需端口
目前 TiUP 支持在 x86_64(AMD64 和 ARM)架构上部署 TiDB 集群
在 AMD64 架构下,建议使用 CentOS 7.3 及以上版本 Linux 操作系统
在 ARM 架构下,建议使用 CentOS 7.6 1810 版本 Linux 操作系统
实施部署
注意:

你可以使用 Linux 系统的任一普通用户或 root 用户登录主机,以下步骤以 root 用户为例。

下载并安装 TiUP:

[root@VM-16-84-centos ~]#  curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

安装 TiUP 的 cluster 组件:

[root@VM-16-84-centos ~]#  tiup cluster

如果机器已经安装 TiUP cluster,需要更新软件版本:

[root@VM-16-84-centos ~]#  tiup update --self && tiup update cluster

由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制:

修改 /etc/ssh/sshd_config 将 MaxSessions 调至 20。

[root@VM-16-84-centos ~]# vi /etc/ssh/sshd_config 
MaxSessions 20

重启 sshd 服务:

[root@VM-16-84-centos ~]#  service sshd restart

创建并启动集群

按下面的配置模板,编辑配置文件,命名为 topo.yaml,其中:

user: “tidb”:表示通过 tidb 系统用户(部署会自动创建)来做集群的内部管理,默认使用 22 端口通过 ssh 登录目标机器
replication.enable-placement-rules:设置这个 PD 参数来确保 TiFlash 正常运行
host:设置为本部署主机的 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: 172.21.16.84

tidb_servers:
 - host: 172.21.16.84

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

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

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

tiflash_servers:
 - host: 172.21.16.84

monitoring_servers:
 - host: 172.21.16.84

grafana_servers:
 - host: 172.21.16.84

执行集群部署命令:

[root@VM-16-84-centos ~]#  tiup cluster deploy  tidbtest  v5.2.0  ./topo.yaml --user root -p

参数 tidbtest 表示设置集群名称
参数 v5.2.0 表示设置集群版本,可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本
按照引导,输入”y”及 root 密码,来完成部署:

Do you want to continue? [y/N]:  y
Input SSH password:

启动集群:

[root@VM-16-84-centos ~]#  tiup cluster start tidbtest

访问集群:

安装 MySQL 客户端。如果已安装 MySQL 客户端则可跳过这一步骤。

[root@VM-16-84-centos ~]#  yum -y install mysql

访问 TiDB 数据库,密码为空:

[root@VM-16-84-centos ~]#  mysql -h 172.21.16.84 -P 4000 -u root   
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.7.25-TiDB-v5.2.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 
MySQL [(none)]> 
MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA     |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.00 sec)

访问 TiDB 的 Grafana 监控:

通过 http://{grafana-ip}:3000 访问集群 Grafana 监控页面,默认用户名和密码均为 admin。

访问 TiDB 的 Dashboard:

通过 http://{pd-ip}:2379/dashboard 访问集群 TiDB Dashboard 监控页面,默认用户名为 root,密码为空。

执行以下命令确认当前已经部署的集群列表:

[root@VM-16-84-centos ~]# tiup cluster list
Starting component `cluster`: /root/.tiup/components/cluster/v1.5.5/tiup-cluster list
Name      User  Version  Path                                           PrivateKey
----      ----  -------  ----                                           ----------
tidbtest  tidb  v5.2.0   /root/.tiup/storage/cluster/clusters/tidbtest  /root/.tiup/storage/cluster/clusters/tidbtest/ssh/id_rsa

执行以下命令查看集群的拓扑结构和状态:

[root@VM-16-84-centos ~]# tiup cluster display tidbtest
Starting component `cluster`: /root/.tiup/components/cluster/v1.5.5/tiup-cluster display tidbtest
Cluster type:       tidb
Cluster name:       tidbtest
Cluster version:    v5.2.0
Deploy user:        tidb
SSH type:           builtin
Dashboard URL:      http://172.21.16.84:2379/dashboard
ID                  Role        Host          Ports                            OS/Arch       Status   Data Dir                    Deploy Dir
--                  ----        ----          -----                            -------       ------   --------                    ----------
172.21.16.84:3000   grafana     172.21.16.84  3000                             linux/x86_64  Up       -                           /tidb-deploy/grafana-3000
172.21.16.84:2379   pd          172.21.16.84  2379/2380                        linux/x86_64  Up|L|UI  /tidb-data/pd-2379          /tidb-deploy/pd-2379
172.21.16.84:9090   prometheus  172.21.16.84  9090                             linux/x86_64  Up       /tidb-data/prometheus-9090  /tidb-deploy/prometheus-9090
172.21.16.84:4000   tidb        172.21.16.84  4000/10080                       linux/x86_64  Up       -                           /tidb-deploy/tidb-4000
172.21.16.84:9000   tiflash     172.21.16.84  9000/8123/3930/20170/20292/8234  linux/x86_64  Up       /tidb-data/tiflash-9000     /tidb-deploy/tiflash-9000
172.21.16.84:20160  tikv        172.21.16.84  20160/20180                      linux/x86_64  Up       /tidb-data/tikv-20160       /tidb-deploy/tikv-20160
172.21.16.84:20161  tikv        172.21.16.84  20161/20181                      linux/x86_64  Up       /tidb-data/tikv-20161       /tidb-deploy/tikv-20161
172.21.16.84:20162  tikv        172.21.16.84  20162/20182                      linux/x86_64  Up       /tidb-data/tikv-20162       /tidb-deploy/tikv-20162
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值