## Module 1: Deploy a TiDB Cluster with TiProxy

### Step 1. Log in to the remote Linux

+ 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. Check the prepared cluster topology YAML file

  ```bash
  cat eleven-nodes.yaml
  ```

  ```output
  global:
    user: "ec2-user"
    ssh_port: 22
    deploy_dir: "/tidb-deploy"
    data_dir: "/tidb-data"
    arch: "amd64"
  server_configs:
    pd:
      replication.max-replicas: 3
    tidb:
      security.auto-tls: true
      graceful-wait-before-shutdown: 10
  pd_servers:
    - host: 10.90.3.160
      client_port: 2379
      peer_port: 2380
      advertise_client_addr: "http://35.92.30.186:2379"
    - host: 10.90.1.162
      client_port: 2379
      peer_port: 2380
      advertise_client_addr: "http://52.34.128.150:2379"
    - host: 10.90.2.223
      client_port: 2379
      peer_port: 2380
      advertise_client_addr: "http://54.245.183.8:2379"
  tidb_servers:
    - host: 10.90.1.157
      port: 4000
      status_port: 10080
      deploy_dir: /tidb-deploy/tidb-4000
      log_dir: /tidb-deploy/tidb-4000/log
    - host: 10.90.2.6
      port: 4000
      status_port: 10080
      deploy_dir: /tidb-deploy/tidb-4000
      log_dir: /tidb-deploy/tidb-4000/log
  tikv_servers:
    - host: 10.90.3.132
      port: 20160
      status_port: 20180
    - host: 10.90.2.171
      port: 20160
      status_port: 20180
    - host: 10.90.1.222
      port: 20160
      status_port: 20180
  monitoring_servers:
    - host: 10.90.4.33
  grafana_servers:
    - host: 10.90.4.33
  alertmanager_servers:
    - host: 10.90.4.33
  tiproxy_servers:
    - host: 10.90.1.153
  ```

### Step 3. Fix system settings to deploy TiDB cluster

  ```bash
  tiup mirror set tidb-community-server-7.5.4-linux-amd64
  tiup cluster check eleven-nodes.yaml \
    --user ec2-user \
    -i /home/ec2-user/.ssh/pe-class-key-${LAB:REGION_NAME}.pem \
    --apply
  ```

  ```output
  ...
  + Try to apply changes to fix failed checks
   - Applying changes on 10.90.1.162 ... ⠧ Sysctl: host=10.90.1.162 vm.swappiness = 0
   - Applying changes on 10.90.2.223 ... ⠧ Sysctl: host=10.90.2.223 vm.swappiness = 0
   - Applying changes on 10.90.3.132 ... ⠧ Sysctl: host=10.90.3.132 vm.swappiness = 0
  + Try to apply changes to fix failed checks
  + Try to apply changes to fix failed checks
   - Applying changes on 10.90.1.162 ... Done
   - Applying changes on 10.90.2.223 ... Done
  + Try to apply changes to fix failed checks
   - Applying changes on 10.90.1.162 ... Done
  + Try to apply changes to fix failed checks
  + Try to apply changes to fix failed checks
   - Applying changes on 10.90.1.162 ... Done
   - Applying changes on 10.90.2.223 ... Done
   - Applying changes on 10.90.3.132 ... Done
   - Applying changes on 10.90.2.171 ... Done
   - Applying changes on 10.90.1.222 ... Done
   - Applying changes on 10.90.4.33 ... Done
   - Applying changes on 10.90.3.160 ... Done
   - Applying changes on 10.90.1.153 ... Done
   - Applying changes on 10.90.2.210 ... Done
   - Applying changes on 10.90.1.157 ... Done
   - Applying changes on 10.90.2.6 ... Done
  ```

### Step 4. Deploy a TiDB cluster

  ```bash
  tiup cluster deploy tidb-demo 7.5.4 ./eleven-nodes.yaml \
    --user ec2-user \
    -i /home/ec2-user/.ssh/pe-class-key-${LAB:REGION_NAME}.pem \
    --yes
  ```

  ```output
  ...
  Cluster `tidb-demo` deployed successfully, you can start it with command: `tiup cluster start tidb-demo --init`
  ```

### Step 5. Start the deployed TiDB cluster

+ Start the cluster.

  ```bash
  tiup cluster start tidb-demo
  ```

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

+ Run the command to get the cluster status. There are 3 PD servers, 3 TiKV servers, 2 TiDB servers, and 1 TiProxy server. Your environment and the sample output will differ in the details of the IP addresses, but the subnets are the same.

> [!TIP]
> If you find any components in a `Down` state, wait a few seconds and run the display command again.

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

  ```output
  Cluster type:       tidb
  Cluster name:       tidb-demo
  Cluster version:    v7.5.4
  Deploy user:        ec2-user
  SSH type:           builtin
  Dashboard URL:      http://13.158.51.172:2379/dashboard
  Grafana URL:        http://10.90.4.109:3000
  ID                 Role          Host         Ports        OS/Arch       Status  Data Dir                      Deploy Dir
  --                 ----          ----         -----        -------       ------  --------                      ----------
  10.90.4.109:9093   alertmanager  10.90.4.109  9093/9094    linux/x86_64  Up      /tidb-data/alertmanager-9093  /tidb-deploy/alertmanager-9093
  10.90.4.109:3000   grafana       10.90.4.109  3000         linux/x86_64  Up      -                             /tidb-deploy/grafana-3000
  10.90.1.128:2379   pd            10.90.1.128  2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.1.51:2379    pd            10.90.1.51   2379/2380    linux/x86_64  Up|L    /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.1.89:2379    pd            10.90.1.89   2379/2380    linux/x86_64  Up      /tidb-data/pd-2379            /tidb-deploy/pd-2379
  10.90.4.109:9090   prometheus    10.90.4.109  9090/12020   linux/x86_64  Up      /tidb-data/prometheus-9090    /tidb-deploy/prometheus-9090
  10.90.2.250:4000   tidb          10.90.2.250  4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.2.97:4000    tidb          10.90.2.97   4000/10080   linux/x86_64  Up      -                             /tidb-deploy/tidb-4000
  10.90.1.105:20160  tikv          10.90.1.105  20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.1.245:20160  tikv          10.90.1.245  20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.1.50:20160   tikv          10.90.1.50   20160/20180  linux/x86_64  Up      /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
  10.90.1.58:6000    tiproxy       10.90.1.58   6000/3080    linux/x86_64  Up      -                             /tidb-deploy/tiproxy-6000
  Total nodes: 12
  ```
