×
Community Blog Install and Configure a Riak KV Database Cluster

Install and Configure a Riak KV Database Cluster

In this tutorial, you will learn how to set up three node Riak KV clusters on an Alibaba Cloud ECS instance.

By Hitesh Jethva, Alibaba Cloud Community Blog author.

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

Before you begin this tutorial, you'll need the following items:

  • Three newly created Alibaba Cloud ECS instances with Ubuntu 16.04 installed.
  • 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:

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

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:

nodename = riak@192.168.0.105
erlang.schedulers.force_wakeup_interval = 500
erlang.schedulers.compaction_of_load = false
ring_size = 64
listener.http.internal = 192.168.0.105:8098
listener.protobuf.internal = 192.168.0.105:8087

Save and close the file. Then, check Riak configuration with the riak chkconfig command. The output is as follows:

config is OK
-config /var/lib/riak/generated.configs/app.2019.01.01.21.32.46.config -args_file /var/lib/riak/generated.configs/vm.2019.01.01.21.32.46.args -vm_args /var/lib/riak/generated.configs/vm.2019.01.01.21.32.46.args

Next, start Riak service with the riak start command. On the second instance: open /etc/riak/riak.conf file with the nano /etc/riak/riak.conf command. Then, make the following changes:

nodename = riak@192.168.0.106
erlang.schedulers.force_wakeup_interval = 500
erlang.schedulers.compaction_of_load = false
ring_size = 64
listener.http.internal = 192.168.0.106:8098
listener.protobuf.internal = 192.168.0.106:8087

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:

nodename = riak@192.168.0.107
erlang.schedulers.force_wakeup_interval = 500
erlang.schedulers.compaction_of_load = false
ring_size = 64
listener.http.internal = 192.168.0.107:8098
listener.protobuf.internal = 192.168.0.107:8087

Save and close the file. Then, start Riak configuration and start Riak service with the riak start command, and now you can now check the Riak configuration by running the following command:

curl -v http://192.168.0.105:8098/types/default/props

The output will be as follows:

*   Trying 192.168.0.105...
* Connected to 192.168.0.105 (192.168.0.105) port 8098 (#0)
> GET /types/default/props HTTP/1.1
> Host: 192.168.0.105:8098
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Vary: Accept-Encoding
< Server: MochiWeb/1.1 WebMachine/1.10.9 (cafe not found)
< Date: Tue, 01 Jan 2019 16:04:43 GMT
< Content-Type: application/json
< Content-Length: 447
< 
* Connection #0 to host 192.168.0.105 left intact
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","small_vclock":50,"w":"quorum","write_once":false,"

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:

riak-admin cluster join riak@192.168.0.105

The output will be as follows:

Success: staged join request for 'riak@192.168.0.106' to 'riak@192.168.0.105'

Next, on node3 (third instance), run the following command to join node3 to the node1:

riak-admin cluster join riak@192.168.0.105

The output will be as so:

Success: staged join request for 'riak@192.168.0.107' to 'riak@192.168.0.105'

Now, back to the node1 and run the following command:

riak-admin cluster plan

=============================== Staged Changes ================================
Action         Details(s)
-------------------------------------------------------------------------------
join           'riak@192.168.0.106'
join           'riak@192.168.0.107'
-------------------------------------------------------------------------------


NOTE: Applying these changes will result in 1 cluster transition

###############################################################################
                         After cluster transition 1/1
###############################################################################

================================= Membership ==================================
Status     Ring    Pending    Node
-------------------------------------------------------------------------------
valid     100.0%     34.4%    'riak@192.168.0.105'
valid       0.0%     32.8%    'riak@192.168.0.106'
valid       0.0%     32.8%    'riak@192.168.0.107'
-------------------------------------------------------------------------------
Valid:3 / Leaving:0 / Exiting:0 / Joining:0 / Down:0

WARNING: Not all replicas will be on distinct nodes

Transfers resulting from cluster changes: 42
  21 transfers from 'riak@192.168.0.105' to 'riak@192.168.0.107'
  21 transfers from 'riak@192.168.0.105' to 'riak@192.168.0.106'

Next, commit the changes with the following command:

riak-admin cluster commit
Cluster changes committed

Next, check the cluster status by running the following command on the node1:

riak-admin cluster status

---- Cluster Status ----
Ring ready: true

+------------------------+------+-------+-----+-------+
|          node          |status| avail |ring |pending|
+------------------------+------+-------+-----+-------+
| (C) riak@192.168.0.105 |valid |  up   | 62.5|  34.4 |
|     riak@192.168.0.106 |valid |  up   | 20.3|  32.8 |
|     riak@192.168.0.107 |valid |  up   | 17.2|  32.8 |
+------------------------+------+-------+-----+-------+

Key: (C) = Claimant; availability marked with '!' is unexpected

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:

curl -XPUT http://192.168.0.105:8098/riak/images/2.png -H "Content-type: image/png" --data-binary @2.png

Now, open your web browser and type the address http://192.168.0.106:8098/riak/images/2.png and http://192.168.0.107:8098/riak/images/2.png. You should see the uploaded image in the following page:

1

2

And so now you've successfully configured three node Riak KV cluster on Ubuntu 16.04 server and also test the replication between all nodes.

1 1 1
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments

Dikky Ryan Pratama May 5, 2023 at 4:09 am

I enjoyed reading your article and was struck by your ability to connect seemingly disparate ideas into a cohesive whole.