Skip to content

Deploy TiDB

lishaoxiong edited this page May 4, 2018 · 1 revision

Notice

In the production environment with high work load,you should deploy tidb/tikv/pd seperately.As for production enviroment with low work load and test environment,we can deploy them all to three nodes.And we will discuss about "three-nodes" mode in this document.

For detail information,please refer to TiDB Official Doc

Basic Preparation(All nodes)

Install OS

You should install CentOS(version>=7.2) in each node,using minimal mode is fine.

Configure local resolves

Add ip/hostname pairs to /etc/hosts file,save the file and validate the result.

Configure NTP

  1. install ntp package

    #yum install ntp -y
  2. point to ntp servers

    edit "/etc/ntp.conf" file,Add proper servers to config file.

  3. start ntp daemon

    #systemctl start ntpd
  4. validate result

    ntpstat

    the result should similar to 'time correct to within 11 ms'

install basic package

#yum install -y git epel-release python-pip curl mysql

configure user

  1. create user "yig" #useradd yig
  2. Add passwd for user #passwd yig
  3. Add sudo privilege to yig Enter "visudo" in shell;Add "yig ALL=(ALL) NOPASSWD:ALL" to file and quit.

Configure deploy node (only in deploy node)

Select one of the node which has access to public network as deploy node.

  1. switch to yig user;
  2. generate ssh key using 'ssh-keygen'
  3. distribute ssh public key to all nodes(include itself) user 'ssh-copy-id'
  4. validate result using 'ssh whoami'

Install TiDB(only in deploy node)

  1. Enter home directory using "yig" user

    # su - yig
  2. Clone "tidb-ansible" repo

    $ git clone -b release-2.0 https://github.com/pingcap/tidb-ansible.git
  3. Install TidB requirements

    $ cd tidb-ansible
    $ sudo pip install -r ./requirements.txt
  4. Modify "inventory.ini" file

    a, Edit "inventory.ini" file to match our architecture

    b, change "deploy_dir" to the real datadir(we suggest using ssd)

    c, set "ansible_user" value to "yig",since we use yig user to execute command.

  5. Back to home directory,Run the local_prepare.yml playbook, connect to the Internet and download TiDB binary to the Control Machine

    $ansible-playbook local_prepare.yml
  6. Initialize the system environment and modify the kernel parameters

    notice: TiDB require ssd disk for performance,but if you don't have than,you can reduce the limitation appropriately by changing the ansible default vars.

    $ansible-playbook bootstrap.yml
  7. Deploy the TiDB cluster software

    $ansible-playbook deploy.yml
  8. Start the TiDB cluster

    $ansible-playbook start.yml
  9. Connect to the TiDB cluster using the MySQL client for test

    $mysql -u root -h <nodeip> -P 4000