How to Install CouchBase Database on Ubuntu 22.04
Introduction
Couchbase is a distributed NoSQL database management designed to deliver high performance, scalability, and flexibility while managing large volumes of data. It combines key-value and document-oriented database functionalities to optimize the storage and retrieval of unstructured data. The Couchbase memory-first architecture focuses on in-memory storage over server storage to improve the response rate for production applications.
This article explains how to deploy a Couchbase database cluster on Ubuntu 22.04. You will use the Vultr VPC 2.0 network to internalize all cluster communications and securely integrate all nodes to form a high-performance cluster.
Prerequisites
In a single Vultr location:
- Deploy a Ubuntu 22.04 server instance with at least
4GB
RAM to use as the Couchbase server. - Deploy at least two Ubuntu 22.04 instances to use as Couchbase nodes with at least
4GB
RAM each. - Attach all servers to the same Vultr VPC 2.0 network to form an internal Couchbase cluster.
- Set Up a new domain A record pointing to the main Couchbase server IP address. For example,
couchbase.example.com
.
Install Couchbase
Access the main Couchbase server using SSH as a non-root user with sudo privileges. Replace
linuxuser
with your actual sudo user account.console$ ssh linuxuser@SERVER-IP
Download the latest Couchbase APT repository configuration package.
console$ curl -O https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-noarch.deb
Install the package to add the Couchbase repository information on your server.
console$ sudo dpkg -i ./couchbase-release-1.0-noarch.deb
Update the server repository index to synchronize the Couchbase information.
console$ sudo apt-get update
Install the latest Couchbase server community package on your server.
console$ sudo apt-get install couchbase-server-community
View the Couchbase server status and verify that it's actively running on your server.
console$ service couchbase-server status
Output:
● couchbase-server.service - Couchbase Server Loaded: loaded (/lib/systemd/system/couchbase-server.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2024-05-26 19:00:42 UTC; 37min ago Docs: https://docs.couchbase.com Main PID: 3177 (beam.smp) Tasks: 284 (limit: 9381) Memory: 937.3M CPU: 2min 33.339s CGroup: /system.slice/couchbase-server.service
View the server IP information and verify the Vultr VPC 2.0 network interface address.
console$ ip a
Your output should be similar to the one below:
3: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc mq state UP group default qlen 1000 link/ether 5a:01:04:ef:52:47 brd ff:ff:ff:ff:ff:ff inet 10.50.96.4/20 brd 10.50.111.255 scope global enp8s0 valid_lft forever preferred_lft forever inet6 fe80::5801:4ff:feef:5247/64 scope link valid_lft forever preferred_lft forever
Allow all network connections through the Vultr VPC 2.0 network using UFW.
console$ sudo ufw allow in on enp8s0
Note
Configure Nginx as a Reverse Proxy to Access the Cluster
All Couchbase servers in the Vultr VPC 2.0 network communicate with each other using private network addresses. Configure Nginx on the main Couchbase server to work as a reverse proxy to securely access all servers without exposing the backend application ports to the Internet. Follow the steps below to install and configure Nginx as a reverse proxy to forward connections to the internal Couchbase cluster nodes.
Install Nginx on the main Couchbase server.
console$ sudo apt install nginx -y
Disable the default Nginx virtual host configuration.
console$ sudo rm /etc/sites-enabled/default
Create a new Nginx virtual host configuration using a text editor such as Nano.
console$ sudo nano /etc/nginx/conf.d/couchbase.conf
Add the following configurations to the file.
nginxserver { listen 80; server_name couchbase.example.com; location / { proxy_pass http://127.0.0.1:8091; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } # Couchbase Node 1 location /node1 { proxy_pass http://10.50.96.3:8091; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } # Couchbase Node 2 location /node2 { proxy_pass http://10.50.96.4:8091; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Save and close the file.
The above Nginx configuration forwards all external HTTP port
80
requests to the main Couchbase server interface port8091
. In addition, thenode1
andnode2
paths redirect to the respective Couchbase servers in your VPC 2.0 network using private network addresses. The above configuration secures all Couchbase external and internal communications by forwarding all connection requests using different access methods.Test the Nginx configuration for errors.
console$ sudo nginx -t
Restart Nginx to apply the configuration changes.
console$ sudo systemctl restart nginx
Allow the HTTP port
80
through the default Uncomplicated Firewall (UFW) to enable connection requests on your server.console$ sudo ufw allow 80/tcp
Reload UFW to apply the new firewall configuration.
console$ sudo ufw reload
Create a Couchbase Cluster
Access your main Couchbase server domain using a web browser such as Chrome.
http://couchbase.example.com
Verify that the Couchbase server interface displays in your web browser. Click Setup New Cluster to configure the new Couchbase cluster.
Enter your Couchbase cluster name, administrator username and a strong password in the respective fields to secure the server.
Click Next: Accept Terms to apply your new administrative user details.
Click the
I accept the terms & conditions
checkbox to accept the Couchbase terms of service and click Finish with Defaults to finish the configuration process.
Add Couchbase Nodes to the Cluster
Access your Couchbase cluster nodes using your domain and the path you specified in the Nginx configuration based on the server's internal VPC 2.0 address. For example, access your node-1 Couchbase server.
http://couchbase.example.com/node1
Verify that the Couchbase setup interface displays in your web browser and click Join Existing Cluster to set up set up a connection to the main Couchbase server.
Enter your main Couchbase server VPC 2.0 address in the Cluster Host Name/IP Address field.
Enter the administrator username and password you created on your main Couchbase server.
Click Join Cluster to join the main Couchbase server cluster.
When the Couchbase cluster connection is successful, verify that the Couchbase interface displays in your web browser.
Click the Servers on the left navigation bar to access the Couchbase cluster.
Click Rebalance button in the top right corner to finish your node configuration process.
Wait for the rebalancing process to complete and verify that a new
Rebalance Completed Successfully
notification displays in your Couchbase dashboard.You have connected the Couchbase node to your cluster. The main Couchbase server actively maintains the cluster and communicates with all nodes in the VPC 2.0 network.
Note
Load a Sample Dataset
The Couchbase server contains 3
sample datasets you can experiment with to use the database cluster. Follow the steps below to load a sample dataset that stores travel data such as hotels and airports.
Access your main Couchbase database server interface.
https://couchbase.example.com
Click Buckets on the left navigation menu.
Click sample bucket link within the
ADD BUCKET
notification message.Select any of the
3
datasets to apply to your database server. For example, check the travel-sample option to use the travel dataset.Click Load Sample Data to add the sample data on your Couchbase server.
Inspect Data
Click Buckets on the main navigation menu.
Verify that the new bucket with sample data is available. Then, click Documents next to the
travel-sample
bucket.Verify the retrieved documents in the
travel-sample
bucket.Click Buckets on the left navigation menu and select
travel-sample
to view additional information about the bucket.Verify the bucket information including the number of replicas, bucket RAM, server nodes and cluster RAM.
Click Scopes & Collections next to Documents to view a list of scopes in the bucket.
Click to expand the inventory scope and view all available collections.
Verify the scope information including the number of documents in each collection and data such as memory and disk usage.
Execute Queries
Click Query on the left navigation menu and enter the following query in the Query Editor field.
sqlSELECT name FROM `travel-sample`.inventory.hotel WHERE type = "hotel" AND city = "Paris" AND free_parking = true LIMIT 5;
The above query retrieves hotels located in Paris with free parking. Within the query:
SELECT name
: Specifies that thename
attribute is queried from the dataset.FROM
travel-sample.inventory.hotel
: Configures the query to retrieve documents from thetravel-sample
bucket, theinventory
scope and thehotel
collection.WHERE type = "hotel" AND city = "Paris" AND free_parking = true
: Defines the conditions that each document must meet for inclusion in the query results. The document must have thetype
attribute set tohotel
,city
set toParis
andfree_parking
set to true.LIMIT 5
: Specifies that a maximum of 5 query results are displayed.
Click Execute to run the query.
Verify the query results displayed in a JSON format. The
Results
field includes5
hotel names that match the specified conditions.
Monitoring
Click Dashboard on the left navigation menu.
Verify the Cluster Overview information to monitor statistics about active database processes on the server.
Expand the Node Resources dropdown to view additional information about the server CPU, request rate, and memory usage statistics.
Click the
Choose Dashboard
dropdown to create a new custom monitoring dashboard.Click new dashboard and enter a name for your dashboard. Then, click Save to create the new monitoring dashboard.
Click Add a Chart to set up a new monitoring chart.
Select combine node data + multiple stats per chart to set up a chart with multiple statistics.
Select multiple charts from the tabbed list of options. For example, select
Available RAM
andSwap Used
. Then, click the Query tab to enableQuery Execution Time
andQueries > 500ms
(queries that take longer than 500 ms to execute).Click Save Chart to apply the new Chart configurations.
Expand the Cluster Overview group and verify that your charts are active. For example, the charts display data, such as the time it takes for queries to execute on the server.
Conclusion
You have deployed a Couchbase cluster with multiple nodes in a Vultr VPC 2.0 network. The main Couchbase server securely manages all nodes to perform basic database operations such as loading datasets, data inspection, query execution, bucket creation, scopes, collections, and documents within the cluster. For more information about Couchbase server clusters, visit the official documentation.