diff --git a/op-guide/build.md b/op-guide/build.md new file mode 100644 index 0000000000000..a7d5bd7c8c2dd --- /dev/null +++ b/op-guide/build.md @@ -0,0 +1,25 @@ +# Build + +## Supported platforms + +The following table lists TiDB support for common architectures and operating systems. + +|Architecture|Operating System|Status| +|------------|----------------|------| +|AMD64|Linux Ubuntu (14.04+)|Stable| +|AMD64|Linux CentOS (7+)|Stable| +|AMD64|Mac OSX|Experimental| + +## Prerequisites + ++ Go [1.5+](https://golang.org/doc/install) ++ Rust [nightly version](https://www.rust-lang.org/downloads.html) ++ GCC 4.8+ with static library + +The [check requirement script](../scripts/check_requirement.sh) can help you check prerequisites and +install the missing ones automatically. + +## Building and installing TiDB components + +You can use the [build script](../scripts/build.sh) to build and install TiDB components in the bin` directory. + diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000000000..cb07fb74edcb6 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +# Use current path for building and installing TiDB. +TIDB_PATH=`PWD` +echo "building TiDB components in $TIDB_PATH" + +# All the binaries are installed in the `bin` directory. +mkdir -p $TIDB_PATH/bin + +# Assume we install go in /usr/local/go +export PATH=$PATH:/usr/local/go/bin + +echo "checking go is installed" +# go is required +go version +# go version go1.6 darwin/amd64 + +echo "checking rust is installed" +# rust nightly is required +rustc -V +# rustc 1.12.0-nightly (7ad125c4e 2016-07-11) + +# GOPATH should be set correctly. +export GOPATH=$TIDB_PATH/deps/go + +build TiDB +echo "building TiDB..." +rm -rf $GOPATH/src/github.com/pingcap/tidb +git clone --depth=1 https://github.com/pingcap/tidb.git $GOPATH/src/github.com/pingcap/tidb +cd $GOPATH/src/github.com/pingcap/tidb + +make server +cp -f ./tidb-server/tidb-server $TIDB_PATH/bin +cd $TIDB_PATH +echo "build TiDB OK" + +# build PD +echo "building PD..." +rm -rf $GOPATH/src/github.com/pingcap/pd +git clone --depth=1 https://github.com/pingcap/pd.git $GOPATH/src/github.com/pingcap/pd +cd $GOPATH/src/github.com/pingcap/pd + +make build +cp -f ./bin/pd-server $TIDB_PATH/bin +cp -rf ./templates $TIDB_PATH/bin/templates +cd $TIDB_PATH +echo "build PD OK" + +# build TiKV +echo "building TiKV..." +rm -rf $TIDB_PATH/deps/tikv +git clone --depth=1 https://github.com/pingcap/tikv.git $TIDB_PATH/deps/tikv +cd $TIDB_PATH/deps/tikv + +ROCKSDB_SYS_STATIC=1 make release + +cp -f ./target/release/tikv-server $TIDB_PATH/bin +cd $TIDB_PATH +echo "build TiKV OK" \ No newline at end of file diff --git a/scripts/check_requirement.sh b/scripts/check_requirement.sh new file mode 100755 index 0000000000000..cfe06eba93f30 --- /dev/null +++ b/scripts/check_requirement.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +set -e + +echo "Checking requirements..." + +SUDO= +if which sudo &>/dev/null; then + SUDO=sudo +fi + +function get_linux_platform { + if [ -f /etc/redhat-release ]; then + # For CentOS or redhat, we treat all as CentOS. + echo "CentOS" + elif [ -f /etc/lsb-release ]; then + DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'` + echo "$DIST" + else + echo "Unknown" + fi +} + +function install_go { + echo "Intall go ..." + case "$OSTYPE" in + linux*) + curl -L https://storage.googleapis.com/golang/go1.6.3.linux-amd64.tar.gz -o golang.tar.gz + ${SUDO} tar -C /usr/local -xzf golang.tar.gz + rm golang.tar.gz + ;; + + darwin*) + curl -L https://storage.googleapis.com/golang/go1.6.3.darwin-amd64.tar.gz -o golang.tar.gz + ${SUDO} tar -C /usr/local -xzf golang.tar.gz + rm golang.tar.gz + ;; + + *) + echo "unsupported $OSTYPE" + exit 1 + ;; + esac +} + +function install_gpp { + echo "Install g++ ..." + case "$OSTYPE" in + linux*) + dist=$(get_linux_platform) + case $dist in + Ubuntu) + ${SUDO} apt-get install -y g++ + ;; + CentOS) + ${SUDO} yum install -y gcc-c++ libstdc++-static + ;; + *) + echo "unsupported platform $dist, you may install g++ manually" + exit 1 + ;; + esac + ;; + + darwin*) + # refer to https://github.com/facebook/rocksdb/blob/master/INSTALL.md + xcode-select --install + brew update + brew tap homebrew/versions + brew install gcc48 --use-llvm + ;; + + *) + echo "unsupported $OSTYPE" + exit 1 + ;; + esac +} + +# Check rust +if which cargo &>/dev/null; then + if ! cargo --version | grep nightly &>/dev/null; then + echo "Please upgrade Rust to nightly." + exit 1 + fi +else + echo "Install Rust ..." + ${SUDO} curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly +fi + +# Check go +if which go &>/dev/null; then + # requires go >= 1.5 + GO_VER_1=`go version | awk 'match($0, /([0-9])+(\.[0-9])+/) { ver = substr($0, RSTART, RLENGTH); split(ver, n, "."); print n[1];}'` + GO_VER_2=`go version | awk 'match($0, /([0-9])+(\.[0-9])+/) { ver = substr($0, RSTART, RLENGTH); split(ver, n, "."); print n[2];}'` + if [[ (($GO_VER_1 -eq 1 && $GO_VER_2 -lt 5)) || (($GO_VER_1 -lt 1)) ]]; then + echo "Please upgrade Go to 1.5 or later." + exit 1 + fi +else + install_go +fi + +# Check g++ +if which g++ &>/dev/null; then + # Check g++ version, RocksDB requires >= 4.7 + G_VER_1=`g++ -dumpversion | awk '{split($0, n, "."); print n[1];}'` + G_VER_2=`g++ -dumpversion | awk '{split($0, n, "."); print n[2];}'` + if [[ (($G_VER_1 -eq 4 && $G_VER_2 -lt 7)) || (($G_VER_1 -lt 4)) ]]; then + echo "Please upgrade g++ to 4.7 or later." + exit 1 + fi +else + install_gpp +fi + +echo OK \ No newline at end of file