Local Install

Instructions for using Vitess on your machine for testing purposes

This guide covers installing Vitess locally for testing purposes, from pre-compiled binaries. We will launch multiple copies of mysqld, so it is recommended to have greater than 4GB RAM, as well as 20GB of available disk space.

A docker setup is also available, which requires no dependencies on your local host.

Install MySQL and etcd

Vitess supports the databases listed here. We recommend MySQL 8.0 if your installation method provides that option:

  1. # Ubuntu based
  2. sudo apt install -y mysql-server etcd curl
  3. # Debian
  4. sudo apt install -y default-mysql-server default-mysql-client etcd curl
  5. # Yum based
  6. sudo yum -y localinstall https://dev.mysql.com/get/mysql80-community-release-el8-3.noarch.rpm
  7. sudo yum -y install mysql-community-server etcd curl

On apt-based distributions the services mysqld and etcd will need to be shutdown, since etcd will conflict with the etcd started in the examples, and mysqlctl will start its own copies of mysqld:

  1. # Debian and Ubuntu
  2. sudo service mysql stop
  3. sudo service etcd stop
  4. sudo systemctl disable mysql
  5. sudo systemctl disable etcd

Install Node

  1. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

Ensure the following is in your bashrc/zshrc or similar. nvm automatically attempts to add them:

  1. export NVM_DIR="$HOME/.nvm"
  2. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  3. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Finally, install node:

  1. nvm install 18
  2. nvm use 18

See the vtadmin README for more details.

Disable AppArmor or SELinux

AppArmor/SELinux will not allow Vitess to launch MySQL in any data directory by default. You will need to disable it:

AppArmor:

  1. # Debian and Ubuntu
  2. sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
  3. sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
  4. # The following command should return an empty result:
  5. sudo aa-status | grep mysqld

SELinux:

  1. # CentOS
  2. sudo setenforce 0

Install Vitess

Download the latest binary release for Vitess on Linux. For example with Vitess 18:

Notes:

  1. version=18.0.1
  2. file=vitess-${version}-aa72dc8.tar.gz
  3. wget https://github.com/vitessio/vitess/releases/download/v${version}/${file}
  4. tar -xzf ${file}
  5. cd ${file/.tar.gz/}
  6. sudo mkdir -p /usr/local/vitess
  7. sudo cp -r * /usr/local/vitess/

Make sure to add /usr/local/vitess/bin to the PATH environment variable. You can do this by adding the following to your $HOME/.bashrc file:

  1. export PATH=/usr/local/vitess/bin:${PATH}

You are now ready to start your first cluster! Open a new terminal window to ensure your .bashrc file changes take effect.

Start a Single Keyspace Cluster

Start by copying the local examples included with Vitess to your preferred location. For our first example we will deploy a single unsharded keyspace. The file 101_initial_cluster.sh is for example 1 phase 01. Lets execute it now:

  1. vitess_path=/usr/local/vitess
  2. mkdir ~/my-vitess-example
  3. cp -r ${vitess_path}/{examples,web} ~/my-vitess-example
  4. cd ~/my-vitess-example/examples/local
  5. ./101_initial_cluster.sh

