CockroachDB is a popular distributed SQL database that is designed to handle large-scale data and offer high availability, scalability, and consistency. Installing a CockroachDB cluster on Ubuntu 24.04 is a relatively straightforward process, and this article will guide you through the steps to set up a CockroachDB cluster on your Ubuntu server.
Step 1: Update Ubuntu
Before you begin, it is recommended to update your Ubuntu system to ensure that you are using the latest software packages. You can do this by running the following commands in the terminal:
sudo apt update
sudo apt upgrade
Step 2: Download and Install CockroachDB
To download and install CockroachDB on your Ubuntu server, you can follow these steps:
-
Visit the CockroachDB download page at https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html#install-cockroachdb and copy the download link for the Linux version.
- Run the following command in the terminal to download the CockroachDB binary:
wget https://binaries.cockroachdb.com/cockroach-v21.x.x.linux-amd64.tgz
- Extract the downloaded file using the following command:
tar -xvf cockroach-v21.x.x.linux-amd64.tgz
- Move the CockroachDB binary to the bin directory to make it accessible from anywhere in the system:
sudo mv cockroach-v21.x.x.linux-amd64/cockroach /usr/local/bin/
- Verify that CockroachDB has been successfully installed by running the following command:
cockroach version
Step 3: Initialize a CockroachDB Cluster
To initialize a CockroachDB cluster, you can follow these steps:
- Create a directory to store the CockroachDB data:
mkdir -p ~/cockroach-data/cluster-1
- Initialize a new CockroachDB node using the following command:
cockroach start --insecure --store=node1 --listen-addr=localhost
--http-addr=localhost:8080 --join=localhost:26257 --background
--store=node-1 --port=26257 --http-port=8080 --store=node1 --insecure
--host=localhost
- Verify that the node has been successfully initialized by running the following command:
cockroach node ls
Step 4: Add Nodes to the CockroachDB Cluster
To add more nodes to the CockroachDB cluster, you can follow these steps:
- Create a new directory to store the CockroachDB data for the second node:
mkdir -p ~/cockroach-data/cluster-2
- Initialize a new CockroachDB node and join it to the existing cluster using the following command, replacing the join address with the address of the existing node:
cockroach start --insecure --store=node2 --listen-addr=localhost
--http-addr=localhost:8081 --join=localhost:26257 --background
--store=node-2 --port=26258 --http-port=8081 --store=node2 --insecure
--host=localhost
- Verify that the new node has been successfully added to the cluster by running the following command:
cockroach node ls
Step 5: Access CockroachDB Admin UI
To access the CockroachDB Admin UI, you can visit http://localhost:8080/ on your web browser. From the admin UI, you can monitor the status of your CockroachDB cluster, view performance metrics, and manage database operations.
Congratulations! You have successfully installed a CockroachDB cluster on your Ubuntu 24.04 server. You can now start using CockroachDB to store and manage your data in a distributed and scalable manner. Happy clustering!