## 模块 1: 检查并设置环境

### 步骤 1. 连接至 TiUP 控制机

+ 点击这里 - [终端 1](ssh://monitor1-ssh#1) 打开一个新的终端，连接到为你的实践实验分配的虚拟机。

### 步骤 2. 确认 TiDB 集群状态

+ 通过TiProxy观察集群运行状态，其中包括一个`tidb`服务器和三个`tikv`服务器。

   ```bash
   ~/.tiup/bin/tiup cluster display tidb-demo
   ```

   ```output
   Cluster type:       tidb
   Cluster name:       tidb-demo
   Cluster version:    v${LAB:TIDB_VERSION}
   Deploy user:        ec2-user
   SSH type:           builtin
   Dashboard URL:      http://35.91.126.63:2379/dashboard
   Grafana URL:        http://10.90.4.204:3000
   ID                 Role          Host         Ports        OS/Arch       Status  Data Dir                      Deploy Dir
   --                 ----          ----         -----        -------       ------  --------                      ----------
   10.90.4.204:9093   alertmanager  10.90.4.204  9093/9094    linux/x86_64  Up      /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
   10.90.4.204:3000   grafana       10.90.4.204  3000         linux/x86_64  Up      -                             /tidb-deploy/grafana-3000
   10.90.3.89:2379    pd            10.90.3.89   2379/2380    linux/x86_64  Up|L    /tidb-data/pd-2379            /tidb-deploy/pd-2379
   10.90.4.204:9090   prometheus    10.90.4.204  9090/12020   linux/x86_64  Up      /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
   10.90.1.74:4000    tidb          10.90.1.74   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
   10.90.1.103:20160  tikv          10.90.1.103  20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.1.30:20160   tikv          10.90.1.30   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.1.34:20160   tikv          10.90.1.34   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
   10.90.4.204:6000   tiproxy       10.90.4.204  6000/3080    linux/x86_64  Up      -                             /tidb-deploy/tiproxy-6000
   Total nodes: 9
   ```

### 步骤 3. 创建 sysbench 配置

   ```bash
   cat << EOF > sysbench_config
   mysql-host=${HOST_MONITOR1_PRIVATE_IP}
   mysql-port=6000
   mysql-user=root
   mysql-password=
   mysql-db=sbtest
   time=120
   threads=14
   report-interval=5
   EOF
   cat sysbench_config
   ```

   ```output
   mysql-host=10.90.4.204
   mysql-port=6000
   mysql-user=root
   mysql-password=
   mysql-db=sbtest
   time=120
   threads=14
   report-interval=5
   ```

### 步骤 4. 连接TiDB集群并创建空数据库 `sbtest`

   ```bash
   mysql -h ${HOST_MONITOR1_PRIVATE_IP} -P 6000 -uroot
   ```

   ```output
   Welcome to the MySQL monitor.  Commands end with ; or \g.
   Your MySQL connection id is 0
   Server version: 8.0.11-TiDB-v${LAB:TIDB_VERSION} TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

   Copyright (c) 2000, 2023, Oracle and/or its affiliates.

   Oracle is a registered trademark of Oracle Corporation and/or its
   affiliates. Other names may be trademarks of their respective
   owners.

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

   mysql>
   ```

   ```sql
   CREATE DATABASE sbtest;
   EXIT;
   ```

   ```output
   Query OK, 0 rows affected (0.11 sec)
   Bye
   ```

### 步骤 5. 准备数据

+ 准备`sysbench`数据，需约3分钟完成。

   ```bash
   sysbench --config-file=sysbench_config oltp_read_only --tables=6 --table-size=1000000 prepare
   ```

   ```output
   sysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)

   Initializing worker threads...

   Creating table 'sbtest4'...
   Creating table 'sbtest1'...
   Creating table 'sbtest3'...
   Creating table 'sbtest2'...
   Creating table 'sbtest6'...
   Creating table 'sbtest5'...
   Inserting 1000000 records into 'sbtest6'
   Inserting 1000000 records into 'sbtest5'
   Inserting 1000000 records into 'sbtest4'
   Inserting 1000000 records into 'sbtest3'
   Inserting 1000000 records into 'sbtest1'
   Inserting 1000000 records into 'sbtest2'
   Creating a secondary index on 'sbtest6'...
   Creating a secondary index on 'sbtest1'...
   Creating a secondary index on 'sbtest4'...
   Creating a secondary index on 'sbtest2'...
   Creating a secondary index on 'sbtest5'...
   Creating a secondary index on 'sbtest3'...
   ```
