Monday, April 25, 2016

Run multiple Redis instances on CentOS7

Install 1st Redis instance

By installing the first Redis instance, you can use the configuration as template for your 2nd one.

yum install redis
service redis start

This redis instance listens on localhost:6379 by default.

Install 2nd Redis instance

create a new working directory

The default redis instance uses /var/lib/redis as its working directory, dumped memory content is saved under this directory with name dump.rdb if you did not change it manually.

to avoid runtime conflict, we need to create a new working directory

mkdir -p /var/lib/redis2/
chown redis /var/lib/redis2/
chgrp redis /var/lib/redis2/

generate configurations

Create a new configuration file by copying /etc/redis.conf

cp /etc/redis.conf /etc/redis2.conf

Edit following settings to avoid conflicts

logfile "/var/log/redis/redis2.log"
dir "/var/lib/redis2"
pidfile "/var/run/redis/"
port 6380

add startup script

Create service file

cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis2.service

Modify the settings under Service section

ExecStart=/usr/bin/redis-server /etc/redis2.conf --daemonize no
ExecStop=/usr/bin/redis-shutdown redis2

set to start with boot

systemctl enable redis2

start 2nd redis

service redis2 start

check status

lsof -i:6379
lsof -i:6380

No comments:

Post a Comment