Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud ServerRiak (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 :
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.
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
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}}
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
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.
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
Related Posts
Comments