## 模块 4: 扩展存储层

在执行`sysbench`工作负载时对存储层进行扩展。

### 步骤 1. 打开新的终端窗口(Terminal 2)，并登陆至 monitor1_address

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

### 步骤 2. 执行测试工作负载

+ [终端 2](ssh://monitor1-ssh#2) 中，执行`sysbench`工作负载。在此过程中无需等待完成，继续执行接下来的步骤。

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

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

   Running the test with following options:
   Number of threads: 14
   Report intermediate results every 5 second(s)
   Initializing random number generator from current time

   Initializing worker threads...

   Threads started!
   ...
   ```

### 步骤 3. 添加一个TiKV服务器到集群

+ 返回[终端 1](ssh://monitor1-ssh#1)，扩展存储层，添加一个TiKV服务器。

   ```bash
   cat scale-out-tikv.yaml
   ```

   ```output
   tikv_servers:
     - host: 10.90.1.245
       port: 20160
       status_port: 20180
   ```

   ```bash
   ~/.tiup/bin/tiup cluster scale-out tidb-demo scale-out-tikv.yaml --user ec2-user -i ~/.ssh/pe-class-key-${LAB:REGION_NAME}.pem -y
   ```

   ```output
   ...
   Scaled cluster `tidb-demo` out successfully
   ```

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

+ 确保 TiDB 集群中有四个`tikv`服务器。TiKV 层的规模从3扩展至4。

   ```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.48:4000    tidb          10.90.1.48   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
   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.245:20160  tikv          10.90.1.245  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: 11
   ```

### 步骤 5. 验证存储层扩容未影响工作负载

- 切换到 [终端 2](ssh://monitor1-ssh#2)，观察并确认扩容操作未中断正在运行的工作负载。
