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


准备环境

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

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

最小规模的 TiDB 集群拓扑:

注意:

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

实例 个数 IP 配置
TiKV 3 10.0.1.1
10.0.1.1
10.0.1.1
避免端口和目录冲突
TiDB 1 10.0.1.1 默认端口
全局目录配置
PD 1 10.0.1.1 默认端口
全局目录配置
TiFlash 1 10.0.1.1 默认端口
全局目录配置
Monitor 1 10.0.1.1 默认端口
全局目录配置

部署主机软件和环境要求:

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

实施部署

注意:

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

  1. 下载并安装 TiUP:

    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  2. 安装 TiUP 的 cluster 组件:

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

    tiup update --self && tiup update cluster
  4. 由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制:

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

    2. 重启 sshd 服务:

      service sshd restart
  5. 创建并启动集群

    按下面的配置模板,编辑配置文件,命名为 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: 10.0.1.1 tidb_servers: - host: 10.0.1.1 tikv_servers: - host: 10.0.1.1 port: 20160 status_port: 20180 config: server.labels: { host: "logic-host-1" } - host: 10.0.1.1 port: 20161 status_port: 20181 config: server.labels: { host: "logic-host-2" } - host: 10.0.1.1 port: 20162 status_port: 20182 config: server.labels: { host: "logic-host-3" } tiflash_servers: - host: 10.0.1.1 monitoring_servers: - host: 10.0.1.1 grafana_servers: - host: 10.0.1.1
  6. 执行集群部署命令:

    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:
  7. 启动集群:

    tiup cluster start <cluster-name>
  8. 访问集群:

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

      yum -y install mysql
    • 访问 TiDB 数据库,密码为空:

      mysql -h 10.0.1.1 -P 4000 -u root
    • 访问 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>


      升级:
      1.查看所有版本 tiup list tidb
      2.tiup cluster upgrade tidb_andyxi v5.2.1


      创建、授权和删除用户

      使用 CREATE USER 语句创建一个用户 tiuser,密码为 123456

      CREATE USER 'tiuser'@'localhost' IDENTIFIED BY '123456';

      授权用户 tiuser 可检索数据库 samp_db 内的表:

      GRANT SELECT ON samp_db.* TO 'tiuser'@'localhost';

      查询用户 tiuser 的权限:

      SHOW GRANTS for tiuser@localhost;

      删除用户 tiuser

      DROP USER 'tiuser'@'localhost';
       

      root@db 11:50: [test]SELECT CONCAT(table_schema,'.',table_name) AS 'Table Name', table_rows AS 'Number of Rows', CONCAT(ROUND(data_length/(1024*1024*1024),4),'G') AS 'Data Size', CONCAT(ROUND(index_length/(1024*1024*1024),4),'G') AS 'Index Size', CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),4),'G') AS'Total'FROM information_schema.TABLES WHERE table_schema LIKE 'test';
      +---------------+----------------+-----------+------------+---------+
      | Table Name | Number of Rows | Data Size | Index Size | Total |
      +---------------+----------------+-----------+------------+---------+
      | test.nation | 25 | 0.0000G | 0.0000G | 0.0000G |
      | test.region | 5 | 0.0000G | 0.0000G | 0.0000G |
      | test.part | 200000 | 0.0245G | 0.0000G | 0.0245G |
      | test.supplier | 10000 | 0.0014G | 0.0000G | 0.0014G |
      | test.partsupp | 800000 | 0.1166G | 0.0119G | 0.1285G |
      | test.customer | 150000 | 0.0242G | 0.0000G | 0.0242G |
      | test.orders | 80896 | 0.0088G | 0.0000G | 0.0088G |
      | test.lineitem | 324608 | 0.0404G | 0.0048G | 0.0453G |
      +---------------+----------------+-----------+------------+---------+


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM