DevOps

Redis as data store: Installation

Introduction

Redis is open-source, advanced key-value data store server. It is counted as Nosql database for the key-value store category. It is more than just the cache server. It is more of data structure server as it supports data units as lists, sets, hashes and sorted set and It is very blazing fast in terms of performance. In this first installment on Redis articles series, i will go through installation of same.redis-logo

Installation

Redis officially supports only linux ports and no official port for windows but do exist unofficial port for same, which is basically discouraged for production environment.

Following are steps to be followed for installation

Step-1: Download the archive

You can either download from official page from here or use the wget command from terminal as shown below in following command

$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz

Step-2: Extract the archive file to directory of your choice

$ tar xzf redis-2.6.14.tar.gz /usr/ajduke/apps

Step-3: Building redis

$ cd /redis-2.6.14/src
$ make

This will produce few redis binaries in same directory(src), which includes Redis server and Redis CLI, which are the core server engine and Redis interpreter for accessing and  querying the redis server

Step-4: Run tests for built redis binaries

$ make test

(if this is not running then you need to install latest “tcl” using following, sudo apt-get install tcl)

It basically runs the all commands that redis have to make sure binaries are correctly built.

Step-5: Install binaries to standard bin directory

Now, to make redis binaries little more developer friendly, lets install this in the standard binary directory which is “/usr/bin/” to access using terminal from any directory.

$ sudo  make install

If you wish to install binary somewhere else then you can use following

$ sudo make PREFIX=/path/to/your/dir install

Step-6: Check proper installation

Check for proper installation lets check for version details

check for redis server and check for redis-cli as follows

$ redis-server -v
Redis server v=2.6.14 sha=00000000:0 malloc=jemalloc-3.2.0 bits=64
$ redis-cli -v
redis-cli 2.6.14

Starting Redis Server

Use following for valid usages and help

$ redis-server -h

For starting the redis server, you can use one of following ways

  • If you don’t pass anything as cmd args, it will internally use the defaults, such as running server on port 6379 etc.
$ redis-server
  • You can specify few command line arguments and it will use that
$ redis-server --port 7793
  • Using config file
    $ redis-server /path/to/redis.conf

    This will use the configuration found in mentioned configuration file

    For now, you can use the one under <redis-install-dir>/redis.conf

    $ redis-server /redis.conf

Usually, you should use last one as preferred way to start the server.

Using the Redis CLI

For start using cli, you can use one of following ways

  • Connect local redis instance with default port (6379), after that redis prompt will appear
    $redis-cli
    redis 127.0.0.1:6379>
  • Connect to specific port on local machine
    redis-cli -p
    // in our case
    $ redis-cli -p 5689
    $redis 127.0.0.1:5689>
  • Connect to specific host and port
    $redis-cli -h  -p
     // For e.g.
     $redis-cli -h 192.68.0.116 -p 5263
    $redis 192.168.0.116:5263>

Once we got the redis cli prompt after connection, we can run few commands such as follows

$ redis-cli
redis 127.0.0.1:6379> ping
PONG

redis 127.0.0.1:6379> info server
# Server
redis_version:2.6.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_mode:standalone
os:Linux 3.8.0-27-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.7.3
process_id:2700
run_id:ae48481c646364be1dc500cbbd7e4f9b415d78de
tcp_port:6379
uptime_in_seconds:5698
uptime_in_days:0
hz:10
lru_clock:1343599

redis 127.0.0.1:6379> time
1) "1376585153"
2) "935261"

redis 127.0.0.1:6379>

Install Redis as service

For development purpose, you can start and stop the redis server from terminal but for production servers, you should not do this, instead, you must install service of redis. For this purpose, redis has out of the box support with use of utility script from redis installation.

Note that, the script only works for Ubuntu or any debian system.

Go through following commands. It will ask for few things, such as, port number, log directory, config file location etc. But you can accept the defaults by hitting enter every time

$ cd /utils/
$ sudo ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf

Please select the redis log filename [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]

s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
update-rc.d: warning: /etc/init.d/redis_6379 missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/redis_6379 ...
/etc/rc0.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc1.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc6.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc2.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc3.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc4.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc5.d/S20redis_6379 -> ../init.d/redis_6379
Success!
Starting Redis server...
Installation successful!

Now, you can start and stop service using

$ sudo service <redis_service_name> start
$ sudo service <redis_service_name> stop

In our case,

$ sudo service redis_6379 start
$ sudo service redis_6379 stop

And after every time rebooting the system, it will start running in background.

Thats all for Redis installation.
 

Reference: Redis as data store: Installation from our JCG partner Abhijeet Sutar at the ajduke’s blog blog.

Abhijeet Sutar

Abhijeet (ajduke) is self-taught, self-organized software developer. His current go to language is Java and also he is exploring other languages such as Scala, Ruby.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Redsmin (redis gui)
10 years ago

Great article, I’m sharing this!

Back to top button