Installing Redis on CentOS 5.6

Redis is a high performance key-value store that can be easily integrated with a variety of applications. Redis can handle many inserts (sets) by keeping newly added values in memory and writing them to disk over time. To install Redis on CentOS 5.6, run the following commands as root.


sudo su
yum install make gcc wget telnet
tar -xf redis-2.2.12.tar.gz
cd redis-2.2.12
make && make install

We're going to change the default redis.conf file to daemonize it, change the location of the database, change the log notices to a production acceptable level, and change the logfile location.

mkdir /etc/redis /var/lib/redis
sed -e "s/^daemonize no$/daemonize yes/" -e "s/^dir \.\//dir \/var\/lib\/redis\//" -e "s/^loglevel debug$/loglevel notice/" -e "s/^logfile stdout$/logfile \/var\/log\/redis.log/" redis.conf > /etc/redis/redis.conf

To make management easy, we're going to use an init script that I found here on github. The install location on this script doesn't match where the /usr/local/bin/redis-server location we're using, so I'm using sed to update it.

sed -i "s/usr\/local\/sbin\/redis/usr\/local\/bin\/redis/" redis-server
chmod u+x redis-server
mv redis-server /etc/init.d
/sbin/chkconfig --add redis-server
/sbin/chkconfig --level 345 redis-server on
/sbin/service redis-server start


To test your installation, run the following commands:

telnet 6379
set attitude:today "happy"
get attitude:today

Additional Settings

There are additional settings that you may want to take a look at in your redis.conf file located at /etc/redis/redis.conf.

  • bind uncommenting this line will lock down redis to connections from your localhost. Do
  • timeout 300: this is how long in seconds it takes to close a connection for an idle client. 10 should be more than sufficient for most web uses unless you're running time consuming scripts.
  • appendonly: turning on appendonly mode stops redis from writing to disk asynchronously. Use this mode if data loss in your application is unacceptable. The penalty is decreased write performance.