How to Setup Riak KV Database Cluster on Ubuntu 18.04

Riak is a distributed NoSQL database that offers high-availability, fault tolerance, operational simplicity, and scalability. Riak has been written in Erlang, and part of 'Basho' products that provide different version, including Riak KV (Key-value), Riak TS (optimized for IoT/Time Series), and Riak CS (Riak Cloud Storage).

In this tutorial, we will show you to step-by-step how to install and configure the NoSQL database Riak KV on Ubuntu 18.04 LTS server. We will create the Riak KV cluster with three Ubuntu servers.

Prerequisites

  • 3 Servers Ubuntu 18.04/16.04
    • hakase-riak01     10.1.1.10
    • hakase-riak02     10.1.1.11
    • hakase-riak03     10.1.1.12
  • Root privileges

What we will do?

  1. Install Riak KV on Ubuntu 18.04
  2. Basic Riak KV Configuration
  3. Setup Riak KV Cluster
  4. Testing

Step 1 - Install Riak KV on Ubuntu 18.04 LTS

The first step we will do for this guide is to install the Riak KV packages on all of the servers, so run all commands in this stage on all servers.

We will install the Riak KV from the packagecloud repository, and will be using the Riak KV packages for Ubuntu Xenial version.

Add the packagecloud key and install 'apt-transport-https'.

curl https://packagecloud.io/gpg.key | sudo apt-key add -
sudo apt-get install -y apt-transport-https

Now go to the '/etc/apt/sources.list.d' directory and create a new repository file 'riak.list'.

cd /etc/apt/sources.list.d/
vim riak.list

Paste Riak KV repository below.

# this file was generated by packagecloud.io for
# the repository at https://packagecloud.io/basho/riak

deb https://packagecloud.io/basho/riak/ubuntu/ xenial main
deb-src https://packagecloud.io/basho/riak/ubuntu/ xenial main

Save and exit.

Update the repository and install the Riak KV packages using the apt command below.

sudo apt update
sudo apt install riak -y

Wait for the installation.

Install Riak Database

Note:

  • Run all commands on this stage on all server nodes.

Step 2 - Basic Configuration Riak KV

In this step, we will configure the Riak KV for our NoSQL cluster. Before configuring the Riak KV itself, we need to setup the open files limit on the Ubuntu system.

Edit the '/etc/security/limits.conf' file using vim editor.

vim /etc/security/limits.conf

Paste configuration below to the end of the line.

riak soft nofile 65536
riak hard nofile 200000

Save and exit.

Now go to the '/etc/riak' directory, edit the default configuration file 'riak.conf'.

cd /etc/riak/
vim riak.conf

Change the default nodename 'riak@localhost' with 'riak@ServerIP'.

nodename = [email protected]

Now uncomment those schedulers lines below.

erlang.schedulers.force_wakeup_interval = 500
erlang.schedulers.compaction_of_load = false

Uncomment the 'ring_size' line and leave it default '64'.

ring_size = 64

Change the HTTP listener and protocol buffers with the 'ServerIP'.

listener.http.internal = 10.1.1.11:8098
listener.protobuf.internal = 10.1.11.11:8087

Save and exit.

Now test riak configurations, then start the riak service.

riak chkconfig
riak start

And the following is the result.

Start Riak

Next, we will test our riak service configuration by running commands below.

riak ping
curl -v http://10.1.1.11:8098/types/default/props

Make sure you get the 'pong' result from the 'riak ping' command, and get the HTTP status code '200' from the curl command.

Basic configurations of Riak KV distributed NoSQL have been completed, and we're ready to setup the Riak KV Cluster.

Note:

  • Run all commands on this stage on all server nodes.

Step 3 - Setup Riak KV Cluster

In this step, we will setup the cluster by joining the 'hakase-riak02' and 'hakase-riak03' nodes to the first node.

Second Node

On the 'hakase-riak02' node, run the riak-admin below.

riak-admin cluster join [email protected]

Setup Riak KV Cluster

Now back to the 'hakase-riak01' node, run riak-admin commands below.

riak-admin cluster plan
riak-admin cluster commit

And the 'hakase-riak02' node has been added to the cluster, check it using command below.

riak-admin cluster status

riak-admin cluster status

Third Node

On the 'hakase-riak03' node, run the riak-admin command below.

riak-admin cluster join [email protected]

Third Node

Now back to the 'hakase-riak01' node, run riak-admin commands below.

riak-admin cluster plan
riak-admin cluster commit

All server node 'hakase-riak02' and 'hakase-riak03' has been added to the cluster, check again using command below.

riak-admin cluster status

The Riak KV cluster installation and configuration has been completed.

iak KV cluster installation complete

Step 4 - Testing

The Riak KV NoSQL cluster has been created, now we want to test the cluster by uploading a data image to the cluster, and test to access from the other nodes to ensure data replication between all nodes.

On the 'hakase-riak01' server, download an image using wget command below.

cd ~/
wget https://vignette.wikia.nocookie.net/nichijou/images/a/a0/113407.jpg -O hakase.jpg

Now upload the image to the Riak KV cluster using curl command.

curl -XPUT http://10.9.9.10:8098/riak/images/hakase.jpg -H "Content-type: image/jpg" --data-binary @hakase.jpg

Testing Riak setup

Open your web browser and type other nodes IP address, and you will get the same image.

'hakase-riak02'.

http://10.1.1.11:8098/riak/images/hakase.jpg

Test node 2

'hakase-riak03'.

http://10.1.1.12:8098/riak/images/hakase.jpg

If you want to delete the image data, use the curl command below.

curl -XDELETE 'http://10.9.9.10:8098/riak/images/hakase.jpg'

The Riak KV Cluster installation and configuration on Ubuntu 18.04 has been completed successfully.

Reference

Share this page:

1 Comment(s)