• Get In Touch
January 15, 2016

How to Install Riak On Ubuntu 14.04

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Riak (Riak KV) is a distributed NoSQL database that is highly available, scalable, and easy to operate.

Riak KV automatically distributes data across the cluster to ensure fast performance and fault-tolerance.

Several key features that Riak has :

  • High Availability. Riak KV is designed to intelligently replicate and retrieve data. Any data that you have from IoT to hybrid cloud application is always available.
  • Massive Scalability. Riak uses scale-out architecture which enables you to add capacity seamlessly using commodity hardware. Add a new machine to the cluster and the performance improvement is near-linear.
  • Operational Simplicity. Data is automatically distributed across nodes. You only need to add a new machine to add capacity – no need to think about distibuting the data itself.
  • Fault Tolerant. Riak can still work, read and write your data, even if there is a network partition or hardware failure.
  • Low Latency. With global replication and masterless architecture, Riak KV serves data quickly and predictably even under peak load conditions.
  • Complex Query Support. Riak KV provides you with three ways to query data using Solr full-text search, secondary indexes and Map Reduce.
  • Riak Data Types. Riak KV provides pre-built data types for the most common data structures that are required by distributed, active workloads.
  • Robust APIs and Client Libraries. Whether you code in Java, Ruby, Python, C#, Erlang, Node.js or .NET – Riak KV makes it easy to select the language your application needs.
  • Multi Cluster Replication. Riak KV makes it easy to replicate clusters across your datacenter or around the world for data geo-location, secondary analytics or business continuity.

Updating the Base System

This tutorial assumes that we have a clean Ubuntu Server 14.04. Before installing Riak, let’s update our base system to the latest update

$ sudo apt-get update
$ sudo apt-get -y upgrade

Now our base system is ready, lets get the latest update and we’re ready to install Riak on our system.

Installing Riak

The first step that we have to do is adding packagecloud signing key so that we can verify Riak packages that we will download.

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

Add riak repository to new apt list file. We will create separate list file under /etc/apt/sources.list.d/ directory.

$ echo "deb https://packagecloud.io/basho/riak/ubuntu/ trusty main" | sudo tee -a /etc/apt/sources.list.d/riak.list
$ echo "deb-src https://packagecloud.io/basho/riak/ubuntu/ trusty main" | sudo tee -a /etc/apt/sources.list.d/riak.list

Update your repository local database.

$ sudo apt-get update

Install Riak

$ sudo apt-get install riak

Now let’s check the riak service status

$ sudo service riak status
Node 'riak@127.0.0.1' not responding to pings.
riak is stopped

We can see above that Riak is not started by default. Let’s start riak service

$ sudo service riak start
!!!!
!!!! WARNING: ulimit -n is 1024; 65536 is the recommended minimum.
!!!!

We can ignore the warning above for now, we’ll deal with it later. Now if we check the riak service status we will get the output that riak is running.

$ sudo service riak status
pong
riak is running

Verify the Riak Installation

Now it’s time to verify our one node Riak installation. The first method is using the riak-admin command :

$ sudo riak-admin test
Successfully completed 1 read/write cycle to 'riak@127.0.0.1'

The output above showed that we did 1 read/write cycle successfully to our Riak installation.

Another method to verify Riak installation is via a HTTP call to Riak. You can run command below:

$ curl -v http://127.0.0.1:8098/types/default/props

You will get the output like below :

* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8098 (#0)
> GET /types/default/props HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:8098
> Accept: */*
> 
< HTTP/1.1 200 OK
< Vary: Accept-Encoding
* Server MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho) is not blacklisted
< Server: MochiWeb/1.1 WebMachine/1.10.8 (that head fake, tho)
< Date: Mon, 21 Dec 2015 05:45:20 GMT
< Content-Type: application/json
< Content-Length: 447
< 
* Connection #0 to host 127.0.0.1 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,"young_vclock":20}}

Configuring Maximum Open Files

By default each user on ubuntu get max file limit 1024. This is why we get a warning when we start Riak. To remove this warning we can use the two methods below.
First is to configure maximum open files from the security limit. We run riak as user riak. We will configure the user riak to have a soft limit 4096 and a hard limitf of 65536 for opened files.
Open /etc/security/limits.conf. At the end of the file add :

riak soft nofile 4096
riak hard nofile 65536

The next step is to create default config for riak. Create new file /etc/default/riak. Add the line below :

ulimit -n 65536

This file will be loaded automatically by the Riak init script. Now when we restart Riak we will not get any warning

$ sudo service riak restart
 * Restarting riak                                                                                                                           ok

Import data to Riak

We have a working Riak installation. Now let's import sample data to our Riak installation. We will use an erlang script to import sample data. The sample data that we will use is Google historical stock price data. For more information you can read Loading Data and Running Mapreduce Tutorial.

Since we will use an Erlang script let's install erlang first. You can use the command below to install Erlang

$ sudo apt-get -y install erlang

After installing erlang, let's download the sample data.

wget -c https://github.com/basho/basho_docs/raw/master/source/data/goog.csv

The last one is of course to download the load data script to import sample data to our Riak installation.

wget -c https://github.com/basho/basho_docs/raw/master/source/data/load_data.erl

After downloading the erlang script and sample data, let's change permissions for the load-data.erl file with additional execute permission so that we can run this file.

$ chmod +x load_data.erl

Now run this script with the parameter goog.csv to import Google stock-price data.

$ ./load_data.erl goog.csv

You will see some output that the script is importing data to our Riak installation.

Summary

In this tutorial we learned how to install Riak on Ubuntu 14.04. We also learned basic configuration of our Riak installation and importing sample data to Riak. We are not configuring Riak as a cluster yet, this will be a topic for a tutorial in the near future. Until then. have fun with Riak!

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]