Skip to main content

Working with Couchbase

Hands-On Lab

 

Photo of Michael McClaren

Michael McClaren

Linux Training Architect I in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on lab, we will install and initialize a Couchbase server on CentOS 7. Once that is complete, we will create a bucket and create some test data.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Working with Couchbase

Introduction

In this hands-on lab, we will install and initialize a Couchbase server on CentOS 7. Once that is complete, we will create a bucket and create some test data.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS

Install Couchbase

  1. Get the Couchbase RPM for version 6 and install it:

    wget https://packages.couchbase.com/releases/6.0.0/couchbase-server-community-6.0.0-centos7.x86_64.rpm 
    sudo yum install -y couchbase-server-community-6.0.0-centos7.x86_64.rpm 
  2. Set the file limits in the limits.conf file:

    sudo vim /etc/security/limits.conf

    Add these lines:

    * soft nofile 75000
    * hard nofile 75000
  3. Start the Couchbase server:

    sudo /opt/couchbase/bin/couchbase-server -- -noinput -detached 

Create the Bucket and Test Data

  1. Set up the Couchbase server:

    • Access the GUI at <PUBLIC_IP_ADDRESS>:8091
    • Click Setup New Cluster
    • On the New Cluster page, provide the following information:
      • Cluster Name: LinuxAcademy
      • Create Admin Username: Administrator
      • Create Password: Omgpassword!
    • Click Next: Accept Terms
    • Check the box to accept the terms and conditions
    • Click Finish With Defaults
  2. To create the bucket via the GUI:

    • Click Buckets in the menu on the left
    • Click ADD BUCKET in the top-right of the page
      • Name: testdata
      • Memory Quota: 128
      • Bucket Type: Couchbase
    • Click Add bucket
  3. Delete the bucket via the GUI so we can practice creating the bucket via the CLI:

    • Click the bucket name to show details about the bucket
    • Click Delete, Delete Bucket
  4. From the CLI:

    cd /opt/couchbase/bin
    ./couchbase-cli bucket-create -c 127.0.0.1:8091 --username Administrator --password Omgpassword! --bucket testdata --bucket-type couchbase --bucket-ramsize 128
  5. Locate the data in the ~/data folder. There is a formatted version and there is an unformatted version. Either way, create a query from this data and run it against the bucket.

    Import the data using cbq:

    ./cbq -e http://127.0.0.1:8091 -u=Administrator

    Provide the password "Omgpassword!"

    Run the following:

    INSERT INTO `testdata` (KEY,VALUE) VALUES
    ("Employee_Duck",
    {"name":"Donald Duck",
    "status":"active",
    "phone":{"primary":"5551212","secondary":"8329050"}}),
    ("Employee_James",
    {"name":"Jimmy James",
    "status":"active",
    "phone":{"primary":"8001234","secondary":"none"}}),
    ("Employee_Solo",
    {"name":"Han Solo",
    "status":"retired",
    "phone":{"primary":"none","secondary":"none"}}),
    ("Employee_Bacca",
    {"name":"Chew Bacca",
    "status":"retired",
    "phone":{"primary":"6123478","secondary":"6461234"}});

Confirm the Data Was Created Correctly

  1. In the GUI, the bucket will show the documents that were created, however, to make the bucket searchable, you will need to create an index:

    CREATE PRIMARY INDEX `td_idx` ON `testdata`

    Then confirm that the data can be queried:

    Select * from `testdata`;
  2. Exit cbq

    EXIT

Conclusion

Congratulations — you've completed this hands-on lab!