How to install Redis Server and also restore the Databases of Redis server from RDB file.

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster

tar xvzf redis-stable.tar.gz
cd redis-stable
Make test
Make install

p/s: after make install it will normally gone into /usr/local/sbin/

Starting Redis


Check if Redis is working

$ redis-cli ping


$ redis-cli
redis> ping
redis> set mykey somevalue
redis> get mykey

Securing Redis
Just to make sure Redis Server listening to loopback address, do not expose redis server to INTERNET!!!!!

Installing Redis more properly

sudo mkdir /etc/redis
sudo mkdir /var/redis

sudo cp utils/redis_init_script /etc/init.d/redis_6379

sudo vi /etc/init.d/redis_6379

sudo cp redis.conf /etc/redis/6379.conf

sudo mkdir /var/redis/6379

Edit the configuration file, making sure to perform the following changes:
Set daemonize to yes (by default it is set to no).
Set the pidfile to /var/run/ (modify the port if needed).
Change the port accordingly. In our example it is not needed as the default port is already 6379.
Set your preferred loglevel.
Set the logfile to /var/log/redis_6379.log
Set the dir to /var/redis/6379 (very important step!)
Finally add the new Redis init script to all the default runlevels using the following command:
sudo update-rc.d redis_6379 defaults

You are done! Now you can try running your instance with:

sudo /etc/init.d/redis_6379 start

Make sure that everything is working as expected:
Try pinging your instance with redis-cli.
Do a test save with redis-cli save and check that the dump file is correctly stored into /var/redis/6379/ (you should find a file called dump.rdb).
Check that your Redis instance is correctly logging in the log file.
If it’s a new machine where you can try it without problems make sure that after a reboot everything is still working.

Restore.rpd file rom old redis.

There is nothing specific to do. Just install the redis server on the new machine, and edit the configuration file. You just need to change the following parameters to point to the location of the dump file you have just copied.
# The filename where to dump the DB dbfilename mydump.rdb
# The working directory.
# # The DB will be written inside this directory, with the filename specified # above using the ‘dbfilename’ configuration directive.
# # Also the Append Only File will be created inside this directory.
# # Note that you must specify a directory here, not a file name. dir /data/mydirectory/
Finally, the redis server can be started in the normal way.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *