Compile from Source
This document describes how to compile KWDB from source on Ubuntu 22.04.
Operating System and Software Dependencies
KWDB supports installation and deployment on Linux operating systems. The following table lists the software dependencies required to compile and run KWDB.
Build Dependencies:
| Dependency | Version | Notes |
|---|---|---|
| ca-certificates | any | |
| Go | v1.15+ | |
| CMake | v3.23 | |
| Autoconf | v2.68+ | |
| goyacc | v0.8.0+ | |
| dpkg-dev | any | Ubuntu only. |
| devscripts | any | Ubuntu only. |
| build-essential | any | |
| checkinstall | any | |
| libssl | v1.1.1+ | - Ubuntu: libssl-dev. - RHEL, CentOS, Kylin, UOS, AnolisOS: libssl-devel. |
| libprotobuf | v3.6.1+ | - Ubuntu: libprotobuf-dev. - RHEL, CentOS, Kylin, UOS, AnolisOS: libprotobuf-devel. |
| liblzma | v5.2.0+ | - Ubuntu: liblzma-dev. - RHEL, CentOS, Kylin, UOS, AnolisOS: liblzma-devel. |
| libncurses | v6.2.0+ | - Ubuntu: libncurses5-dev. - RHEL, CentOS, Kylin, UOS, AnolisOS: libncurses-devel. |
| libatomic | v7.3.0+ | Only required for GCC and G++ version 7.3.0. |
| libstdc++-static | v7.3.0+ | Only required for GCC and G++ version 7.3.0. |
| protobuf-compiler | any | |
| git | any | |
| libprotoc-dev | v3.6.1+ | - Ubuntu: libprotoc-dev. - RHEL, CentOS, Kylin, UOS, AnolisOS: libprotobuf-devel. |
| gflags | V2.2.2 | |
| libz4 | V1.9.2 |
Runtime Dependencies:
| Dependency | Version |
|---|---|
| openssl | v1.1.1+ |
| libprotobuf | v3.6.1+ Note: Ubuntu 18.04 default libprotobuf version does not meet the requirements. Users need to install the required version in advance (recommended 3.6.1 and 3.12.4), and specify the higher version path during compilation via make PROTOBUF_DIR=<protobuf_directory>. |
| geos | v3.3.8+ |
| xz-libs | v5.2.0+ |
| squashfs-tools | any |
| libgcc | v7.3.0+ |
| mount | any |
| squashfse | any |
Environment Preparation
-
Download and extract the CMake installation package.
tar -C /usr/local/ -xvf cmake-3.23.4-linux-x86_64.tar.gz
mv /usr/local/cmake-3.23.4-linux-x86_64 /usr/local/cmake -
Download and extract the Go installation package.
tar -C /usr/local -xvf go1.22.5.linux-amd64.tar.gz -
Create a code directory to store the project code.
mkdir -p /home/go/src/gitee.com -
Set environment variables for Go and CMake.
-
For single user: edit
~/.bashrcfile -
For system-wide (requires root): edit
/etc/profilefileexport GOROOT=/usr/local/go
export GOPATH=/home/go # Please use the actual code download and storage path. This example uses /home/go directory.
export PATH=$PATH:/usr/local/go/bin:/usr/local/cmake/bin
-
-
Apply the environment variables immediately:
-
For single user:
source ~/.bashrc -
For system-wide:
source /etc/profile
-
-
Install dependencies (Ubuntu)
sudo apt install -y build-essential libprotobuf-dev protobuf-compiler libssl-dev libgflags-dev libprotoc-dev liblz4-dev autoconf automake libtool libncurses5-dev
Downloading Code
Download the code from the KWDB code repository and store it in the directory specified by GOPATH.
-
Using git clone command:
git clone https://gitee.com/kwdb/kwdb.git /home/go/src/gitee.com/kwbasedb # Do not modify the path src/gitee.com/kwbasedb
cd /home/go/src/gitee.com/kwbasedb
git submodule update --init # For first time code pull
git submodule update --remote -
Download the code archive and extract it to the specified directory.
Building and Installing
-
Create and switch to the build directory in the project directory.
cd /home/go/src/gitee.com/kwbasedb
mkdir build && cd build -
Run CMake configuration.
cmake .. -DCMAKE_BUILD_TYPE= [Release | Debug]Parameter description:
CMAKE_BUILD_TYPE: Specifies the build type, defaults toDebug. Valid values areDebugorRelease, with the first letter capitalized. -
Disable Go modules.
-
Set environment variable
-
For single user: edit
~/.bashrcfile -
For system-wide (requires root): edit
/etc/profilefileexport GO111MODULE=off
-
-
Apply the environment variables immediately:
-
For single user:
source ~/.bashrc -
For system-wide:
source /etc/profile
-
-
-
Build and install the project.
warning- If compilation fails due to stale protobuf auto-generated files, use
make cleanto clean the build directory. - If you need to additionally specify the protobuf file path, use
make PROTOBUF_DIR=<protobuf_directory>.
make
make installFile list after successful build and installation:
/home/go/src/gitee.com/kwbasedb
├── install
│ ├── bin
│ │ ├── err_inject.sh
│ │ ├── query_kwbase_status.sh
│ │ ├── query_status.sh
│ │ ├── setup_cert_file.sh
│ │ ├── utils.sh
│ │ └── kwbase
│ └── lib
│ ├── libcommon.so
│ └── libkwdbts2.so - If compilation fails due to stale protobuf auto-generated files, use
-
(Optional) Navigate to the directory where the kwbase script is located and check the database version to verify successful installation.
./kwbase version
KaiwuDB Version: V2.0.3.2_RC3-3-gfe5eeb853e-dirty
Build Time: 2024/07/19 06:24:00
Distribution:
Platform: linux amd64 (x86_64-linux-gnu)
Go Version: go1.22.5
C Compiler: gcc 11.4.0
Build SHA-1: fe5eeb853e0884a963fd43b380a0b0057f88fb19
Starting the Database
-
Navigate to the directory where the kwbase script is located.
cd /home/go/src/gitee.com/kwbasedb/install/bin -
Set the shared library search path.
export LD_LIBRARY_PATH=../lib -
Start the database.
./kwbase start-single-node --insecure --listen-addr=:26257 --background -
After the database starts, you can connect to and use KWDB via the kwbase CLI tool, KaiwuDB Developer Center, or JDBC and other connectors. For specific connection and usage details, see Connect to KWDB Using kwbase CLI, Connect to KWDB Using KDC, and Connect to KWDB Using JDBC.