Here are simple steps to get Redis 2.2.14 running on CentOS 5/6 (local desktop running CentOS 5.4 and EC2 AMI running CentOS 6.1) using an init script.
The setup is intended to be used on developer desktop/laptop rather than production infrastructure.
As ever, first download and unzip Redis from here.
$> cd /tmp
$> wget http://redis.googlecode.com/files/redis-2.2.14.tar.gz
$> tar xvfz redis-2.2.14.tar.gz
$> cd redis-2.2.14
$> make
$> sudo make install
Your Redis binaries should now be located in /usr/local/bin.
To get an init script and Redis config working cleanly with this setup, download my init and config files from my development/redis repo.
My init script is pretty standard. However my redis.conf sets Redis up with 1Gb of virtual memory and 20Gb of swap space – intended for general development purposes.
$> wget http://www.zorranlabs.com/development/redis/redis.conf
$> wget http://www.zorranlabs.com/development/redis/redis-server
Runner “redis-server” is using start-stop-daemon from Debian distribution, so it needs to be compiled on CentOS. You can take it from my repo. Make sure you have gcc-c++, otherwise, you might get the following error: “exec: g++: not found”
$> sudo yum install gcc gcc-c++ m4 make automake libtool gettext openssl-devel
$> wget http://www.zorranlabs.com/development/start-stop-daemon/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
$> tar xvfz apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
$> cd apps/sys-utils/start-stop-daemon-IR1_9_18-2/
$> gcc start-stop-daemon.c -o start-stop-daemon
$> cp start-stop-daemon /usr/sbin/
There is a small difference between start-stop-daemon versions, so redis-server script should be update:
Please replace the following line
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
to this one
if start-stop-daemon --start --quiet --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
Update redis.conf to change the following line
vm-enabled yes
to the following line
vm-enabled no
Otherwise, you will get the following error, trying to start redis-server:
“Redis Virtual Memory is going to be deprecated soon,
we think you should NOT use it, but use Redis only if
your data is suitable for an in-memory database.
If you *really* want VM add this in the config file:
really-use-vm yes
Copy init script, and redis.conf it their proper locations:
$> sudo cp redis-server /etc/init.d/redis-server
$> sudo chmod +x /etc/init.d/redis-server
$> sudo cp redis.conf /etc/redis.conf
Before you can fire up the Redis server for the first time, you’ll need add a redis user and prep a data and logging folder.
$> sudo /usr/sbin/useradd redis
$> sudo mkdir -p /var/lib/redis
$> sudo mkdir -p /var/log/redis
$> sudo chown redis.redis /var/lib/redis
$> sudo chown redis.redis /var/log/redis
Also, you need to activate your Redis services init script by adding it to your system’s run-level configuration. That way the service will startup during the boot sequence and stop nicely during the OS’ shutdown procedure.
## initial check, should show nothing
$> sudo /sbin/chkconfig --list | grep redis
$> sudo /sbin/chkconfig --add redis-server
## confirmation, should retruen something like that:
## redis-server 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$> sudo /sbin/chkconfig --list | grep redis
#enable service, specifies run levels 3 and 5:
$> sudo /sbin/chkconfig --level 35 redis-server on
You’re now ready to launch Redis server with and should see that it is started:
$> sudo /etc/init.d/redis-server start
Starting redis-server: redis-server
Netstat should tell you that you listen on redis port, 6379
$> netstat -an | grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN
Do not forget to “open” port 6379 on your firewall to get it accessible outside of the host
Good luck and thanks authors of the following posts for the guides and ideas:
http://www.denofubiquity.com/nosql/412/
http://www.cyberciti.biz/faq/rhel5-update-rcd-command/
https://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=24207&forum=40
http://chast.in/start-stop-daemon-on-centos.html