Here are some points in the compilation process of TiDB. Although in theory, the source code downloaded from github can be compiled after decompression, in the actual operation process, there may still be errors due to various reasons. This paper shares several problems and solutions in the actual operation process.
The environment used in this article is CentOS 7.4
- Environmental preparation
(1) golang compilation environment
For the compilation environment of golang, it is recommended to install it directly with yum in many articles, as follows:
yum install golang -y
This is OK, but it should be noted that the installed version of golang is related to the configured yum source. Generally, it is not the latest version. The go version installed by the author using this method is 1.15.14. This version cannot compile the current "git clone" normally https://github.com/pingcap/tidb.git ”The downloaded TiDB version can be used to download and decompress the earlier version on GitHub, such as 5.0. Git clone for compilation https://github.com/pingcap/tidb.git ”The downloaded TiDB version needs to be above golang version 1.16, which can be downloaded from the official website of golang. 1.17 used in this article is as follows:
wget https://golang.google.cn/dl/go1.17.linux-amd64.tar.gz
Then unzip it directly into the directory to be installed:
tar -zxf go1.17.linux-amd64.tar.gz -C /usr/local
Next, configure the golang environment variable (in. bashrc or. bash_profile) as follows:
export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export GOARCH=amd64
export GOOS=linux
export GOPATH=/opt/tidb
Among them, in GOPATH, prepare the location of TiDB source code download, storage and compilation
(2) Rust compilation environment
The Rust compilation environment can be directly described in other articles on the Internet, from which you can find the nightly version of the corresponding platform:
wget https://mirrors.ustc.edu.cn/rust-static/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz && tar zxf rust-nightly-x86_64-unknown-linux-gnu.tar.gz
cd rust-nightly-x86_64-unknown-linux-gnu
./install.sh
Then configure the Rust environment variable (in. bashrc or. bash_profile) as follows:
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
Then apply the environment variable
. ~/.bashrc
(3) Hard disk space
If you compile directly from clone TiDB, PD and TiKV on github, you need to prepare large disk space first. During the compilation process, you need to download a lot of things online from github and google. Finally, you need to occupy a total of more than 10GB of space
- Code download
First create a subdirectory under GOPATH set above:
Mkdir -p src/github.com/pingcap/
Under this subdirectory:
There are two ways
First, git clone:
git clone https://github.com/pingcap/tidb.git
git clone GitHub - tikv/pd: Placement driver for TiKV
git clone https://github.com/pingcap/tikv.git
Second, choose from github, that is, download the appropriate version by yourself
- compile
(1)Tidb
In short:
cd tidb
gmake
However, there may be some problems:
One is in main Go hang stayed for a long time, as follows:
This is probably because github or google are not connected. If you can try to set GOPROXY to solve it
export GOPROXY=https://goproxy.cn,direct
Second, sometimes:
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-1164296440/000014.o: unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
This is because the version of ld is too low and needs to be upgraded. You can use
yum install binutils
Sometimes it may be
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
.... For other mistakes, you can try the following:
yum install glibc-static.x86_64 -y
If you can't connect to google, you need to go Add replace after mub
replace ( cloud.google.com/go => github.com/google/go-cloud v0.4.1-0.20181112030950-0b43d4400e53 go.uber.org/atomic => github.com/uber-go/atomic v1.3.3-0.20181018215023-8dc6146f7569 go.uber.org/multierr => github.com/uber-go/multierr v1.1.1-0.20180122172545-ddea229ff1df go.uber.org/zap => github.com/uber-go/zap v1.9.2-0.20180814183419-67bc79d13d15 golang.org/x/crypto => github.com/golang/crypto v0.0.0-20181106171534-e4dc69e5b2fd golang.org/x/lint => github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 golang.org/x/net => github.com/golang/net v0.0.0-20181108082009-03003ca0c849 golang.org/x/oauth2 => github.com/golang/oauth2 v0.0.0-20181106182150-f42d05182288 golang.org/x/sync => github.com/golang/sync v0.0.0-20181108010431-42b317875d0f golang.org/x/sys => github.com/golang/sys v0.0.0-20181107165924-66b7b1311ac8 golang.org/x/text => github.com/golang/text v0.3.1-0.20181030141323-6f44c5a2ea40 golang.org/x/time => github.com/golang/time v0.0.0-20181108054448-85acf8d2951c golang.org/x/tools => github.com/golang/tools v0.0.0-20181111003725-6d71ab8aade0 google.golang.org/api => github.com/google/google-api-go-client v0.0.0-20181108001712-cfbc873f6b93 google.golang.org/appengine => github.com/golang/appengine v1.3.1-0.20181031002003-4a4468ece617 google.golang.org/genproto => github.com/google/go-genproto v0.0.0-20181109154231-b5d43981345b google.golang.org/grpc => github.com/grpc/grpc-go v1.2.1-0.20181109233107-eb55fa50e6c9 honnef.co/go/tools => github.com/dominikh/go-tools v0.0.0-20180920025451-e3ad64cb4ed3 )
If the later version of v does not display correctly, you can try to change it to master
(2)Pd
cd pd
gmake
(3)Tikv
cd tikv
carge build
It takes a long time to compile tikv. In addition, there is another point to pay special attention to:
At present, the new version of git clone compiled (January 2022) requires a higher version of GCC. Version 4.8.5 of CentOS7 comes with errors when compiling grcp (0.9.1)
Therefore, you need to upgrade the gcc version yourself