How to Install & Configure Redis-Server on Centos/Fedora Server

‘Redis’ is an Open source key-value data store, shared by multiple processes, multiple applications, or multiple Servers. Key values are more complex types like Hashes, Lists, Sets or Sorted Sets.

Let’s have a quick look on the installation steps of “Redis

Here we go…

Step – 1

First of all we need to switch to superuser & install dependencies:

[code language=”html”]
su
yum install make gcc wget tcl
[/code]

Step-2
Download Redis Packages & Unzip. This guide is based on installing Redis 2.8.3:

[code language=”html”]
wget http://download.redis.io/releases/redis-2.8.3.tar.gz
tar xzvf redis-2.8.3.tar.gz
[/code]

Step-3
Compiling and Installing Redis from the source:

[code language=”html”]
cd redis-2.8.3
make
make install
[/code]

Step- 4

Starting Redis server by executing the following command without any argument:

[code language=”html”]
redis-server
[/code]

Step-5

Check if Redis is working. To check, send a PING command using redis-cli. This will return ‘PONG’ if everything is fine.

[code language=”html”]
redis-cli ping
PONG
[/code]

Step-6

Add Redis-server to init script. Create a directory to store your Redis config files & data:

[code language=”html”]
mkdir -p /etc/redis
mkdir -p /var/redis
[/code]

Also we need to create a directory inside “/var/redis” that works as data &  a working directory for this Redis instance.

[code language=”html”]
mkdir /var/redis/redis
[/code]

Step-7

Copy the template configuration file you’ll find in the root directory of Redis distribution into /etc/redis/

[code language=”html”]
cp redis.conf /etc/redis/redis.conf
[/code]

Edit the configuration file, make sure to perform the following changes:

  • Set daemonize to yes (by default it’s set to ‘No’).
  • Set the pidfile to /var/run/redis.pid
  • Set your preferred loglevel
  • Set the logfile to /var/log/redis.log
  • Set the dir to /var/redis/redis
  • Save and exit from the editor

Step-8 
Add the Redis init script.

[code language=”html”]
vi /etc/init.d/redis
[/code]

And paste the following codes to it

[code language=”html”]
#!/bin/sh
#
# chkconfig: 345 20 80
# description: Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker.

# Source function library.
. /etc/init.d/functions

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis/redis.conf"

case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server…"
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping …"
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown …"
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
stop
start
;;
*)
echo "Please use start or stop as first argument"
;;
esac
exit 0
[/code]

Save the file and exit from the editor.

Step-9
Give appropriate permission to the init script

[code language=”html”]
chmod u+x /etc/init.d/redis
[/code]

Step-10
To run the Redis server at startup we need to add it to the chkconfig list.

[code language=”html”]
chkconfig –add redis
chkconfig –level 345 redis on
[/code]

Step-11
Finally we are ready to start the Redis Server.

[code language=”html”]
/etc/init.d/redis start
[/code]

The redis server will start automatically on system boot.

Conclusion:

‘Redis’ also supports datatypes such as Transitions, Publish and Subscribe. ‘Redis’ is considered more powerful than ‘Memcache’. It would be smart to bring ‘Redis’ into practice and put ‘Memcache’ down for a while.

We provide one-stop solution by utilizing Redis server with Rails , PHP applications and deploy in cloud services such as AWS to make sure that the application is fully scalable.

You can also check the compression of Memcached vs Redis, to know more information on which one to pick for Large web apps?

Do you have anything to add here? Share your thoughts with comments.

It’s always pleasure to hear from you and for5 any assistance and support on AWS you can write us at info@andolasoft.com.

How do I check if a file exists in AWS S3 bucket using Rails3

Amazon_S3_Online_Service-123

Introduction

Amazon S3 provides a simple web services interface that can be used to store and retrieve any amount of data, at any time, from anywhere on the web. While uploading a file to S3 we need to check whether the file exists to avoid any data duplication.

Steps to check the presence of a file

Step#1

Add the below in your gem file,

[sourcecode]gem ‘aws-s3′[/sourcecode]

Then run the bundle,

[sourcecode]bundle install[/sourcecode]

Step#2

Modify your model as,

[sourcecode]require ‘aws/s3’

def  is_file_exist?
AWS::S3::Base.establish_connection!( :access_key_id => ‘S3_KEY’, :secret_access_key => ‘S3_SECRET’)
return AWS::S3::S3Object.exists? attachment_id, “<YOUR_BUCKET_NAME>”
end[/sourcecode]

It is preferred to have the s3 credentials on the config folder and use it from the config file.

Step#3

Now modify your controller where you want to check the existence of the file,

[sourcecode]current_user.is_file_exist? #return true if exists[/sourcecode]

Easy method to avoid data redundancy in secured AWS S3.

Read Also: How to use Amazon S3 Bucket with Paperclip to store images in Rails3

I hope you find this useful. If you want to develop application in rails or want to deploy app in AWS cloud, then Andolasoft is the ideal and cost savvy option for you.  Have something to add to this topic? Share it in the comments.

AWS-Elastic Beanstalk VS Custom Environment Solution

Amazon_S3_Online_Service-123 (1)

AWS has a beautiful feature named Elastic Beanstalk to deploy application in AWS cloud with minimal knowledge on environment setup. Currently it supports Ruby, Java, Node.js, python and PHP applications. But the question is, “should we use Elastic Beanstalk for a low/ medium traffic application?

Advantage:

  • The Elastic Beanstalk is a fully automatic feature for application deployment and versioning
  • AWS has pre-setup templates that can be used like LAMP stack, Ruby Stack
  • Helps to provide single management interface to monitor the activity of your environments like EC2, ELB and S3

