Sep 27, 2010

Running multiple instances of Memcached on CentOS

If you install Memcached via Yum or RPM, you will get the following main scripts

  1. memcached binary (may be at /usr/bin/memcached)
  2. /etc/sysconfig/memcached which is the main configuration of memcached
  3. /etc/init.d/memcached which is the startup script of memcached
The above files could run only one instance of memcached, i usually ignore those scripts (no: 2,3) and use direct command line to run multiple instancs of memcached. However this method lacks system administration and is too difficult to maintain. You have to put your multiple command lines into /etc/rc.local. 

Another solution to support this idea is, modify /etc/init.d/memcached to read all configuration of /etc/sysconfig/memcached_* and use those information to start the daemon.

Here is the link to /etc/init.d/memcached

Here is the link to /etc/sysconfig/memcached_11211

After upload the scripts to the server, please
  • Create a folder at /var/run/memcached
  • Change owner of /var/run/memcached to "nobody" and change mode to 755
Usage:
  • Startup command
    # /etc/init.d/memcached start
    # /etc/init.d/memcached start memcached_11211
  • Status command
    # /etc/init.d/memcached status
    # /etc/init.d/memcached status memcached_11211
  • Stop command
    # /etc/init.d/memcached stop
    # /etc/init.d/memcached stop memcached_11211
Note
  • You could create more than one instances of memcached by using 1 startup script by copy & modify /etc/sysconfig/memcached_11211 to memcached_PORT 
  • Don't forget to change the startup parameters inside that file especially the port number
  • Original version of /etc/init.d/memcached is modified from here
  • The block layout of /etc/init.d/memcached is not so good, but it works for me.


5 comments:

Unknown said...

The modified /etc/init.d/memcached link is dead. Can you please check it?

AuntiSpam said...

It's about the sharing setting on google. Both files have the same setting but i don't know why one can not be accessed.

I will update the new link tomorrow. Not enough time for now.

Sorry and thank you for your feedback.

AuntiSpam said...

I modified the link to /etc/init.d/memcached in the document.

ben said...

Thanks for this script.

I don't know if it was intentional, but the 'stop' command doesn't delete the pid file. Also, the reload & status commands don't work. I added the following lines respectively.

rm -f $PIDFILE
...
killproc -p $PIDFILE memcached -HUP
...
status -p $PIDFILE memcached

Anonymous said...

tried your script, but start only 11211
shows ok for others but i dont see them in top.


cheers