I installed Redis on Ubuntu 16.04. I couldn't find Redis directory nor redis.conf file (tried with: sudo find redis.conf).
My application depends on some data pulled from third party APIs. I store the (processed) data in Redis. My problem is, after reboot I lose the data. I guess I need to specify in config file that the data should be persisted on reboot, but I couldn't find the config file. Do I need to create the config file? Are there some templates to use? My goal is just to have the data persisted after reboot.
Thank you!
Use dpkg -L redis-server | grep redis.conf to find config file path. It should be located at /etc/redis/redis.conf as I know.
Redis has 2 methods for persistense: Snapshotting and Append-only file:
Snapshotting will be enabled by adding (or uncommenting) save X Y in config file. It means Redis will automatically dump the dataset to disk every X seconds if at least Y keys changed. There could be more than one save options in config file.
Append-only file will be enabled by adding (or uncommenting) appendonly yes in config file
you should turn on the rdb or aof.
see https://redis.io/topics/persistence
Add this to the config file.
appendonly yes
This will append data as you store new data. This enables durability.
Related
I am quite familiar with redis conf files, I also aware that by default redis stores dump.rdb files under /var/lib/redis
I transitioned to handle app where previous team installed redis in /opt/app/, also I see dump.rdb files present in /var/lib/redis but it is not storing anything and date stamp is 2 years old. Now I found that redis storing dump.rdb in different location but I am not able to find that location specified in redis.conf file, Is there any other file where dump.rdb location could be specified that tells redis to store dump.rdb to specific location?
You can use config get dir and config get dbfilename to get the path and filename of current RDB file. You can also use config set dir xxx and config set dbfilename xxx to dynamically change the path and filename.
Also you can use the info server command to get the path of config file your Redis instance is loading (check the config_file item)
I have configured my redis cluster with the following config:
appendonly no
save ""
But I found out that my redis is taking a back up and has taken a backup recently. My use case doesn't require any rdb save to be done. Am I missing some thing?
For disable all backups in redis go to redis.conf file do the following:
Comment all save directives, by default there are three of them.
save 900 1
save 300 10
save 60 10000
Disable appendonly (set appendonly to no)
I need to load a dump.rdb file to a redis cluster instance. How to do it?
While I am keeping in data directory and trying to start the instance alone (say 11211) is flushing my rdb and new rdb file is written. Even by turning the appendonly to no.
Got it.
Stop all redis instance (because redis overwrites the current rdb file when it exits).
do the below steps in master instance.
Copy your backup rdb file to the redis working directory (this is the dir option in your redis config). Also make sure your backup filename matches the dbfilename config option.
Change the redis config appendonly flag to no (otherwise redis will ignore your rdb file when it starts).
Start redis.
Run redis-cli BGREWRITEAOF to create a new appendonly file.
Restore redis config appendonly flag to yes.
After running fine for a while, I am getting write error on my redis instance:
(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.
In the log I see:
9948:C 22 Mar 20:49:32.241 # Failed opening the RDB file root (in server root dir /var/spool/cron) for saving: Read-only file system
However, my redis config file is /etc/redis/redis.conf as confirmed by:
redis-cli -p 6379 info | grep 'config_file'
config_file:/etc/redis/redis.conf
And there I have:
dir /mnt/data/redis
And indeed, there is a snapshot there.
But despite the above, redis now thinks my data directory is
redis-cli -p 6379 CONFIG GET dir
1) "dir"
2) "/var/spool/cron"
Corresponding to the error I was getting as quoted above.
Can anyone tell me why/how my data directory is changing after redis starts, such that it is no longer what is specified in the config file?
So the answer is that the redis server was hacked and the configuration changed, which is very easy to do as it turns out. (I should point out that I had no reason to think it wasn't easy to do. I just assumed security by obscurity was sufficient in this case--wrong. No matter, this was just a playground not any sort of production server).
So don't open your redis port to the world. Use security groups if on AWS to limit access to machines that need it, or use AUTH (which is still not awesome because then all clients need to know the single password which also apparently gets sent in the clear), or have some middleware controlling access.
Hacking redis is easy to do, can compromise your data, and even enable unauthorized SSH access to your server. And that's why you shouldn't highline.
I have enabled both aof and rdb in my redis server. Redis will save the two files appendonly.aof and dump.rdb on the disk. How can I use environment variables to control the path of these two files?
AFAIK, Redis DOES NOT read these configuration from environment variables.
You CAN config these paths in the redis.conf file, or use the CONFIG SET command to dynamically set these paths.
The corresponding configuration keys are: dir, dbfilename and appendfilename.
NOTE: it seems that, by now, appendfilename is NOT supported to be dynamically changed with CONFIG SET command.