Running multiple instance of Redis on Centos
Asked Answered
A

2

18

I want to run multiple instance of Redis on Centos 7. Can anyone point me to proper link or post steps here.

I googled for the information but I didn't find any relevant information.

Ashok answered 6/9, 2016 at 15:38 Comment(2)
Possible duplicate of How can I run redis on a single server on different ports?Poach
my question is not duplicateAshok
S
43

You can run multiple instances of Redis using different ports on a single machine. If this what concerns you then you can follow the below steps.

By installing the first Redis instance, it listens on localhost:6379 by default.

For Second 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. To avoid runtime conflicts, 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/redis.conf

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

Edit following settings to avoid conflicts

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

Create service file

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

Modify the settings under Service section

[Service]
ExecStart=/usr/bin/redis-server /etc/redis/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

By Following this you can start two Redis servers. If you want more repeat the steps again.

Scarcity answered 7/9, 2016 at 7:53 Comment(7)
Thanks a lot this helpsAshok
I have one more question. In section "Edit following settings to avoid conflicts" last line "add startup script". What does that mean?Ashok
When i run "service redis-6379 start" I get following message Redirecting to /bin/systemctl start redis-6380.service ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to manage system services or units. Authenticating as: Ashish K (ashish) Password: XXX But redis server process is not thereAshok
Edit following settings to avoid conflicts means you need to set the separate log file,pid file ,datadir to new redis instanceScarcity
Sorry for the inconvenience Please don't consider 'add startup script' I wrongly mentioned.Scarcity
For your second question: You need to change all tings in redis2.conf file.Need to mention separate files to each instanceScarcity
Note that to start Redis with systemd, I would use systemctl start redis and not the sysv command as shown.Featherveined
S
2

If I set to --daemonize no, Redis will crash when data insert.

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

Should change to

ExecStart=/usr/bin/redis-server /etc/redis2.conf --supervised systemd

My Redis is 5.0.7.

FYI.

Saveloy answered 20/12, 2019 at 3:45 Comment(2)
how does the "--daemonize no" change the equation?Karyotype
@Karyotype You can follow the first comment step by step, and vi /usr/lib/systemd/system/redis2.service to chnage the equation.Saveloy

© 2022 - 2024 — McMap. All rights reserved.