Download Redis from http://redis.io/download:
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
Extract it and compile with:
tar -xzvf redis-3.0.0.tar.gz
cd redis-3.0.0
make
Install binaries:
make install
This directory will work as data and working directory for your Redis instance:
mkdir -p /var/redis/6379
Create a directory where to store your Redis config files:
mkdir /etc/redis
Copy the template configuration file you'll find in the root directory of the Redis distribution into /etc/redis/
using the port number as name, for instance:
cp redis.conf /etc/redis/6379.conf
Edit this file, making sure to perform the following changes:
vi /etc/redis/6379.conf
yes
(by default it is set to no)./var/run/redis_6379.pid
(modify the port if needed).6379
./var/log/redis_6379.log
/var/redis/6379
(very important step!)# bind 127.0.0.1
(very important step for security reasons! With such settings redis will be accessible only from localhost. It will reject connections from outside network.)Copy the init script that you'll find in the Redis distribution under the utils
directory into /etc/init.d
. We suggest calling it with the name of the port where you are running this instance of Redis. For example:
cp utils/redis_init_script /etc/init.d/redis_6379
Edit the init script.
vi /etc/init.d/redis_6379
Add the following lines at the top of init script (below line #!/bin/sh):
#!/bin/sh
#
# 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
Make sure to modify REDIS_PORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.
Finally add the new Redis init script to all the default runlevels using the following command:
chkconfig --add redis_6379
chkconfig redis_6379 on
You are done! Now you can try running your instance with:
/etc/init.d/redis_6379 start
Make sure that everything is working as expected:
redis-cli ping
.redis-cli save
and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb).