8

I basically want to have 2 instances of redis on Ubuntu. I looked at /etc/init.d/redis-server script and tried to create a new one (redis-server-dev) pointing to another config file (new port etc) but it didn't seem to work.

What is the correct procedure?

Thanks

Dan
  • 371
  • 2
  • 9
  • I found this http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit that explains how those script work but I still have no clue how to create a new instance. – Dan Sep 23 '10 at 21:44

3 Answers3

19
  • Create a new config file /etc/redis/redis-new.conf (copied from redis.conf) and change these fields in the new config
    • pidfile
    • port
    • logfile
    • dir (for the default db)
  • Create a new file /etc/init.d/redis-server-new (copied from the file redis-server) and change these fields in the new file
    • name
    • pidfile (same as in the config file in step 1)
    • deamon_args (the path to the config file in step 1).
  • Create the needed directorymkdir /var/lib/redis-new (and give it the proper rights chown redis:redis /var/lib/redis-new)
  • Make the new file executable: chmod +x /etc/init.d/redis-server-new
  • Register the new deamon: update-rc.d redis-server-new defaults
Dan
  • 371
  • 2
  • 9
  • I am getting this error: # update-rc.d redis-server-dev defaults insserv: script redis-server-dev: service redis-server already provided! insserv: exiting now! – Bobby S Sep 13 '16 at 05:11
5

Adding to Dan's answer,

According to this error in the log file we have to create one extra directory

# Can't chdir to '/var/lib/redis-new': No such file or directory

so

mkdir /var/lib/redis-new

Otherwise /etc/init.d/redis-server-new won't start.

Don't forget to add proper rights by

chown redis:redis /var/lib/redis-new
Hypo
  • 51
  • 1
  • 2
0

Also there is another way, we can use the installation script which is at https://github.com/antirez/redis/blob/3.0/utils/install_server.sh (comes with the source if you have compiled redis from source), there are 2 template files:

  1. redis_init_script.tpl (is in the utils directory)
  2. redis.conf (is in the ../ directory from utils in the source

You need to tell just the port on which new instance is to be run(there are other configurable choices, but defaults can be used), rest of the placement of files will be done automatically.

sebix
  • 4,313
  • 2
  • 29
  • 47
Mohit
  • 101
  • 1