## Module 1: Install TiUP And Familiarize Yourself With The Lab Environment

### Step 1. Connect to the remote Linux machine

+ Click [Terminal 1](ssh://monitor1-ssh#1) to open a new terminal connected to the virtual machine assigned for your hands-on lab.

### Step 2. Get the lab resources information

+ Stay in `ec2-user` home directory, check the contents of the `hosts-env.sh` file for IP addresses information. Your output might be different as the `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
   ```

+ Set the node IP address variables on the Linux you connected to.

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

+ You can also click the <kbd>Resources</kbd> tab at the top of this lab guide at any time to access all the lab resource information.

### Step 3. Download and install TiUP - the TiDB cluster management utility

+ Enter the following command at the terminal prompt to install the `tiup` utility. Note that `tiup` may or may not be pre-installed in your environment.

   ```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
   ===============================================
   ```

### Step 4. Setup TiUP environment variables

+ Enter the following command at the terminal prompt.

   ```bash
   source .bash_profile
   ```

### Step 5. Change the TiUP mirror to a local folder

+ Make sure the local TiUP mirror is set to the folder `tidb-community-server-${LAB:TIDB_VERSION}-linux-amd64` on the connected Linux. It had been already [cloned](https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup) for this hands-on lab.

   ```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
   ```

+ For more information on setting up a local TiUP mirror, please refer to the [TiUP documentation](https://docs.pingcap.com/tidb/stable/production-deployment-using-tiup). Now, the environment is ready for deploying a TiDB cluster, please proceed to the next practice.

### Step 6. Verify that the TiUP cluster component has been already installed by executing `tiup cluster`

+ Enter the following command at the terminal prompt and receive the results shown. Note that the `tiup cluster` command can install the `cluster` component from the configured TiUP mirror if it is not already installed.

   ```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.
   ```

### Step 7. Verify that the private/public keys had been already set up for you

+ Note that in this lab, the private/public keys pair was prepared by the lab environment. Note that you must prepare the private/public keys pair by using `ssh-keygen` by yourself in your own environment after the lab.

+ The private key is under `~/.ssh` directory and the permission of the private key file is read only. You will use this private key to deploy the TiDB cluster.

   ```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
   ```

+ The peering public key is in `~/.ssh/authorized_keys` file on every node in this lab, so the you can SSH connect to any node without password.

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

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