How to install Redis as a service on Centos 6.0
Update: Please checkout my new and improved (incidentally how can something be new and improved? Either it's new, or it's improved, in which case it's not new) article Install Redis as Service on Centos 6, which is a better guide.
There are a few pages explaining how to install/daemonise redis as a service with Centos specific stuff and some sed magic. This might work, but personally I don't like running too many commands that I don't understand and actually Redis has a nice little instruction manual explaining how to set it up as a service in Debian. It doesn't quite work for Centos. Here's how to stick as close as possible to the standard Redis doco, making the minimal adjustments to make it work with Centos:
Follow the redis Quickstart Guide, in particular the part underneath the rather artistic title "Installing Redis more properly". You will make it all the way to the
update-rc.d command, which doesn't work in Centos. No problem, edit
/etc/init.d/redis_6379 and add the following at the top:
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis
I think the chkconfig line is the really important one.
Note that personally I just called it /etc/init.d/redis, but you can do as you like.
chkconfig --add redis_6379 (or
chkconfig --add redis in my case), and everything is done. You can now run
service redis_6379 start.
Alternantively this file on Git probably gives you a more complete Centos-like init script, but I haven't tried it, I just stuck to my modified distributed version as described.
Another thing popped up in the logs for me: when you start the server it says:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
So, that's what I did and the message went away. I can't really explain it better than the message itself does, you just
vm.overcommit_memory = 1 to the end of
/etc/sysctl.conf. To be honest I'm not entirely sure what that does, but I'm in the dev phase on a dev machine right now so I'm happy. If you're in prod you might like to look up the meaning of that command. Enjoy!