## モジュール 3: ワークロードが実行中の状態で TiDB クラスタをアップグレードする

### 手順 1. TiUP ミラーの場所を設定します

+ [ターミナル 1](ssh://monitor1-ssh#1) に戻り、tiup コマンドを実行して TiUP のローカルミラーを v8.1.1 に変更します。

  ```bash
  tiup mirror set tidb-community-server-8.1.1-linux-amd64
  ```

  ```output
  Successfully set mirror to /home/ec2-user/tidb-community-server-8.1.1-linux-amd64
  ```

### 手順 2. TiDB クラスタをアップグレードします

+ `tiup` コマンドを実行して TiDB クラスタを v7.5.4 から v8.1.1 にアップグレードします。アップグレードが進行中の間、[ターミナル 2](ssh://monitor1-ssh#2) と [ターミナル 3](ssh://monitor1-ssh#3) に切り替えます。

  ```bash
  tiup cluster upgrade tidb-demo 8.1.1 --yes
  ```

  ```output
  Before the upgrade, it is recommended to read the upgrade guide at https://docs.tidb.io/tidb/stable/upgrade-tidb-using-tiup and finish the preparation steps.
  This operation will upgrade tidb v7.5.4 cluster tidb-demo to v8.1.1:
  will upgrade and restart component "                 pd" to "v8.1.1",
  will upgrade and restart component "               tikv" to "v8.1.1",
  will upgrade and restart component "               tidb" to "v8.1.1",
  ...
  + [ Serial ] - Download: component=grafana, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=tikv, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=tidb, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=prometheus, version=v8.1.1, os=linux, arch=amd64
  + [ Serial ] - Download: component=pd, version=v8.1.1, os=linux, arch=amd64
  ...
  Upgrading component pd
  	Restarting instance 10.90.1.135:2379
  	Restart instance 10.90.1.135:2379 success
  	Restarting instance 10.90.2.182:2379
  	Restart instance 10.90.2.182:2379 success
  	Restarting instance 10.90.3.231:2379
  	Restart instance 10.90.3.231:2379 success
  Upgrading component tikv
  	Evicting 11 leaders from store 10.90.1.55:20160...
  	  Still waiting for 11 store leaders to transfer...
  	  Still waiting for 11 store leaders to transfer...
  .
  .
  .
  Upgrading component tidb
  	Restarting instance 10.90.1.124:4000
  	Restart instance 10.90.1.124:4000 success
  	Restarting instance 10.90.2.122:4000
  	Restart instance 10.90.2.122:4000 success
  .
  .
  .
  ```

### 手順 3. INSERT および QUERY 作業が中断されていないことを確認します

+ [ターミナル 2](ssh://monitor1-ssh#2) と [ターミナル 3](ssh://monitor1-ssh#3) において、サンプルアプリケーション接続とトランザクションがアップグレード中に中断されていないことを確認します。

+ [ターミナル 1](ssh://monitor1-ssh#1) でのアップグレードコマンドが完了するまで待ってから、次のステップに進みます。

  ```output
  ...
  Upgraded cluster `tidb-demo` successfully
  ```

### 手順 4. アップグレード結果を確認します

+ クラスタのステータスを取得するコマンドを実行し、クラスタのバージョンが v8.1.1 であることを確認します。

  ```bash
  tiup cluster display tidb-demo
  ```

  ```output
  Cluster type:       tidb
  Cluster name:       tidb-demo
  Cluster version:    v8.1.1
  Deploy user:        ec2-user
  SSH type:           builtin
  Dashboard URL:      http://18.138.239.33:2379/dashboard
  Grafana URL:        http://10.90.4.8:3000
  ID                Role          Host         Ports        OS/Arch       Status  Data Dir                      Deploy Dir
  --                ----          ----         -----        -------       ------  --------                      ----------
  10.90.4.8:9093    alertmanager  10.90.4.8    9093/9094    linux/x86_64  Up      /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
  10.90.4.8:3000    grafana       10.90.4.8    3000         linux/x86_64  Up      -                             /tidb-deploy/grafana-3000
  10.90.1.152:2379  pd            10.90.1.152  2379/2380    linux/x86_64  Up|L    /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.2.73:2379   pd            10.90.2.73   2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.3.163:2379  pd            10.90.3.163  2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.4.8:9090    prometheus    10.90.4.8    9090/12020   linux/x86_64  Up      /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
  10.90.2.180:4000  tidb          10.90.2.180  4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.3.89:4000   tidb          10.90.3.89   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.1.88:20160  tikv          10.90.1.88   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.2.20:20160  tikv          10.90.2.20   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.3.69:20160  tikv          10.90.3.69   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.1.60:6000   tiproxy       10.90.1.60   6000/3080    linux/x86_64  Up      -                             /tidb-deploy/tiproxy-6000
  Total nodes: 12
  ```

+ [ターミナル 2](ssh://monitor1-ssh#2) と [ターミナル 3](ssh://monitor1-ssh#3) で <kbd>Ctrl</kbd>+<kbd>C</kbd> を押して、両方のワークロードを停止します。

![tiup-upgrade-magna-cut-01.jpg 66%](https://lab-static.pingcap.com/images/2025/10/24/ca14839c97fd287309f6b35ce75a09a084fa125d.jpg)
