Skip to content

Instantly share code, notes, and snippets.

@EddyF
Last active June 17, 2018 00:40
Show Gist options
  • Save EddyF/aba031f91c8238eccc3b to your computer and use it in GitHub Desktop.
Save EddyF/aba031f91c8238eccc3b to your computer and use it in GitHub Desktop.

#FOR MULTIPLE REDIS INSTANCE INSTALLATION ON RHEL7+ USE THE FOLLOWING PATHS AND SETUP PROCESS:

  • create a new redis .conf file
$ cp /etc/redis.conf /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
#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
  • THERE IS NO init.d files RHEL uses systemctl instead so:
  • copy existing service over to your new service
$ cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis-xxx.service
  • modify your new service script to the following: (just change the redis-xxx path)
...

#[Unit]
Description=Redis persistent key-value database
After=network.target

#[Service]
ExecStart=/usr/bin/redis-server /etc/redis-xxx.conf --daemonize no
ExecStop=/usr/bin/redis-shutdown
User=redis
Group=redis

#[Install]
WantedBy=multi-user.target
...
  • if you have sentinel enabled on your system you will need to: (otherwise skip this step)
# Copy values from cat /usr/lib/systemd/system/redis.service to /usr/lib/systemd/system/redis-xxx.service
$ cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis-xxx.service
  • then edit the contents of /usr/lib/systemd/system/redis-xxx.service (just change the /etc/redis-xxx path again)

  • start the new services:

$ service redis-xxx start
  • check the new services status:
$ service redis-xxx status
  • stop the new services status:
$ service redis-xxx stop
  • restart the new services status:
$ service redis-xxx restart
  • if you get some problems with service not found:
  • you can do the following:
$ systemctl unmask packagekit.service
$ systemctl mask packagekit.service
  • then try to start the service again
@desaiamogh
Copy link

I am trying this on an ec2 amazon ami with no systemctl also redis-shutdown is at /usr/libexec/ and this doesnt work: ExecStop=/usr/libexec/redis-shutdown redis_6379

Instead I have created multiple copies of redis-shutdown, redis-server and init files for each instance.
so I have

/etc/init.d/redis_6379 /etc/init.d/redis_6380 and /etc/init.d/redis_6381
/usr/bin/redis_6379 /usr/bin/redis_6380 and /usr/bin/redis_6381  (instead of /usr/bin/redis-server)
/usr/libexec/redis_6379-shutdown /usr/libexec/redis_6380-shutdown and /usr/libexec/redis_6381-shutdown (instead of /usr/libexec/redis-shutdown

This line in each shutdown file points to each init file. SERVICE_NAME=redis_6379 Its working fine with 3 instances right now with ports 6379, 80. 81. no errors on start and stop. Only thing i need some explanation is these lines in the default shutdown file:

if [ "$SERVICE_NAME" = **redis** ]; then
    PORT=${PORT:-**6379**}
else
    PORT=${PORT:-**26739**}

whats the 26739 port for ?
I have currently used following config for each of the shut down file
example: /usr/libexec/redis_6380-shutdown

if [ "$SERVICE_NAME" = **redis_6380** ]; then
    PORT=${PORT:-**6380**}
else
    PORT=${PORT:-**26740**}

Is there an easier alternative to this??

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