Simulating Production TiDB Cluster Deployment on a Single Computer

Deploying a Production Cluster on a Single Computer

Scenario: experience a minimal TiDB cluster with a complete topology and simulate the procedure for deploying a production cluster on a single Linux server. This section explains how to deploy a TiDB cluster with a minimal topology YAML file in TiUP.

Preparing for Cluster Deployment

Prepare a target machine that meets the following requirements.

  • CentOS 7.3 or later is installed.
  • The Linux OS can access the internet. This is required to download TiDB and related software installation packages.

The minimal TiDB cluster topology is as follows.

Instance Count Address Configuration
TiKV 3 10.0.1.1
10.0.1.1
10.0.1.1
Avoid port and directory conflicts
TiDB 1 10.0.1.1 Default port
Global directory configuration
PD 1 10.0.1.1 Default port
Global directory configuration
TiFlash 1 10.0.1.1 Default port
Global directory configuration
Monitor 1 10.0.1.1 Default port
Global directory configuration

Other requirements for the target machine:

  • A root user and password are required.

  • Stop the firewall service on the target system or open the ports required by TiDB cluster nodes.

  • TiUP Cluster currently supports TiDB deployment on x86_64 (AMD64) and ARM architectures.

    • On AMD64, CentOS 7.3 or later is recommended.
    • On ARM, CentOS 7.6 1810 is recommended.

Running Cluster Deployment

  1. Download and install TiUP.

    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    
  2. Declare global environment variables.

    source ${your_shell_profile}
    
  3. Install the TiUP cluster component.

    tiup cluster
    
  4. If TiUP Cluster is already installed on the machine, update the software version.

    tiup update --self && tiup update cluster
    
  5. Use root privileges to increase the connection limit of the sshd service. This is because TiUP needs to simulate deployment across multiple machines.

    1. Change /etc/ssh/sshd_config and set MaxSessions to 20.
    2. Restart the sshd service.
      service sshd restart
      
  6. Create and start the cluster.

    Edit the configuration file according to the following template and name it topo.yaml.

    # # Global variables are applied to all deployments and used as the default value of
    # # the deployments if a specific deployment value is missing.
    global:
    user: "tidb"
    ssh_port: 22
    deploy_dir: "/tidb-deploy"
    data_dir: "/tidb-data"
    
    # # Monitored variables are applied to all the machines.
    monitored:
    node_exporter_port: 9100
    blackbox_exporter_port: 9115
    
    server_configs:
    tidb:
    log.slow-threshold: 300
    tikv:
    readpool.storage.use-unified-pool: false
    readpool.coprocessor.use-unified-pool: true
    pd:
    replication.enable-placement-rules: true
    replication.location-labels: ["host"]
    tiflash:
    logger.level: "info"
    
    pd_servers:
    - host: 10.0.1.1
    
    tidb_servers:
    - host: 10.0.1.1
    
    tikv_servers:
    - host: 10.0.1.1
    port: 20160
    status_port: 20180
    config:
        server.labels: { host: "logic-host-1" }
    
    - host: 10.0.1.1
    port: 20161
    status_port: 20181
    config:
        server.labels: { host: "logic-host-2" }
    
    - host: 10.0.1.1
    port: 20162
    status_port: 20182
    config:
        server.labels: { host: "logic-host-3" }
    
    tiflash_servers:
    - host: 10.0.1.1
    
    monitoring_servers:
    - host: 10.0.1.1
    
    grafana_servers:
    - host: 10.0.1.1
    
    • user: "tidb": uses the tidb system user, which is automatically created during deployment, to perform internal cluster management. By default, it logs in to the target machine through SSH on port 22.
    • replication.enable-placement-rules: this PD parameter is configured so TiFlash works properly.
    • host: the IP address of the target machine.
  7. Run the cluster deployment command.

    tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml --user root -p
    
    • <cluster-name>: sets the cluster name.

    • <tidb-version>: sets the TiDB cluster version. You can run tiup list tidb to see all supported TiDB versions.

    • -p: specifies the password used to connect to the target machine.

    Enter “y” and the root user’s password to complete deployment.

    Do you want to continue? [y/N]:  y
    Input SSH password:
    
  8. Start the cluster.

    tiup cluster start <cluster-name>
    
  9. Access the cluster.

    • Install the MySQL client. If it is already installed, skip this step.

      yum -y install mysql
      
    • Access TiDB. The password is empty.

      mysql -h 10.0.1.1 -P 4000 -u root
      
    • Access the Grafana monitoring dashboard at http://{grafana-ip}:3000. The default username and password are both admin.

    • Access the TiDB dashboard at http://{pd-ip}:2379/dashboard. The default username is root, and the password is empty.

    • To view the currently deployed cluster list:

      tiup cluster list
      
    • To view the cluster topology and status:

      tiup cluster display <cluster-name>
      

References