Deploy Using kwbase CLI
This section describes how to deploy a KWDB cluster on a single machine using the kwbase CLI.
Note: In production environments, deploy only one node per machine to enhance availability and reduce the risk of data loss.
Prerequisites
- The hardware, operating system, software dependencies, and ports of the nodes to be deployed meet the deployment requirements.
- One of the following user permissions:
- Root user access
- Regular user with
sudoprivileges:- Users with passwordless
sudowon't need to enter passwords during installation. - Users without passwordless
sudowill be prompted for passwords when needed.
- Users with passwordless
- The source code is compiled following KWDB Compilation and Installation Instructions.
Steps
Navigate to the program directory:
cd /home/go/src/gitee.com/kwbasedb/install/bin(Optional) For secure deployment, create certificates by following these steps:
Create a directory to store the certificates:
mkdir -p <certs_dir>Generate certificates and keys:
# Create database certificate authority and key ./kwbase cert create-ca --certs-dir=<certs_dir> --ca-key=<certs_dir>/ca.key && \ # Create client certificate and key for database installation user (replace username with actual username) ./kwbase cert create-client <username> --certs-dir=<certs_dir> --ca-key=<certs_dir>/ca.key && \ # Create node certificate and key ./kwbase cert create-node 127.0.0.1 localhost 0.0.0.0 --certs-dir=<certs_dir> --ca-key=<certs_dir>/ca.keyNote
When deploying in cross-machine mode, use the
./kwbase cert create-node <node_ip>command to create certificates and keys for all nodes, then transfer all certificates and keys to every node in the cluster.
Start the cluster by starting all the nodes in the cluster:
For single-replica clusters:
Insecure mode:
./kwbase start-single-replica --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host1>:26257 \ --brpc-addr=:27257 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start-single-replica --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host2>:26258 \ --brpc-addr=:27258 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start-single-replica --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host3>:26259 \ --brpc-addr=:27259 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257Secure mode:
./kwbase start-single-replica \ --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host1>:26257 \ --brpc-addr=:27257 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start-single-replica \ --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host2>:26258 \ --brpc-addr=:27258 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start-single-replica \ --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host3>:26259 \ --brpc-addr=:27259 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257
For multi-replica clusters:
Insecure mode:
./kwbase start --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host1>:26257 \ --brpc-addr=:27257 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host2>:26258 \ --brpc-addr=:27258 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start --insecure \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host3>:26259 \ --brpc-addr=:27259 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257Secure mode:
./kwbase start --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host1>:26257 \ --brpc-addr=:27257 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host2>:26258 \ --brpc-addr=:27258 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257 ./kwbase start --certs-dir=<certs_dir> \ --listen-addr=0.0.0.0:26257 \ --advertise-addr=<host3>:26259 \ --brpc-addr=:27259 \ --http-addr=0.0.0.0:8080 \ --store=/var/lib/kaiwudb \ --join=<host1>:26257
Initialize the cluster.
Insecure mode:
./kwbase init --insecure --host=<address_of_any_node>Secure mode:
./kwbase init --certs-dir=<certs_dir> --host=<address_of_any_node>
View database status.
Insecure mode:
./kwbase node status --insecure --host=<address_of_any_alive_node>Secure mode:
./kwbase node status --certs-dir=<certs_dir> --host=<address_of_any_alive_node>
(Optional) Create a database user and grant admin privileges. If this step is skipped, the system will default to using the user that deployed the database without requiring a password to access the database.
Insecure mode (without password):
./kwbase sql --host=127.0.0.1:$local_port --insecure \ -e "create user $username; \ grant admin to $username with admin option;"Secure mode (with password):
./kwbase sql --certs-dir=/usr/local/kaiwudb/certs --host=127.0.0.1:$local_port \ -e "create user $username with password \"$user_password\"; \ grant admin to $username with admin option;"
After deployment is complete, you can connect to and manage KWDB via kwbase CLI, KWDB Supported Connectors, or KaiwuDB Developer Center.