## Module 1: Installing TiUP

### Step 1. Log into the remote Linux

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

### Step 2. Check `hosts-env.sh` file for IP addresses

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

### Step 3. Set IP address variables in your terminal environment

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

### Step 4. Install 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
  ===============================================
  ```

### Step 5. Setup TiUP environment variables

  ```bash
  source .bash_profile
  ```

### Step 6. Verify that the TiUP cluster component is 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 permission of the private key file is read only

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

### Step 8. Set TiUP mirror

  ```bash
  tiup mirror set tidb-community-server-7.5.0-linux-amd64
  tiup mirror show
  ```

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