## モジュール 1: TiUP のインストールと演習環境への慣れ

  ![65%](https://lab-static.pingcap.com/quick-demo/demo_010_en.png)

### 手順 1. リモート Linux マシンに接続する

+ ここをクリック - [ターミナル 1](ssh://monitor1-ssh#1) で、ハンズオン演習用に割り当てられた仮想マシンに接続された新しいターミナルを開きます。

### 手順 2. 演習リソース情報を取得する

+ `ec2-user` のホームディレクトリにとどまり、`hosts-env.sh` ファイルの内容をIPアドレス情報のために確認してください。あなたの出力は `sample_output` と異なるかもしれません。

   ```bash
   cat hosts-env.sh
   ```

   ```output
   export HOST_MONITOR1_PRIVATE_IP=10.90.4.19
   export HOST_MONITOR1_PUBLIC_IP=44.234.33.106
   export HOST_CM_PRIVATE_IP=10.90.4.19
   export HOST_CM_PUBLIC_IP=44.234.33.106
   export HOST_PD1_PRIVATE_IP=10.90.1.197
   export HOST_PD1_PUBLIC_IP=18.236.76.37
   export HOST_PD2_PRIVATE_IP=10.90.3.218
   export HOST_PD2_PUBLIC_IP=18.237.226.109
   export HOST_PD3_PRIVATE_IP=10.90.2.84
   export HOST_PD3_PUBLIC_IP=18.237.105.199
   export HOST_DB1_PRIVATE_IP=10.90.3.216
   export HOST_DB1_PUBLIC_IP=34.222.212.46
   export HOST_DB2_PRIVATE_IP=10.90.2.245
   export HOST_DB2_PUBLIC_IP=54.188.31.139
   export HOST_KV1_PRIVATE_IP=10.90.1.94
   export HOST_KV1_PUBLIC_IP=35.87.137.198
   export HOST_KV2_PRIVATE_IP=10.90.2.38
   export HOST_KV2_PUBLIC_IP=35.91.214.228
   export HOST_KV3_PRIVATE_IP=10.90.3.112
   export HOST_KV3_PUBLIC_IP=54.184.160.176
   export HOST_TIFLASH1_PRIVATE_IP=10.90.4.28
   export HOST_TIFLASH1_PUBLIC_IP=34.223.94.92
   ```

+ 接続したLinux上でノードIPアドレスの変数を設定してください。

   ```bash
   source ./hosts-env.sh
   ```

+ 演習ガイドの上部にある<kbd>Resources</kbd> タブをいつでもクリックすることにより、すべての演習リソース情報にアクセスできます。

### 手順 3. TiUP のダウンロードとインストール - TiDB クラスタ管理ユーティリティ

+ ターミナルプロンプトで次のコマンドを入力して `tiup` ユーティリティをインストールします。環境によっては `tiup` が事前にインストールされている場合もあります。

   ```bash
   curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
   ```

   ```output
   curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
     % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                    Dload  Upload   Total   Spent    Left  Speed
   100 5152k  100 5152k    0     0  14.8M      0 --:--:-- --:--:-- --:--:-- 14.8M
   Successfully set mirror to https://tiup-mirrors.pingcap.com
   Detected shell: bash
   Shell profile:  /home/ec2-user/.bash_profile
   Installed path: /home/ec2-user/.tiup/bin/tiup
   ===============================================
   Have a try:     tiup playground
   ===============================================
   ```

### 手順 4. TiUP 環境変数をセットアップ

+ ターミナルプロンプトで次のコマンドを入力してください。

   ```bash
   source .bash_profile
   ```

### 手順 5. TiUP ミラーをローカルフォルダーに変更

+ 接続されたLinux上で、ローカルTiUPミラーがフォルダー`tidb-community-server-${LAB:TIDB_VERSION}-linux-amd64` に設定されていることを確認してください。この設定は、ハンズオン演習のためにすでに[クローンされています](https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup)。

   ```bash
   tiup mirror set tidb-community-server-${LAB:TIDB_VERSION}-linux-amd64
   tiup mirror show
   ```

   ```output
   Successfully set mirror to /home/ec2-user/tidb-community-server-${LAB:TIDB_VERSION}-linux-amd64
   /home/ec2-user/tidb-community-server-${LAB:TIDB_VERSION}-linux-amd64
   ```

+ ローカルTiUPミラーのセットアップに関する詳細については、[TiUPドキュメント](https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup)を参照してください。これで、TiDBクラスタをデプロイする準備が整いましたので、次の練習に進んでください。

### 手順 6. `tiup cluster` を実行して TiUP クラスタコンポーネントがすでにインストールされているかどうかを確認

+ ターミナルプロンプトで次のコマンドを入力して、結果を確認します。`tiup cluster` コマンドは構成されたTiUPミラーから `cluster` コンポーネントをインストールすることができます。

   ```bash
   tiup cluster
   ```

   ```output
   Checking updates for component cluster... Deploy a TiDB cluster for production

   Usage:
   tiup cluster [command]

   Available Commands:
   check       Perform preflight checks for the cluster.
   deploy      Deploy a cluster for production
   start       Start a TiDB cluster
   stop        Stop a TiDB cluster
   restart     Restart a TiDB cluster
   scale-in    Scale in a TiDB cluster
   scale-out   Scale out a TiDB cluster
   destroy     Destroy a specified cluster
   clean       (EXPERIMENTAL) Cleanup a specified cluster
   upgrade     Upgrade a specified TiDB cluster
   display     Display information of a TiDB cluster
   prune       Destroy and remove instances that is in tombstone state
   list        List all clusters
   audit       Show audit log of cluster operation
   import      Import an exist TiDB cluster from TiDB-Ansible
   edit-config Edit TiDB cluster config
   show-config Show TiDB cluster config
   reload      Reload a TiDB cluster's config and restart if needed
   patch       Replace the remote package with a specified package and restart the service
   rename      Rename the cluster
   enable      Enable a TiDB cluster automatically at boot
   disable     Disable automatic enabling of TiDB clusters at boot
   replay      Replay previous operation and skip successed steps
   template    Print topology template
   tls         Enable/Disable TLS between TiDB components
   meta        backup/restore meta information
   rotatessh   rotate ssh keys on all nodes
   help        Help about any command
   completion  Generate the autocompletion script for the specified shell

   Flags:
   -c, --concurrency int     max number of parallel tasks allowed (default 5)
      --format string       (EXPERIMENTAL) The format of output, available values are [default, json] (default "default")
   -h, --help                help for tiup
      --ssh string          (EXPERIMENTAL) The executor type: 'builtin', 'system', 'none'.
      --ssh-timeout uint    Timeout in seconds to connect host via SSH, ignored for operations that don't need an SSH connection. (default 5)
   -v, --version             version for tiup
      --wait-timeout uint   Timeout in seconds to wait for an operation to complete, ignored for operations that don't fit. (default 120)
   -y, --yes                 Skip all confirmations and assumes 'yes'

   Use "tiup cluster help [command]" for more information about a command.
   ```

### 手順 7. プライベートキー/パブリックキーがすでにセットアップされていることを確認

+ この演習では、プライベートキー/パブリックキーペアは演習環境で準備されています。自分の環境で演習後にプライベートキー/パブリックキーペアを準備するには、`ssh-keygen` を使用する必要があります。

+ プライベートキーは `~/.ssh` ディレクトリの下にあり、プライベートキーファイルの権限は読み取り専用です。このプライベートキーを使用してTiDBクラスタをデプロイします。

   ```bash
   ls -l /home/ec2-user/.ssh/pe-class-key-${LAB:REGION_NAME}.pem
   ```

   ```output
   -r-------- 1 ec2-user ec2-user 1674 May 25 04:09 /home/ec2-user/.ssh/pe-class-key-${LAB:REGION_NAME}.pem
   ```

+ 対応するパブリックキーはこの演習の各ノードの `~/.ssh/authorized_keys` ファイルにあるので、パスワードなしで任意のノードにSSH接続できます。

   ```bash
   cat ~/.ssh/authorized_keys | grep ${LAB:REGION_NAME}
   ```

   ```output
   ssh-rsa AAAAB3Nza..........FvuLk3f5/Wsdx7jdNrP pe-class-key-${LAB:REGION_NAME}
   ```
