Question

Multiple Redis instances on Ubuntu 16.04?

I’ve read the Redis install guide for Ubuntu 16.04: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-redis-on-ubuntu-16-04

What about configuring more than one instance of Redis so each of my applications can use a separate instance? They would be on different ports and it makes sense they be owned by the user who owns the application using them.

Any guides out there?

Note: I actually installed Redis using apt-get redis-server, not manually as in the above guide, but that shouldn’t make much of a difference except for some file locations.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Depending on the the use case, I would usually recommend a single instance per host. That said, it is certainly possible to run multiple instances of Redis on a single server. The key is that both the configuration file and the startup script will need to be duplicated and modified.

When installed with apt-get on Ubuntu 16.04, the file /etc/redis/redis.conf will contain the the config information for Redis. If you want to run multiple instances, you will need to create a copy of this file for each one. Then you must make a number of changes to each.

Bellow, I’ve included only the parts of the file which need to be changed. Each file, and each Redis instance, should have it’s own pid file, log file, data directory, and port.

# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
pidfile /var/run/redis/redis-server.pid

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# [ ... ]

logfile /var/log/redis/redis-server.log

# [ ... ]
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

So you might create a new file named /etc/redis/redis_6380.conf with:

# [ ... ]
pidfile /var/run/redis/redis-server_6380.pid
port 6380
logfile /var/log/redis/redis-server_6380.log
dir /var/lib/redis_6380
# [ ... ]

When installed with apt-get on Ubuntu 16.04, systemd is used to manage the Redis process. The systemd unit file is located at /etc/systemd/system/redis.service Like the configuration file, it will need to be duplicated for each instance, and each new file will need to be updated to point to its own configuration file, pid file, and data directories. For example, the lines:

ExecStart=/usr/bin/redis-server /etc/redis/redis.conf
PIDFile=/var/run/redis/redis-server.pid

would need to be updated to:

# [ ... ]
ExecStart=/usr/bin/redis-server /etc/redis/redis_6380.conf
PIDFile=/var/run/redis/redis-server_6380.pid
# [ ... ]

I would look into using a configuration management tool like Ansible to help manage all of this. It would allow you to create reusable templates for these files.