|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2019 The Vitess Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +source "$(dirname "${BASH_SOURCE[0]:-$0}")/lib/utils.sh" |
| 18 | + |
| 19 | +hostname=$(hostname -f) |
| 20 | +vtctld_web_port=15000 |
| 21 | +export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}" |
| 22 | + |
| 23 | +if [[ $EUID -eq 0 ]]; then |
| 24 | + fail "This script refuses to be run as root. Please switch to a regular user." |
| 25 | +fi |
| 26 | + |
| 27 | +# mysqld might be in /usr/sbin which will not be in the default PATH |
| 28 | +PATH="/usr/sbin:$PATH" |
| 29 | +for binary in mysqld etcd etcdctl curl vtctldclient vttablet vtgate vtctld mysqlctl; do |
| 30 | + command -v "$binary" > /dev/null || fail "${binary} is not installed in PATH. See https://vitess.io/docs/get-started/local/ for install instructions." |
| 31 | +done; |
| 32 | + |
| 33 | +# vtctldclient has a separate alias setup below |
| 34 | +for binary in vttablet vtgate vtctld mysqlctl vtorc vtctl; do |
| 35 | + alias $binary="$binary --config-file-not-found-handling=ignore" |
| 36 | +done; |
| 37 | + |
| 38 | +if [ "${TOPO}" = "zk2" ]; then |
| 39 | + # Each ZooKeeper server needs a list of all servers in the quorum. |
| 40 | + # Since we're running them all locally, we need to give them unique ports. |
| 41 | + # In a real deployment, these should be on different machines, and their |
| 42 | + # respective hostnames should be given. |
| 43 | + zkcfg=(\ |
| 44 | + "1@$hostname:28881:38881:21811" \ |
| 45 | + "2@$hostname:28882:38882:21812" \ |
| 46 | + "3@$hostname:28883:38883:21813" \ |
| 47 | + ) |
| 48 | + printf -v zkcfg ",%s" "${zkcfg[@]}" |
| 49 | + zkcfg=${zkcfg:1} |
| 50 | + |
| 51 | + zkids='1 2 3' |
| 52 | + |
| 53 | + # Set topology environment parameters. |
| 54 | + ZK_SERVER="localhost:21811,localhost:21812,localhost:21813" |
| 55 | + # shellcheck disable=SC2034 |
| 56 | + #TODO: Remove underscore(_) flags in v25, replace them with dashed(-) notation |
| 57 | + TOPOLOGY_FLAGS="--topo_implementation zk2 --topo_global_server_address ${ZK_SERVER} --topo_global_root /vitess/global" |
| 58 | + |
| 59 | + mkdir -p "${VTDATAROOT}/tmp" |
| 60 | +elif [ "${TOPO}" = "consul" ]; then |
| 61 | + # Set up topology environment parameters. |
| 62 | + CONSUL_SERVER=127.0.0.1 |
| 63 | + CONSUL_HTTP_PORT=8500 |
| 64 | + CONSUL_SERVER_PORT=8300 |
| 65 | + #TODO: Remove underscore(_) flags in v25, replace them with dashed(-) notation |
| 66 | + TOPOLOGY_FLAGS="--topo_implementation consul --topo_global_server_address ${CONSUL_SERVER}:${CONSUL_HTTP_PORT} --topo_global_root vitess/global/" |
| 67 | + mkdir -p "${VTDATAROOT}/consul" |
| 68 | +else |
| 69 | + ETCD_SERVER="localhost:2379" |
| 70 | + #TODO: Remove underscore(_) flags in v25, replace them with dashed(-) notation |
| 71 | + TOPOLOGY_FLAGS="--topo_implementation etcd2 --topo_global_server_address $ETCD_SERVER --topo_global_root /vitess/global" |
| 72 | + |
| 73 | + mkdir -p "${VTDATAROOT}/etcd" |
| 74 | +fi |
| 75 | + |
| 76 | +mkdir -p "${VTDATAROOT}/tmp" |
| 77 | + |
| 78 | +# Set aliases to simplify instructions. |
| 79 | +# In your own environment you may prefer to use config files, |
| 80 | +# such as ~/.my.cnf |
| 81 | + |
| 82 | +alias mysql="command mysql --no-defaults -h 127.0.0.1 -P 15306 --binary-as-hex=false" |
| 83 | +alias vtctldclient="command vtctldclient --server localhost:15999" |
| 84 | + |
| 85 | +# If using bash, make sure aliases are expanded in non-interactive shell |
| 86 | +if [[ -n ${BASH} ]]; then |
| 87 | + shopt -s expand_aliases |
| 88 | +fi |
| 89 | + |
0 commit comments