There are plenty of reasons to want to run multiple instances of memcache on the same box. We use it to have multiple testing enviroments on the same cluster. By running different instances on different ports we can safely test without collisions. These directions are written for centOS, but could be easily applied to other distributions.
The Setup
For my purpose of example, we are calling the second instance, "memcached_second" though I would recommend naming it something more applicable depending on your circumstance, like "memcache_staging" for example.
If you don't have a configuration, I'll include the one I use at the bottom of this page.
1. Copy the init.d script & config, symlink the binary.
cp /etc/init.d/memcached /etc/init.d/memcached_second cp /etc/sysconfig/memcached /etc/sysconfig/memcached_second
ln -s /usr/bin/memcached /usr/bin/memcached_second
2. Modify the files
Change the init.d script to point to the new config and program name
### Default variables PORT="11212" USER="nobody" MAXCONN="1024" CACHESIZE="64" OPTIONS="" SYSCONFIG="/etc/sysconfig/memcached_second"
...
RETVAL=0 prog="memcached_second" desc="Distributed memory caching"
Change the default port in the config file (located in /etc/sysconfig)
PORT="11212" USER="nobody" MAXCONN="1024" CACHESIZE="64" OPTIONS=""
3. Tell it to start when the server boots
chkconfig memcached_second on
4. Start the instance
/etc/init.d/memcached_second start
My Memcache Config
/etc/init.d/memcache
#!/bin/bash<br> #<br> # Init file for memcached<br> #<br> # Written by Dag Wieƫrs <dag@wieers.com><br> # Modifications by Steve Francia <spf13.com><br> #<br> # chkconfig: - 80 12<br> # description: Distributed memory caching daemon<br> #<br> # processname: memcached<br> # config: /etc/sysconfig/memcached<br> # config: /etc/memcached.conf<br> <br> source /etc/rc.d/init.d/functions<br> <br> ### Default variables<br> <strong> PORT="11211"</strong><br> USER="nobody"<br> MAXCONN="1024"<br> CACHESIZE="64"<br> OPTIONS=""<strong><br> SYSCONFIG="/etc/sysconfig/memcached" </strong><br> <br> ### Read configuration<br> [ -r "$SYSCONFIG" ] && source "$SYSCONFIG"<br> <br> RETVAL=0<br> <strong> prog="memcached"</strong><br> desc="Distributed memory caching"<br> <br> start() {<br> echo -n $"Starting $desc ($prog): "<br> daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS<br> RETVAL=$?<br> echo<br> [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog<br> return $RETVAL<br> }<br> <br> <br> stop() {<br> echo -n $"Shutting down $desc ($prog): "<br> killproc $prog<br> RETVAL=$?<br> echo<br> [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog<br> return $RETVAL<br> }<br> <br> restart() {<br> stop<br> start<br> }<br> <br> reload() {<br> echo -n $"Reloading $desc ($prog): "<br> killproc $prog -HUP<br> RETVAL=$?<br> echo<br> return $RETVAL<br> }<br> <br> <br> case "$1" in<br> start)<br> start<br> ;;<br> stop)<br> stop<br> ;;<br> restart)<br> restart<br> ;;<br> condrestart)<br> [ -e /var/lock/subsys/$prog ] && restart<br> RETVAL=$?<br> ;;<br> reload)<br> reload<br> ;;<br> status)<br> status $prog<br> RETVAL=$?<br> ;;<br> *)<br> echo $"Usage: $0 {start|stop|restart|condrestart|status}"<br> RETVAL=1<br> esac<br> <br> exit $RETVAL<br>
/etc/sysconfig/memcached
PORT="11211" USER="nobody" MAXCONN="1024" CACHESIZE="1536" OPTIONS=""














What is the purpose of symlinking the binary?
What is the purpose of symlinking the binary?
Post new comment