使用 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_configMaxSessions 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: 22deploy_dir: "/tidb-deploy"data_dir: "/tidb-data"# # Monitored variables are applied to all the machines.monitored:node_exporter_port: 9100blackbox_exporter_port: 9115server_configs:tidb:log.slow-threshold: 300tikv:readpool.storage.use-unified-pool: falsereadpool.coprocessor.use-unified-pool: truepd:replication.enable-placement-rules: truereplication.location-labels: ["host"]tiflash:logger.level: "info"pd_servers:- host: 172.21.16.84tidb_servers:- host: 172.21.16.84tikv_servers:- host: 172.21.16.84port: 20160status_port: 20180config:server.labels: { host: "logic-host-1" }- host: 172.21.16.84port: 20161status_port: 20181config:server.labels: { host: "logic-host-2" }- host: 172.21.16.84port: 20162status_port: 20182config:server.labels: { host: "logic-host-3" }tiflash_servers:- host: 172.21.16.84monitoring_servers:- host: 172.21.16.84grafana_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]: yInput 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 rootWelcome to the MariaDB monitor. Commands end with ; or \g.Your MySQL connection id is 19Server version: 5.7.25-TiDB-v5.2.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatibleCopyright (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 listStarting component `cluster`: root/.tiup/components/cluster/v1.5.5/tiup-cluster listName 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 tidbtestStarting component `cluster`: /root/.tiup/components/cluster/v1.5.5/tiup-cluster display tidbtestCluster type: tidbCluster name: tidbtestCluster version: v5.2.0Deploy user: tidbSSH type: builtinDashboard URL: http://172.21.16.84:2379/dashboardID 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-3000172.21.16.84:2379 pd 172.21.16.84 2379/2380 linux/x86_64 Up|L|UI /tidb-data/pd-2379 /tidb-deploy/pd-2379172.21.16.84:9090 prometheus 172.21.16.84 9090 linux/x86_64 Up /tidb-data/prometheus-9090 /tidb-deploy/prometheus-9090172.21.16.84:4000 tidb 172.21.16.84 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000172.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-9000172.21.16.84:20160 tikv 172.21.16.84 20160/20180 linux/x86_64 Up /tidb-data/tikv-20160 /tidb-deploy/tikv-20160172.21.16.84:20161 tikv 172.21.16.84 20161/20181 linux/x86_64 Up /tidb-data/tikv-20161 /tidb-deploy/tikv-20161172.21.16.84:20162 tikv 172.21.16.84 20162/20182 linux/x86
文章转载自DBA学习成长笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




