Skip to main content

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:

DependencyVersionNotes
ca-certificatesany
Gov1.15+
CMakev3.23
Autoconfv2.68+
goyaccv0.8.0+
dpkg-devanyUbuntu only.
devscriptsanyUbuntu only.
build-essentialany
checkinstallany
libsslv1.1.1+- Ubuntu: libssl-dev.
- RHEL, CentOS, Kylin, UOS, AnolisOS: libssl-devel.
libprotobufv3.6.1+- Ubuntu: libprotobuf-dev.
- RHEL, CentOS, Kylin, UOS, AnolisOS: libprotobuf-devel.
liblzmav5.2.0+- Ubuntu: liblzma-dev.
- RHEL, CentOS, Kylin, UOS, AnolisOS: liblzma-devel.
libncursesv6.2.0+- Ubuntu: libncurses5-dev.
- RHEL, CentOS, Kylin, UOS, AnolisOS: libncurses-devel.
libatomicv7.3.0+Only required for GCC and G++ version 7.3.0.
libstdc++-staticv7.3.0+Only required for GCC and G++ version 7.3.0.
protobuf-compilerany
gitany
libprotoc-devv3.6.1+- Ubuntu: libprotoc-dev.
- RHEL, CentOS, Kylin, UOS, AnolisOS: libprotobuf-devel.
gflagsV2.2.2
libz4V1.9.2

Runtime Dependencies:

DependencyVersion
opensslv1.1.1+
libprotobufv3.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>.
geosv3.3.8+
xz-libsv5.2.0+
squashfs-toolsany
libgccv7.3.0+
mountany
squashfseany

Environment Preparation

  1. 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
  2. Download and extract the Go installation package.

    tar -C /usr/local -xvf go1.22.5.linux-amd64.tar.gz
  3. Create a code directory to store the project code.

    mkdir -p /home/go/src/gitee.com
  4. Set environment variables for Go and CMake.

    • For single user: edit ~/.bashrc file

    • For system-wide (requires root): edit /etc/profile file

      export 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
  5. Apply the environment variables immediately:

    • For single user:

      source ~/.bashrc                           
    • For system-wide:

      source /etc/profile                           
  6. 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

  1. Create and switch to the build directory in the project directory.

    cd /home/go/src/gitee.com/kwbasedb
    mkdir build && cd build
  2. Run CMake configuration.

    cmake .. -DCMAKE_BUILD_TYPE= [Release | Debug]

    Parameter description: CMAKE_BUILD_TYPE: Specifies the build type, defaults to Debug. Valid values are Debug or Release, with the first letter capitalized.

  3. Disable Go modules.

    1. Set environment variable

      • For single user: edit ~/.bashrc file

      • For system-wide (requires root): edit /etc/profile file

        export GO111MODULE=off
    2. Apply the environment variables immediately:

      • For single user:

        source ~/.bashrc                           
      • For system-wide:

        source /etc/profile                           
  4. Build and install the project.

    warning
    • If compilation fails due to stale protobuf auto-generated files, use make clean to clean the build directory.
    • If you need to additionally specify the protobuf file path, use make PROTOBUF_DIR=<protobuf_directory>.
    make
    make install

    File 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
  5. (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

  1. Navigate to the directory where the kwbase script is located.

    cd /home/go/src/gitee.com/kwbasedb/install/bin
  2. Set the shared library search path.

    export LD_LIBRARY_PATH=../lib
  3. Start the database.

    ./kwbase start-single-node --insecure --listen-addr=:26257 --background
  4. 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.