Install and Configure a Riak KV Database Cluster

Riak KV is a distributed NoSQL database built on a set of core services that offers high availability, high fault tolerance, as well as overall operational simplicity and scalability. Riak KV offers an advanced local and multi-cluster replication and automatic data distribution across the cluster for performance and resilience. Riak KV provides the data architecture required by modern messaging and chat applications. Riak KV can able to read and write your data even if hardware failures cause unanticipated outages.

Now that you understand what Riak Kv is, let's get into the tutorial. For this tutorial, you will specifically learn how to set up three node Riak KV clusters on an Alibaba Cloud Elastic Compute Service (ECS) instance.

Prerequisites

A static IP address of 192.168.0.105 that is set up on the first instance, and a static IP address of 192.168.0.106 set up on the second instance, and one of 192.168.0.107 setup on the third instance.

A root password is set up on all the instances.

For reference purposes, you can check out create a new ECS instance and connect to your instance. Next, once you are logged into your Ubuntu 16.04 instance, run the apt-get update -y command to update your base system with the latest available packages.

Getting Started

First, you will need to setup hostname and hostname resolution on all the instances. On the first instance, setup hostname with the hostnamectl set-hostname node1 command. Next, configure hostname resolution by editing /etc/hosts file with the nano /etc/hosts command, and then add the following lines:

192.168.0.105 Node1
192.168.0.106 Node2
192.168.0.107 Node3

On the second instance, setup hostname with the hostnamectl set-hostname node2 command. Next, configure hostname resolution by editing /etc/hosts file with the nano /etc/hosts command, and then add the following lines:

192.168.0.105 Node1
192.168.0.106 Node2
192.168.0.107 Node3

On the third instance, setup hostname with the hostnamectl set-hostname node3 commandconfigure hostname resolution by editing /etc/hosts file with the nano /etc/hosts command and add the following lines:

192.168.0.105 Node1
192.168.0.106 Node2
192.168.0.107 Node3

Save and close the file, when you are finished.

Install Riak KV

Before starting, you will need to install Riak KV on all the instances. By default, Riak KV is not available in the Ubuntu 16.04 default repository. So, you will need to add a repository for that. To do so, follow these steps:

First, download and add the GPG key with the following command:

curl https://packagecloud.io/gpg.key | apt-key add -

Next, add the repository by editing /etc/apt/sources.list file with the nano /etc/apt/sources.list command. Then, add the following line:

Save and close the file, when you are finished. Then, update the repository and install the Riak KV with the following command:

apt-get update -y
apt-get install riak -y

Configure Riak KV

Next, you will need to configure Riak KV on all the instances. First, you will need to set up the open files limit on all the instances. You can do this by editing /etc/security/limits.conf file with the nano /etc/security/limits.conf command.Then, add the following lines:

riak soft nofile 65536
riak hard nofile 200000

Save and close the file. Next, you will need to configure Riak KV default configuration file on all the instances. On the first instance: open /etc/riak/riak.conf file with the nano /etc/riak/riak.conf command. Then, make the following changes:

Save and close the file. Then, start Riak service with the riak start command, and on the third instance : open /etc/riak/riak.conf file with the nano /etc/riak/riak.conf command, and make the following changes:

Configure Riak KV Cluster

Riak KV basic setup is now completed. Now, you will need to setup the cluster by joining the node2 and node3 to the node1. To do this, on node2 (second instance), run the following command to join node2 to the node1:

Test Riak KV

The Riak KV cluster is now setup successfully, so now it's time to test the cluster by uploading some image to the clusterand try to access the uploaded image by accessing other nodes. To do so, first on node1, download the sample image with the following command:

wget https://www.gstatic.com/webp/gallery3/2.png

Next, upload the downloaded image to the Riak KV cluster with the following command: