Tuesday, 23 September 2014

Working with Object Stores: RiakCS

Working with Object Stores: Riak-CS


We have all heard of the amazing power and flexibility of Amazon's S3 (Simple Storage as a Service) offering.. a simple Object Storage that can be used to virtually to store any content you have up on Amazon's Cloud.



Lucky for us, we have similar products and solutions that can provide us the same S3-like feel on our own in-house infrastructure. Enter Riak-CS!!



I have been working on Riak-CS for quite a short while now and must say, it's really something we all IT admins must try out sometime in our lives... its a unique open source solution that can be used virtually in a same manner as S3, providing a list of features and functions that can be leveraged with real ease.



In this set of tutorials, Ill be showing how to setup Riak-CS on a single Linux box and then work with it using s3cmd tools. 



Before we begin, here's a quick intro of the services that we will be working with... first up:



Riak

"Riak is a distributed NoSQL key-value data store that offers extremely high availability, fault tolerance, operational simplicity and scalability. Written in Erlang, Riak has fault tolerance data replication and automatic data distribution across the cluster for performance and resilience"


Riak CS


"Riak CS (Cloud Storage) is simple, open source storage software built on top of Riak. It can be used to build public or private clouds, or as reliable storage to power applications and services. It features:

--Highly available, fault-tolerant storage
--Large object support and multipart upload
--S3-compatible API and authentication
--Multi-tenancy and per-user reporting
--Simple operational model for adding capacity
--Robust stats for monitoring and metrics
--OpenStack integration with Object Storage API and Keystone authentication service"


Stanchion

"Manages requests involving globally unique system entities, such as 
buckets and users sent to a Riak instance, for example, to create users or to create or delete buckets"


Setting up Riak-CS is fairly simple and straightforward. Here, Ill be using a CentOS 6.5 64 Bit machine with a hard disk of 50 GB. I have setup the hard disk as a LVM, so that in case the disk runs short of capacirty, I can easily increase its size by adding a new hard drive. To know more about LVM, check out my previous tutorial on the same.



NOTE: You can refer to the Riak Docs for a better understanding of what hardware and OS to use for a Production setup.



Prerequisites

These are optional requirements, but never the less, important ones. Make sure the Riak-CS server has a static set IP and a FQDN hostname as shown below:


NOTE: You can set the FQDN of your server by editing the /etc/hosts file and adding the FQDN there.



# ifconfig

# hostname



Also, make sure you have enough of Hard Drive space available for testing and working. Here, I am using a 50 gig drive and I have set it up as a LVM on my CentOS system

# df -h




Installation
Riak-CS can be installed either by using the source or by the RPMs. Here, I'm using the RPMs cause they are really easy to get going with.

First things first, add the Basho repo using the following command:

# sudo yum install http://yum.basho.com/gpg/basho-release-6-1.noarch.rpm



Once done, install Riak, Riak-CS and Stanchion as shown below:

# sudo yum install riak



# sudo yum install riak-cs



# sudo yum install stanchion




Configurations
Once the packages are installed, there are a few simple steps required to configure Riak-CS out. You can follow the in-depth, step-by-step official guide here as well 

Firstly, we need to increase the OS's open files limit. there are two ways to do this:

1) A temporary setting, which is valid ONLY for the current session:
# ulimit -n 65536

2) A permanent setting, done in the limits.conf file:

# vi /etc/security/limits.conf
root soft nofile 65536 
root hard nofile 65536 
riak soft nofile 65536 
riak hard nofile 65536
Save the file and exit the editor.

Next, we need to modify the following config files and add few commands to them:

# vi /etc/riak/app.config

Add this line to the riak_core section, which starts off like this:  {riak_core, [

{default_bucket_props, [{allow_mult, true}]},



Next, in the same config file, find the following text and replace that with the contenet as shown below:

Change this -- 
{storage_backend, riak_kv_bitcask_backend}

To this --
{add_paths, ["/usr/lib/riak-cs/lib/riak_cs-1.5.0/ebin"]},
{storage_backend, riak_cs_kv_multi_backend},
{multi_backend_prefix_list, [{<<"0b:">>, be_blocks}]},
{multi_backend_default, be_default},
{multi_backend, [
    {be_default, riak_kv_eleveldb_backend, [
        {max_open_files, 50},
        {data_root, "/var/lib/riak/leveldb"}
    ]},
    {be_blocks, riak_kv_bitcask_backend, [
        {data_root, "/var/lib/riak/bitcask"}
    ]}

]},



Next, in the same config file, swap the http and https IP addresses with localhost (127.0.0.1) to your Riak Server's IP address (192.168.50.150)

{http, [ {"192.168.50.150", 8098 } ]}
{https, [ {"192.168.50.150", 8098 } ]}

Save the file and exit the editor.



Next, edit the riak-cs config file and change the IP addresses there as well

# vi /etc/riak-cs/app.config

Change the following lines only, replacing the localhost IP with your Riak Server IP:

{cs_ip, "192.168.50.150"}
{riak_ip, "192.168.50.150"}

{stanchion_ip, "192.168.50.150"}

Save and exit the editor.



Follow the same steps for the stanchion config file  in /etc/stanchion/app.config as well:

# vi /etc/stanchion/app.config 

Change the following lines only, replacing the localhost IP with your Riak Server IP:

{stanchion_ip, "192.168.50.150"}

{riak_ip, "192.168.50.150"}

Save and exit the editor.



Next, edit the following files and change the -name parameter values as shown below:

# vi /etc/riak/vm.args

-name riak@192.168.50.150



# vi /etc/riak-cs/vm.args

-name riak-cs@192.168.50.150



# vi /etc/stanchion/vm.args

-name stanchion@192.168.50.150



All done, we are now ready to start our services. 

NOTE: Start them in the correct order as shown below:

# sudo riak start
# sudo stanchion start
# sudo riak-cs start



You can test whether your Riak-CS service is running properly by executing the riak-cs ping command. 

# riak-cs ping

You can check riak and stanchion services are functioning correctly or not as well using this same command.




Creating an Admin user
Let's face it, nothing works without an admin user!! 

To get started, first edit the /etc/riak-cs/app.config and find the anonymous_user_creation parameter as shown. This is set to false by default. Change it and set it true.

# vi /etc/riak-cs/app.config

{anonymous_user_creation, true},

NOTE: This is a temporary setting that we are changing so that we can create a  user. Once the user is created, make sure you set the parameter back to false.



Restart the riak-cs service so that the changes take effect

# riak-cs restart



Next, ruun the following command. This will create a new user named "admin" with an email "admin@cloud.com". it will also generate two VERY IMPORTANT KEYS: an Access Key and a Secret Key 

# curl -XPOST http://localhost:8080/riak-cs/user \
  -H 'Content-Type: application/json' \

  -d '{"email":"admin@cloud.com", "name":"admin"}'

The user's access key and secret key are returned in the key_id and key_secret fields respectively. Take note of these keys as they will be required in the testing step.


In this case, those keys are:
Access key: XNTMDGWOV2VI0EHMMDI6
Secret key: Rvny0twbBMc53pABDvOjY2lxp_Ifv0Yrq4gbTw==


Next, add these keys in BOTH, the riak-cs and stanchion config files as shown:

# vi /etc/riak-cs/app.config

Find the admin_ket and admin_secret parameters and provide the admin_key and admin_secret to them respectively:

{admin_key, "XNTMDGWOV2VI0EHMMDI6"}

{admin_secret, "Rvny0twbBMc53pABDvOjY2lxp_Ifv0Yrq4gbTw=="}



Do the same for the stanchion config file as well located at /etc/stanchion/app.config

Once added, restart both riak-cs and stanchion for the changes to take effect.. and voila.. your Object Store is now ready for use!!!

# sudo stanchion restart

# sudo riak-cs restart




Stay tuned for the next part of this series where we install and configure S3CMD Tools for accessing the Object Store!!




No comments :

Post a Comment