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.