logo

Installing & Configuring Redis in CentOS 6 - From Source

I’ve previously posted about the installation of Redis from the YUM repositories. Recently we have had the need to install to a specific version, which requires that it be compiled from source (unless you are lucky enough to have exactly the correct version in the YUM repositories).

In this post, we will install pre-requisite compilation tools, download & compile version 2.6.16, and install as a service within CentOS.

Pre-Requisites

We need to install make, gcc & cc in order to compile the downloaded source. If these have already been installed, then this command won’t hurt, it’ll just be ignored.

yum -y install make gcc cc

Download, Un-pack, Make Redis & Copy to /usr/local/bin

cd /home
curl  http://download.redis.io/releases/redis-2.6.16.tar.gz > redis-2.6.16.tar.gz
tar zxvf redis-2.6.16.tar.gz
cd redis-2.6.16
make
cp src/redis-server /usr/local/bin
cp src/redis-cli /usr/local/bin

To test the installation of Redis, you can now use:

redis-cli ping

If the result is ‘PONG’, then installation has been successful.

Installing Redis as a Service

mkdir -p /etc/redis
mkdir -p /var/redis
cd /home/redis-2.6.16/
cp utils/redis_init_script /etc/init.d/redis

You will need to modify the contents of the Redis init script (nano /etc/init.d/redis), so that it is compatible with chkconfig under CentOS. I’ve taken the liberty of creating this file for you. This can be downloaded from here. In this file, I’ve assumed that the config file that we’re going to use will be at /etc/redis/redis.conf (the next steps will put this in-place). If you want to use the file that I have created, instead of the last line in the previous set of commands, do this:

curl -L  https://bitbucket.org/ptylr/public-stuff/raw/41d5c8e87ce6adb34aa16cd571c3f04fb4d5e7ac/etc/init.d/redis > /etc/init.d/redis

Now we need to copy and amend the redis.conf file from the source into the correct location (/etc/redis/redis.conf):

cd /home/redis-2.6.16/
cp redis.conf /etc/redis/redis.conf

The redis.conf file must be amended (nano /etc/redis/redis.conf), as follows:

  • Set daemonize to yes (by default it is no);
  • Check that the pidfile is /var/run/redis.pid;
  • Set the logfile to /var/log/redis.log;
  • Set the dir to /var/redis/.

Finally, we need to add the service to chkconfig, set it to auto-start, and actually start the service:

chkconfig --add redis
chkconfig redis on
service redis start

Again, test the installation of Redis:

redis-cli ping

If the result is ‘PONG’, then installation has been successful.