Introduction
CockroachDB is a distributed database with standard SQL for cloud applications. It stores copies of data in multiple locations to deliver speedy access. It is described as a scalable, consistently-replicated, transactional data store.
CockroachDB features database replication with strong consistency, SQL query language support, automated scaling and repairing, and high availability.
Prerequisites
- A minimum of 2 or more Ubuntu 20.04 servers are required.
- CockroachDB should be pre-installed on the servers.
Note: For installation of Cockroach DB refer to the following article. How to install Cockroach DB on ubuntu OS 20.04.
This article will demonstrate bringing up the Cockroach DB Cluster on two Ubuntu Servers.
Configure the firewall in CockroachDB
- Open the firewall ports which are needed for setting up the CockroachDB. Make sure the below commands are executed on all the servers.
$ sudo ufw allow 8080/tcp
$ sudo ufw allow 26257/tcp - Enabling the
ufw
on both servers.$ sudo ufw enable
- Verify the
ufw
status on both servers.$ sudo ufw status
Output
- Reload the
ufw
on both servers.$ sudo ufw reload
Creating the cluster
First, let's configure the individual server, and then we will set up the cluster.
- Start the CockroachDB on Server 1(192.168.0.1).
cockroach start --insecure --store=server1 --listen-addr=192.168.0.1:26257 --http-addr=192.168.0.1:8080 --join=192.168.0.1:26257,192.168.0.2:26258 --background
The above flags are described as follows:
- –store: For storing the data of the CockroachDB cluster.
- –listen-address: IP address the cockroach DB will be running on server 1 using port
26257
. - -Join: Ipv4 addresses of both servers 1 and sever 2 on ports
26257
and26258
. - –http-addr: IP address the cockroach DB web-based administration will be running on accessed via port
8080
. - –insecure: We will be using the unsecured (http) connection.
- Start the CockroachDB on Server 2(192.168.0.2).
cockroach start --insecure --store=server2 --listen-addr=192.168.0.2:26257 --http-addr=192.168.0.2:8080 --join=192.168.0.1:26257,192.168.0.2:26258 --background
- Initialize the CockroachDB cluster on server 1.
cockroach init --insecure --host=192.168.0.1:26257
Verify the cluster installation
Access the Web Interface via the browser.
- Open a web browser and navigate to below-mentioned URL.
http://192.168.0.1:8080
Output