使用 TiUP cluster 在单机上模拟生产环境部署步骤

一 实验环境

适用场景:

希望用单台 Linux 服务器,体验 TiDB 最小的完整拓扑的集群,并模拟生产的部署步骤。

本节介绍如何参照 TiUP 最小拓扑的一个 YAML 文件部署 TiDB 集群。

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

  • 推荐安装 CentOS 7.3 及以上版本
  • Linux 操作系统开放外网访问,用于下载 TiDB 及相关软件安装包

实验环境:

二 安装步骤

2.1 下载并安装 TiUP

[root@Centos7-Mode-V8 opt]# curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh  

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 6064k  100 6064k    0     0  6648k      0 --:--:-- --:--:-- --:--:-- 6642k

WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json

You can revoke this by remove /root/.tiup/bin/7b8e153f2e2d0928.root.json

Successfully set mirror to https://tiup-mirrors.pingcap.com

Detected shell: bash

Shell profile:  /root/.bash_profile

/root/.bash_profile has been modified to add tiup to PATH

open a new terminal or source /root/.bash_profile to use it

Installed path: /root/.tiup/bin/tiup

===============================================

Have a try:     tiup playground

===============================================

2.2 安装 TiUP 的 cluster 组件

新打开一个会话,执行:

tiup cluster

/*

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

tiup update --self && tiup update cluster

*/

2.3 调大sshd服务的连接数限制

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

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

重启 sshd 服务:

service sshd restart

2.4 编辑集群配置文件

vi /opt/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: "/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: 192.168.144.249



tidb_servers:

 - host: 192.168.144.249



tikv_servers:

 - host: 192.168.144.249

   port: 20160

   status_port: 20180

   config:

     server.labels: { host: "logic-host-1" }



 - host: 192.168.144.249

   port: 20161

   status_port: 20181

   config:

     server.labels: { host: "logic-host-2" }



 - host: 192.168.144.249

   port: 20162

   status_port: 20182

   config:

     server.labels: { host: "logic-host-3" }



tiflash_servers:

 - host: 192.168.144.249



monitoring_servers:

 - host: 192.168.144.249



grafana_servers:

 - host: 192.168.144.249

注意:

需要修改host: 192.168.144.249处的ip为自己服务器的ip

/*

user: "tidb":表示通过 tidb 系统用户(部署会自动创建)来做集群的内部管理,默认使用 22 端口通过 ssh 登录目标机器。

如果操作系统有限制,不让远程连接,需要修改/etc/ssh/sshd_config 文件,在AllowUsers 后添加tidb,示例:

AllowUsers  root tidb

#重启ssh

service sshd restart

*/

2.5 部署集群

tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml --user root -p

参数 <cluster-name> 表示设置集群名称

参数 <tidb-version> 表示设置集群版本,可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本

按照引导,输入”y”及 root 密码,来完成部署。

示例:

[root@Centos7-Mode-V8 yum.repos.d]# tiup cluster deploy myTiDB v5.1.0  /opt/topo.yaml --user root -p

Starting component `cluster`: /root/.tiup/components/cluster/v1.6.1/tiup-cluster deploy myTiDB v5.1.0 /opt/topo.yaml --user root -p

Input SSH password: 

……
Do you want to continue? [y/N]: (default=N) y

+ Generate SSH keys ... Done

……

Cluster `myTiDB` deployed successfully, you can start it with command: `tiup cluster start myTiDB`

2.6 启动集群

2.6.1 启动集群

tiup cluster start 集群名称

示例:

[root@Centos7-Mode-V8 yum.repos.d]# tiup cluster start myTiDB

……

Started cluster `myTiDB` successfully

2.6.2 查看集群拓扑结构和状态

#确认当前已经部署的集群列表

[root@Centos7-Mode-V8 ~]# tiup cluster list

Starting component `cluster`: /root/.tiup/components/cluster/v1.6.1/tiup-cluster list

Name    User  Version  Path                                         PrivateKey

----    ----  -------  ----                                         ----------

myTiDB  tidb  v5.1.0   /root/.tiup/storage/cluster/clusters/myTiDB  /root/.tiup/storage/cluster/clusters/myTiDB/ssh/id_rsa

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

tiup cluster display myTiDB

 2.7 安装mysql客户端

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

yum -y install mysql

2.8 访问集群

2.8.1 访问TiDB数据库

mysql -h 192.168.144.249 -P 4000 -u root

密码为空。

2.8.2 访问 TiDB 的 Grafana 监控

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

 

2.8.3 访问 TiDB 的 Dashboard

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

示例:

 

--本篇文章参考自:TiDB 数据库快速上手指南 | PingCAP Docs中的‘使用 TiUP cluster 在单机上模拟生产环境部署步骤’。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值