bind 127.0.0.1 (don't do this if you need to access redis from another computer)

loglevel notice

logfile /var/log/redis.log

dir /var/lib/redis

wget https://gist.github.com/paulrosania/257849 (an init script for Redis en Centos someone kindly wrote.) I haven't tested this one, the one I originally used has diappeared but SkiOne left this link in the comments section.

vi redis-server:

redis="/usr/local/bin/redis-server"

mv redis-server /etc/init.d

chmod 755 /etc/init.d/redis-server

chkconfig --add redis-server

chkconfig --level 345 redis-server on

vi /etc/sysctl.conf (see below):

vm.overcommit_memory = 1

sysctl vm.overcommit_memory=1 (see below)

service redis-server start

Finished! Run redis-cli to connect, set a key, save, then check a dump.rdb file appears in /var/lib/redis.

But what are those scary kernel-configuring commands you're asking me to make with "vm.overcommit_memory"?

You don't have to do it, but it's recommended and explained in the Redis FAQ under "Background saving is failing with a fork() error under Linux even if I've a lot of free RAM!". I found out about it because if you don't do it, after startup Redis writes a warning about it into the log file. Here's my summary of the situation: If you're confident that there will always be as much memory as Redis is currently using free in your system, you don't need it. If not, you should enable it because writes to disk could fail. Unless you don't mind some of the disk writes failing, I suppose.

Basically Redis forks in order to write to disk, since forking means duplicating the process, logically you need at least as much free memory available as Redis is currently using, in order to be taken by the forked process. The trick comes with the fact that with optimisations in modern OSs, this statement is no longer true and the forked process will actually just share the same memory as the original process as long as neither changes it. So it could be that you need no additional memory at all! Setting overcommit_memory = 1 allows us to take advantage of this and tells the kernel to approve the memory allocation even if there is not sufficient memory technically available. Redhat says:

Use these previous two parameters with caution. Enabling overcommit_memory can create significant performance gains at little cost but only if your applications are suited to its use. If your applications use all of the memory they allocate, memory overcommit can lead to short performance gains followed by long latencies as your applications are swapped out to disk frequently when they must compete for oversubscribed RAM.

Since Redis is evidently suited to its use, I reckon it should be OK. But have a think about what else is running on the system.

Lastly you can alternatively set it to 2 which causes it to work in combination with an "overcommit_ratio" setting, allowing overcommits up to a percentage above physical memory. Note that in one point the above linked Redhat article mixes up the settings 1 and 2 I believe - can be confirmed here.

Thanks for the walkthrough. One problem is that it is not running it as a service in the background. With your command, as soon as I ctrl+c to get my prompt back the redis server stops. What options do I have to continue to run even after I logout?

Just a small correction for step 9: the current command just downloads the HTML for the gist to the file '257849'. You want to download the raw gist and save that as 'redis-server'. So the command for step 9 should be:wget https://gist.github.com/paulrosania/257849/raw -O redis-server