How to Install CouchBase Database on Ubuntu 22.04

Updated on July 25, 2024
How to Install CouchBase Database on Ubuntu 22.04 header image

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:

Install Couchbase

  1. 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
    
  2. Download the latest Couchbase APT repository configuration package.

    console
    $ curl -O https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-noarch.deb
    
  3. Install the package to add the Couchbase repository information on your server.

    console
    $ sudo dpkg -i ./couchbase-release-1.0-noarch.deb
    
  4. Update the server repository index to synchronize the Couchbase information.

    console
    $ sudo apt-get update
    
  5. Install the latest Couchbase server community package on your server.

    console
    $ sudo apt-get install couchbase-server-community
    
  6. 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
  7. 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
  8. Allow all network connections through the Vultr VPC 2.0 network using UFW.

    console
    $ sudo ufw allow in on enp8s0
    
    Note
    Repeat the above Couchbase installation process on all servers to form a cluster in your Vultr VPC 2.0 network.

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.

  1. Install Nginx on the main Couchbase server.

    console
    $ sudo apt install nginx -y
    
  2. Disable the default Nginx virtual host configuration.

    console
    $ sudo rm /etc/sites-enabled/default
    
  3. Create a new Nginx virtual host configuration using a text editor such as Nano.

    console
    $ sudo nano /etc/nginx/conf.d/couchbase.conf
    
  4. Add the following configurations to the file.

    nginx
    server {
        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 port 8091. In addition, the node1 and node2 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.

  5. Test the Nginx configuration for errors.

    console
    $ sudo nginx -t
    
  6. Restart Nginx to apply the configuration changes.

    console
    $ sudo systemctl restart nginx
    
  7. Allow the HTTP port 80 through the default Uncomplicated Firewall (UFW) to enable connection requests on your server.

    console
    $ sudo ufw allow 80/tcp
    
  8. Reload UFW to apply the new firewall configuration.

    console
    $ sudo ufw reload
    

Create a Couchbase Cluster

  1. Access your main Couchbase server domain using a web browser such as Chrome.

    http://couchbase.example.com
  2. Verify that the Couchbase server interface displays in your web browser. Click Setup New Cluster to configure the new Couchbase cluster.

    Create a new Cluster with the Couchbase Server Web Interface

  3. Enter your Couchbase cluster name, administrator username and a strong password in the respective fields to secure the server.

  4. Click Next: Accept Terms to apply your new administrative user details.

    Create a new Cluster with the Couchbase Server Web Interface

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

    Finish the Cluster Installation with the Couchbase Server Web Interface

Add Couchbase Nodes to the Cluster

  1. 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
  2. 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.

    Join an Existing Cluster with the Couchbase Server Web Interface

  3. Enter your main Couchbase server VPC 2.0 address in the Cluster Host Name/IP Address field.

  4. Enter the administrator username and password you created on your main Couchbase server.

  5. Click Join Cluster to join the main Couchbase server cluster.

    Join an Existing Cluster with the Couchbase Server Web Interface

  6. When the Couchbase cluster connection is successful, verify that the Couchbase interface displays in your web browser.

  7. Click the Servers on the left navigation bar to access the Couchbase cluster.

  8. Click Rebalance button in the top right corner to finish your node configuration process.

    Rebalance the Cluster with the Couchbase Server Web Interface

  9. Wait for the rebalancing process to complete and verify that a new Rebalance Completed Successfully notification displays in your Couchbase dashboard.

    Rebalance the Cluster with the Couchbase Server Web Interface

    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
    Repeat the above process on all servers in your VPC 2.0 network to join the Couchbase cluster.

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.

  1. Access your main Couchbase database server interface.

    https://couchbase.example.com
  2. Click Buckets on the left navigation menu.

  3. Click sample bucket link within the ADD BUCKET notification message.

    Load a The Travel Sample Dataset with the Couchbase Server Web Interface

  4. Select any of the 3 datasets to apply to your database server. For example, check the travel-sample option to use the travel dataset.

  5. Click Load Sample Data to add the sample data on your Couchbase server.

    Load a The Travel Sample Dataset with the Couchbase Server Web Interface

Inspect Data

  1. Click Buckets on the main navigation menu.

    Inspect the Sample Travel Dataset with the Couchbase Server Web Interface

  2. Verify that the new bucket with sample data is available. Then, click Documents next to the travel-sample bucket.

    View Documents in the Sample Travel Dataset with the Couchbase Server Web Interface

  3. Verify the retrieved documents in the travel-sample bucket.

    View Documents in the Sample Travel Dataset with the Couchbase Server Web Interface

  4. Click Buckets on the left navigation menu and select travel-sample to view additional information about the bucket.

  5. Verify the bucket information including the number of replicas, bucket RAM, server nodes and cluster RAM.

  6. Click Scopes & Collections next to Documents to view a list of scopes in the bucket.

    Inspect the Travel Dataset With The Couchbase Web Interface

  7. Click to expand the inventory scope and view all available collections.

    Inspect the Travel Dataset With The Couchbase Web Interface

  8. Verify the scope information including the number of documents in each collection and data such as memory and disk usage.

    Inspect the Travel Dataset With The Couchbase Web Interface

Execute Queries

  1. Click Query on the left navigation menu and enter the following query in the Query Editor field.

    sql
    SELECT 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 the name attribute is queried from the dataset.
    • FROM travel-sample.inventory.hotel: Configures the query to retrieve documents from the travel-sample bucket, the inventory scope and the hotel 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 the type attribute set to hotel, city set to Paris and free_parking set to true.
    • LIMIT 5: Specifies that a maximum of 5 query results are displayed.
  2. Click Execute to run the query.

  3. Verify the query results displayed in a JSON format. The Results field includes 5 hotel names that match the specified conditions.

    Run a Query with the Couchbase Server Web Interface

Monitoring

  1. Click Dashboard on the left navigation menu.

    Monitor Couchbase Server Processes

  2. Verify the Cluster Overview information to monitor statistics about active database processes on the server.

  3. Expand the Node Resources dropdown to view additional information about the server CPU, request rate, and memory usage statistics.

    View the Couchbase Node Resources

  4. Click the Choose Dashboard dropdown to create a new custom monitoring dashboard.

  5. Click new dashboard and enter a name for your dashboard. Then, click Save to create the new monitoring dashboard.

  6. Click Add a Chart to set up a new monitoring chart.

  7. Select combine node data + multiple stats per chart to set up a chart with multiple statistics.

  8. Select multiple charts from the tabbed list of options. For example, select Available RAM and Swap Used. Then, click the Query tab to enable Query Execution Time and Queries > 500ms (queries that take longer than 500 ms to execute).

    Save Monitoring Chart Features

  9. Click Save Chart to apply the new Chart configurations.

  10. 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.

    View the Custom Couchbase Monitoring Dashboard

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.