You should see an output similar to the following:

  1. $ ./101_initial_cluster.sh
  2. add /vitess/global
  3. add /vitess/zone1
  4. add zone1 CellInfo
  5. Created cell: zone1
  6. etcd start done...
  7. Starting vtctld...
  8. vtctld is running!
  9. Successfully created keyspace commerce. Result:
  10. {
  11. "name": "commerce",
  12. "keyspace": {
  13. "served_froms": [],
  14. "keyspace_type": 0,
  15. "base_keyspace": "",
  16. "snapshot_time": null,
  17. "durability_policy": "semi_sync",
  18. "throttler_config": null,
  19. "sidecar_db_name": "_vt"
  20. }
  21. }
  22. Starting MySQL for tablet zone1-0000000100...
  23. Starting vttablet for zone1-0000000100...
  24. HTTP/1.1 200 OK
  25. Date: Mon, 26 Jun 2023 19:21:51 GMT
  26. Content-Type: text/html; charset=utf-8
  27. Starting MySQL for tablet zone1-0000000101...
  28. Starting vttablet for zone1-0000000101...
  29. HTTP/1.1 200 OK
  30. Date: Mon, 26 Jun 2023 19:21:54 GMT
  31. Content-Type: text/html; charset=utf-8
  32. Starting MySQL for tablet zone1-0000000102...
  33. Starting vttablet for zone1-0000000102...
  34. HTTP/1.1 200 OK
  35. Date: Mon, 26 Jun 2023 19:21:56 GMT
  36. Content-Type: text/html; charset=utf-8
  37. vtorc is running!
  38. - UI: http://localhost:16000
  39. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtorc.out
  40. - PID: 49556
  41. New VSchema object:
  42. {
  43. "sharded": false,
  44. "vindexes": {},
  45. "tables": {
  46. "corder": {
  47. "type": "",
  48. "column_vindexes": [],
  49. "auto_increment": null,
  50. "columns": [],
  51. "pinned": "",
  52. "column_list_authoritative": false,
  53. "source": ""
  54. },
  55. "customer": {
  56. "type": "",
  57. "column_vindexes": [],
  58. "auto_increment": null,
  59. "columns": [],
  60. "pinned": "",
  61. "column_list_authoritative": false,
  62. "source": ""
  63. },
  64. "product": {
  65. "type": "",
  66. "column_vindexes": [],
  67. "auto_increment": null,
  68. "columns": [],
  69. "pinned": "",
  70. "column_list_authoritative": false,
  71. "source": ""
  72. }
  73. },
  74. "require_explicit_routing": false
  75. }
  76. If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).
  77. Waiting for vtgate to be up...
  78. vtgate is up!
  79. Access vtgate at http://Florents-MacBook-Pro-2.local:15001/debug/status
  80. vtadmin-api is running!
  81. - API: http://Florents-MacBook-Pro-2.local:14200
  82. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtadmin-api.out
  83. - PID: 49695
  84. vtadmin-web is running!
  85. - Browser: http://Florents-MacBook-Pro-2.local:14201
  86. - Logs: /Users/florentpoinsard/Code/vitess/vtdataroot/tmp/vtadmin-web.out
  87. - PID: 49698

You can also verify that the processes have started with pgrep:

  1. $ pgrep -fl vitess
  2. 14119 etcd
  3. 14176 vtctld
  4. 14251 mysqld_safe
  5. 14720 mysqld
  6. 14787 vttablet
  7. 14885 mysqld_safe
  8. 15352 mysqld
  9. 15396 vttablet
  10. 15492 mysqld_safe
  11. 15959 mysqld
  12. 16006 vttablet
  13. 16112 vtgate
  14. 16788 vtorc

The exact list of processes will vary. For example, you may not see mysqld_safe listed.

If you encounter any errors, such as ports already in use, you can kill the processes and start over:

  1. pkill -9 -f '(vtdataroot|VTDATAROOT|vitess|vtadmin)' # kill Vitess processes
  2. rm -rf vtdataroot

Setup Aliases

For ease-of-use, Vitess provides aliases for mysql and vtcltdclient:

  1. source ../common/env.sh

Setting up aliases changes mysql to always connect to Vitess for your current session. To revert this, type unalias mysql && unalias vtctldclient or close your session.

Connect to your cluster

You should now be able to connect to the VTGate server that was started in 101_initial_cluster.sh:

  1. $ mysql
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 2
  4. Server version: 8.0.31-Vitess (Ubuntu)
  5. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. mysql> show tables;
  11. +-----------------------+
  12. | Tables_in_vt_commerce |
  13. +-----------------------+
  14. | corder |
  15. | customer |
  16. | product |
  17. +-----------------------+
  18. 3 rows in set (0.00 sec)

You can also now browse and administer your new Vitess cluster using the VTAdmin UI at the following URL:

  1. http://localhost:14201

VTOrc is also setup as part of the initialization. You can look at its user-interface at:

  1. http://localhost:16000

Summary

In this example, we deployed a single unsharded keyspace named commerce. Unsharded keyspaces have a single shard named 0. The following schema reflects a common ecommerce scenario that was created by the script:

  1. create table product (
  2. sku varbinary(128),
  3. description varbinary(128),
  4. price bigint,
  5. primary key(sku)
  6. );
  7. create table customer (
  8. customer_id bigint not null auto_increment,
  9. email varbinary(128),
  10. primary key(customer_id)
  11. );
  12. create table corder (
  13. order_id bigint not null auto_increment,
  14. customer_id bigint,
  15. sku varbinary(128),
  16. price bigint,
  17. primary key(order_id)
  18. );

The schema has been simplified to include only those fields that are significant to the example:

  • The product table contains the product information for all of the products.
  • The customer table has a customer_id that has an auto_increment. A typical customer table would have a lot more columns, and sometimes additional detail tables.
  • The corder table (named so because order is an SQL reserved word) has an order_id auto-increment column. It also has foreign keys into customer(customer_id) and product(sku).

Next Steps

You can now proceed with MoveTables.

Or alternatively, if you would like to teardown your example:

  1. ./401_teardown.sh
  2. rm -rf vtdataroot