Disadvantage:

  • Since this does not support micro instance the cost of for Small instance or higher configuration instance to AWS is redundant
  • There are some limitations to customize the ELB after deployment.
  • AWS scales up and down the resources based on metrics. It supports Elastic Beanstalk on a single metric.
  • AutoScaling cannot be configured with CPU parameters and Network traffic.

Finally, it can be said that Elastic beanstalk is the best fit for application environments that require very little customization with heavy traffic. As it doesn’t support Micro instances, so it is advisable to use customizable environments for low traffic applications.

How to use Amazon S3 Bucket with Paperclip to store images in Rails3

Amazon_S3_Online_Service-resized200-150x150

“S3 Bucket” is Amazon Simple Storage Service – a “highly durable and available store” and can be used to reliably store graphical and other applications contents such as media files, static assets and user uploads. It allows you to off-load your entire storage infrastructure. This feature facilitates better scalability, reliability, and speed than just storing files on the file-system.

It is an online storage web service offered by Amazon Web Services and provides storage through web services interfaces (REST, SOAP etc.)

Here is an example on how to use Amazon S3 with paperclip in Ruby on Rails applications.

Step#1

  • In rails 3.x

Install aws-s3 gem by adding in Gemfile

gem 'aws-s3'

And run

Run “bundle install”

Step#2

To get AWS S3 bucket ‘Access Key ID’ and ‘Secret Access Key’ go to the “http://aws.amazon.com/s3”

Create s3.yml file under config directory and enter your Amazon S3 credentials

development:
bucket: bucket-dev-name
access_key_id: xxxxx
secret_access_key: xxxxx
test:
bucket: bucket-test-name
access_key_id: xxxxx
secret_access_key: xxxxx
production:
bucket: bucket-prod-name
access_key_id: xxxxx
secret_access_key: xxxxx

Step#3

Open your model file that would hold the attachment and modify it as follows

###Paperclip
has_attached_file :photo,:styles =>{ :thumb => "100x100", :medium => "200x200", :large => "600x400" },:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",:path => ":attachment/:id/:style.:extension",:bucket => 'yourbucket'

Step#4

In view, to display the image

How to cut down Amazon Web Services (AWS) billing?

Amazon_S3_online_servicesAndolasoft is specialized in providing Cloud Computing services to its customers. Here we have a huge team of skilled personnel to provide monitoring and support services for 24×7 across the world.

As a technology partner with Amazon Web Services, we would like to share some features as well as some useful tips about controlling the AWS billing cost.

What is Cloud Computing?

Integrating computing resources with World Wide Web to provide remote IT Infrastructure facilities is Cloud Computing. It’s an option to replace traditional IT infrastructures with virtual networking for faster job processing and higher productivity at lower costs.

What is AWS?

Amazon is providing similar IT infrastructure services as a web service, popularly known as Amazon Web Services or AWS. Currently it is providing services to millions of businesses in more than 190 countries.
Features that makes AWS unique in public cloud

  • Auto Scaling

Number of Amazon EC2 instances can be scaled dynamically or by user defined schedule to increase or decrease them automatically depending on the demand. You will receive notifications to initiate Auto Scaling actions, or when Auto Scaling completes an action. Auto scaling feature can be used via APIs or Command Line Tools with no additional fees.

  • Amazon Cloud Front and it’s Functionalities

Amazon Cloud Front is a web service to distribute contents to end users at high speed .Here you can store the original version of your files on one or more origin servers and configure them by using URL pattern matches to specify which origin has what contents. You can use distribution’s domain name in your web pages or application so when users request an object using this domain name, they are automatically routed to the nearest location to deliver your contents.

  • AWS Identity and Access Management (IAM)

Manage IAM users and their access- Identity and Access Management (IAM) offers greater security, flexibility, and control when using AWS. IAM enables you to create users in AWS and manage access to AWS services and resources for your users. It also enables you to grant access to users managed outside AWS. You can assign individual security credentials (access keys, password, Authentication devices) or request temporary security credentials to provide users access to AWS services.

Manage IAM roles and their permissions- You can create roles in IAM and manage permissions to grant specific operations to the entities.Manage access for federated users- You can enable identity federation to allow users to access the AWS Management Console, without creating an IAM user for each identity. It is done by requesting temporary security credentials. This temporary security credentials are comprised of short lived access keys and session tokens associated with them. Users can use the access keys the same way as before, but they also have to pass the token . They can further be restricted by specifying explicit permissions while creating them. Any number of temporary security credentials can be issued.

  • IAM provides the following access controls:

Fine-grained access control to your AWS resources: IAM enables you to add specific conditions to control how a user can use AWS, such as time of day, their IP address, by using SSL, or authenticating with a Multi-Factor Authenticationdevice.Identity federation between your enterprise and AWS services: IAM can be used to grant employees, and applications access to AWS Management Console and AWS service APIs, using existing identity systems.

Mobile and browser-based applications: Mobile and browser-based applications can also be enabled to access specific AWS resources using temporary security credentials for a configurable period of time.

Tips to cut down AWS Billing:

  • Use AWS reserved instance for long running projects and spot instances for short term projects.
  • Use AWS private IP for data transfer between instances.
  • Use AWS Rout53 DNS to reduce Elastic IP usages.
  • Use Linux based Instances.
  • AWS recently lunched Glacier which offers $0.01 per GB / month only. Use Glacier for data storage instead of S3 to reduce the price of S3.

Planning anything on AWS? Talk to our Experts