## 模块 5: 修改 TiKV 配置文件参数

### 步骤 1. 在 `TiKV server 1`，查看 `tikv.toml` 文件的内容

- 在 [终端 1](ssh://monitor1-ssh#1) 中，执行以下命令。

  ```bash
  ssh -i ~/.ssh/pe-class-key-${LAB:REGION_NAME}.pem ec2-user@${HOST_KV1_PRIVATE_IP} vi /tidb-deploy/tikv-20160/conf/tikv.toml
  ```

  ```output
  # WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
  # You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
  # All configuration items you want to change can be added to:
  # server_configs:
  #   tikv:
  #     aa.b1.c3: value
  #     aa.b2.c4: value
  ...
  ```

- 在 `vi` 编辑器中，按下 `ESC` 键并输入 `:q!` 以退出到终端。

### 步骤 2. 在控制机上, 更改 `TiKV server` 的 `log.level`

+ 在[终端 1](ssh://monitor1-ssh#1), 使用 `tiup cluster edit-config` 命令启动一个编辑器。然后，将 `TiKV server` 的 `log.level` 更改为 `warn`。按 `ESC` 键，然后输入 `:wq` 退出回到终端：

  ```bash
  tiup cluster edit-config tidb-test
  ```

  ```output
  ...
  server_configs:
  tidb: {}
  tikv:
     log.level: warn
  pd:
     replication.location-labels:
     - region
     - zone
     - storage-performance
     replication.max-replicas: 3
  tidb_dashboard: {}
  tiflash: {}
  tiproxy: {}
  tiflash-learner: {}
  pump: {}
  drainer: {}
  ```

### 步骤 3. 重新加载 TiDB 集群

+ 在[终端 1](ssh://monitor1-ssh#1)，使用 `tiup cluster reload` 命令更新配置。此步骤将重启所有 `TiKV server`。

  ```bash
  tiup cluster reload tidb-test
  ```

  ```output
  Will reload the cluster tidb-test with restart policy is true, nodes: , roles: .
  Do you want to continue? [y/N]:(default=N) y
  + [ Serial ] - SSHKeySet: privateKey=/home/ec2-user/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/home/ec2-user/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub
  + [Parallel] - UserSSH: user=ec2-user, host=10.90.2.99
  + [Parallel] - UserSSH: user=ec2-user, host=10.90.2.92
  ...
  Reloaded cluster `tidb-test` successfully
  ```

### 步骤 4. 在 `TiKV server 1`, 再次查看 `tikv.toml` 的内容

+ 在 `TiKV server 1` 上, 使用文本编辑器再次查看 `tikv.toml` 文件的内容，并验证 `log.level = "warn"`. 输入 `:q!` 退出编辑器。

  ```bash
  ssh -i ~/.ssh/pe-class-key-${LAB:REGION_NAME}.pem ec2-user@${HOST_KV1_PRIVATE_IP} vi -m /tidb-deploy/tikv-20160/conf/tikv.toml
  ```

  ```output
  # WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
  # You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
  # All configuration items you want to change can be added to:
  # server_configs:
  #   tikv:
  #     aa.b1.c3: value
  #     aa.b2.c4: value
  [log]
  level = "warn"
  ...
  ```

### 步骤 5. 在控制机上，将 `log.level` 的值恢复为默认值

+ 在控制机上, 使用 `tiup cluster edit-config` 命令启动一个编辑器。将 `TiKV server` 的 `log.level` 从 `warn` 改回默认值。按 `ESC` 键，然后输入 `:wq` 退出回到终端：

  ```bash
  tiup cluster edit-config tidb-test
  ```

  ```output
  ...
  server_configs:
  tidb: {}
  tikv: {}
  pd:
     replication.location-labels:
     - region
     - zone
     - storage-performance
     replication.max-replicas: 3
  tidb_dashboard: {}
  tiflash: {}
  tiproxy: {}
  tiflash-learner: {}
  pump: {}
  drainer: {}
  ```

### 步骤 6. 重新加载 TiDB 集群

  ```bash
  tiup cluster reload tidb-test
  ```

  ```output
  Will reload the cluster tidb-test with restart policy is true, nodes: , roles: .
  Do you want to continue? [y/N]:(default=N) y
  + [ Serial ] - SSHKeySet: privateKey=/home/ec2-user/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/home/ec2-user/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub
  + [Parallel] - UserSSH: user=ec2-user, host=10.90.2.99
  + [Parallel] - UserSSH: user=ec2-user, host=10.90.2.191
  ...
  Reloaded cluster `tidb-test` successfully
  ```

### 步骤 7. 在 `TiKV server 1` 上，再次查看 `tikv.toml` 的内容

+ 在 `TiKV server 1` 上， 使用文本编辑器再次查看 `tikv.toml` 文件的内容，并验证 `log.level` 已恢复为默认值。输入 `:q!` 退出编辑器。

  ```bash
  ssh -i ~/.ssh/pe-class-key-${LAB:REGION_NAME}.pem ec2-user@${HOST_KV1_PRIVATE_IP} vi -m /tidb-deploy/tikv-20160/conf/tikv.toml
  ```

  ```output
  # WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
  # You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
  # All configuration items you want to change can be added to:
  # server_configs:
  #   tikv:
  #     aa.b1.c3: value
  #     aa.b2.c4: value
  [server]
  [server.labels]
  region = "seattle"
  storage-performance = "high"
  zone = "az1"
  ...
  ```
