Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save akhdaniel/04e4bb2df76ef534b0cb982c1dc6225b to your computer and use it in GitHub Desktop.
Save akhdaniel/04e4bb2df76ef534b0cb982c1dc6225b to your computer and use it in GitHub Desktop.
run multiple redis instances on the same server for centos

Run Multiple Instances of Redis on Centos 7

create a new redis .conf file

$ cp /etc/redis.conf /etc/redis-xxx.conf
$ sudo chown redis:redis /etc/redis-xxx.conf

edit /etc/redis-xxx.conf, illustrated as below

...
#modify pidfile
#pidfile /var/run/redis/redis.pid
pidfile /var/run/redis/redis-xxx.pid

...
#dir /var/lib/redis/
dir /var/lib/redis-xxx/

...
#modify port
#port 6379
port 6380

...
#modify logfile
#logfile /var/log/redis/redis.log
logfile /var/log/redis/redis-xxx.log

...
#modify vm-swap-file IF ANY
#vm-swap-file /tmp/redis.swap
vm-swap-file /tmp/redis-xxx.swap
...

make dir /var/lib/redis-xxx

$ mkdir -p /var/lib/redis-xxx
$ sudo chown redis:redis /var/lib/redis-xxx

copy init script

$ cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis-xxx.service

edit the new init script

...

#ExecStart=/usr/bin/redis-server /etc/redis.conf --daemonize no
#ExecStop=/usr/libexec/redis-shutdown
ExecStart=/usr/bin/redis-server /etc/redis-xxx.conf --daemonize no
ExecStop=/usr/libexec/redis-xxx-shutdown


...

#RuntimeDirectory=redis
RuntimeDirectory=redis-xxx

...

copy shutdown script

$ cp /usr/libexec/redis-shutdown /usr/libexec/redis-xxx-shutdown

edit the shutdown script

...
#   SERVICE_NAME=redis
   SERVICE_NAME=redis-6380

...

#    PORT=${PORT:-6379}
    PORT=${PORT:-6380}

query the status of this redis in

$ sudo systemctl status redis-xxx
# server is stopped

# start service
$ sudo systemctl start redis-xxx 

make redis-xxx service auto start

$ sudo systemctl enable redis-xxx

test redis instances

redis-cli -p 6379
redis-cli -p xxx
@TigerRageMC
Copy link

Mar 25 19:30:46 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:12] Assignment outside of section. Ignoring.
Mar 25 19:30:46 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:14] Assignment outside of section. Ignoring.
Mar 25 19:30:46 localhost.localdomain systemd[1]: redis-2.service lacks both ExecStart= and ExecStop= setting. Refusing.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:1] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:5] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:6] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:9] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:12] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/redis-2.service:14] Assignment outside of section. Ignoring.
Mar 25 19:30:48 localhost.localdomain systemd[1]: redis-2.service lacks both ExecStart= and ExecStop= setting. Refusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment