A typical Developer Blog
by Gordon Franke
Icon

Wie kann ich mehrere Instanzen von memcached auf einem Server laufen lassen?

Problem

Ich brauche mehr als einen Memcached Server.

Lösung

Virtuellemaschinen

Ich kann für jeden memcached server eine Virtuellemaschine erstellen.

Probleme

  • mehr speicher (system+memcached)
  • eine ip addresse pro Instanz
  • mehr Aufwand

Multiple Instanzen mithilfe von Ports

Dafür müssen die Skripte init.d und start-memcached gepatched werden um Multiple Instanzen zum laufen zubekommen.

Nach dem patch sucht es nach Konfigurationsdateien die folgendem Muster entsprechen /etc/memcached_*.conf. Wenn es keine Dateien findet benutzt es die /etc/memcached.conf Konfigurationsdatei. Es ist also rückwärtskompatibel.

Wenn du nun 2 memached Instanzen erstellen möchtest kopiere die Konfigurationsdatei und ändere den Port, Speicher …

cp /etc/memcached.conf /etc/memcached_myserver_1.conf
cp /etc/memcached.conf /etc/memcached_myserver_2.conf

Befehle

startet alle Server

/etc/init.d/memcached start

startet nur einen bestimmten Server

/etc/init.d/memcached start myserver_1

stopt alle Server

/etc/init.d/memcached stop

stopt nur einen bestimmten Server

/etc/init.d/memcached stop myserver_1

Die Änderungen

/usr/share/memcached/scripts/start-memcached

26,30d25
> if (scalar(@ARGV) == 2) {
> 	$etcfile = shift(@ARGV);
> 	$pidfile = shift(@ARGV);
> }
>

/etc/init.d/memcached

16a17
> DAEMONNAME=memcached
18d18
< NAME=memcached
20d19
< PIDFILE=/var/run/$NAME.pid
26a26,63
> FILES=(/etc/memcached_*.conf);
> # check for alternative config schema
> if [ -r "${FILES[0]}" ]; then
>   CONFIGS=();
>   for FILE in "${FILES[@]}";
>   do
>     # remove prefix
>     NAME=${FILE#/etc/};
>     # remove suffix
>     NAME=${NAME%.conf};
>
>     # check optional second param
>     if [ $# -ne 2 ];
>     then
>       # add to config array
>       CONFIGS+=($NAME);
>     elif [ "memcached_$2" == "$NAME" ];
>     then
>       # use only one memcached
>       CONFIGS=($NAME);
>       break;
>     fi;
>   done;
>
>   if [ ${#CONFIGS[@]} == 0 ];
>   then
>     echo "Config not exist for: $2" >&2;
>     exit 1;
>   fi;
> else
>   CONFIGS=(memcached);
> fi;
>
> CONFIG_NUM=${#CONFIGS[@]};
> for ((i=0; i < $CONFIG_NUM; i++)); do
>   NAME=${CONFIGS[${i}]};
>   PIDFILE="/var/run/${NAME}.pid";
>
30c67
<       start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
---
>       start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
50c87
<       start-stop-daemon --start --quiet --exec $DAEMONBOOTSTRAP
---
>       start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
54c91
<       N=/etc/init.d/$NAME
---
>       N=/etc/init.d/$DAEMONNAME
59a97
> done;

No related posts.

Ähnliche Artikel bereitgestellt von Yet Another Related Posts Plugin.

Author:

Category: Uncategorized, unix

Tagged: , , , , , ,

23 Responses

  1. Dave sagt:

    Could you post the full files or email me the 2 files? I’m having some problems when trying to run the patch

  2. FYI

    Make sure you check line 1 on /etc/init.d/memcached

    it should be :

    #! /bin/bash

    not

    #! /bin/sh

    else the code will not work.

  3. Chris sagt:

    Welche Version von Memcached wurde hier gepatched? Ich arbeite gerade an 1.4.2. und es scheint nicht zusammen zu passen.

  4. John sagt:

    Unfortunately i can’t get that to work. How do you apply the patch files? I tried it by hand but there seems to be an error. all i get is a

    /etc/init.d/memcached: line 100: syntax error near unexpected token `;’

    that’s weird. I should have patched this automatically but this isn’t a diff-file is it?

  5. Mike sagt:

    Looks like the patch has a tiny syntax bug-

    > CONFIG_NUM=${#CONFIGS[@]};
    > for ((i=0; i NAME=${CONFIGS[${i}]};
    > PIDFILE=”/var/run/${NAME}.pid”;

    should be

    > CONFIG_NUM=${#CONFIGS[@]};
    > for ((i=0; i NAME=${CONFIGS[${i}]};
    > PIDFILE=”/var/run/${NAME}.pid”;
    > done

    Note the done

  6. have you apply this patch? i think the “done” is in line 59

  7. Andrew sagt:

    Hello,

    How is one supposed to use the code provided in the patch windows?

    Regards

    Andrew

  8. You can use the command patch or manually change the files.

  9. Andrew sagt:

    I had googled this page: http://linux.about.com/od/commands/l/blcmdl1_patch.htm

    I am new to using the patch command so bear with me! I created a file on my server called diff1 containing the code for /usr/share/memcached/scripts/start-memcached. I then created a backup of my start-memcached. When I run patch start-memcached.bak < diff1, I receive this error message:

    patching file start-memcached.bak
    patch: **** `<' expected at line 2 of patch

    Am I doing something stupid?

    Regards

    Andrew

  10. I am currently using memcached 1.4.2-1ubuntu3 and these patches will not work for me at all. on the first patch I keep getting this error: patch: **** ` was expected, this was caused by there not being a space after those such as ‘> ‘. I fixed that and got the above errors.

    Any assistance?
    Joseph Crawford´s last [type] ..Repairing the Oil Pan on my 2006 Katana 600

  11. UndiFineD sagt:

    #full /etc/init.d/memcached for my ubuntu 10.04+

    #! /bin/bash
    ### BEGIN INIT INFO
    # Provides: memcached
    # Required-Start: $syslog
    # Required-Stop: $syslog
    # Should-Start: $local_fs
    # Should-Stop: $local_fs
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: memcached – Memory caching daemon
    # Description: memcached – Memory caching daemon
    ### END INIT INFO

    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/bin/memcached
    DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached
    DAEMONNAME=memcached
    DESC=memcached
    PIDFILE=/var/run/$NAME.pid
    FILES=(/etc/memcached_*.conf);
    if [ -r "${FILES[0]}” ]; then
    CONFIGS=();
    for FILE in “${FILES[@]}”;
    do
    # remove prefix
    NAME=${FILE#/etc/};
    # remove suffix
    NAME=${NAME%.conf};

    # check optional second param
    if [ $# -ne 2 ];
    then
    # add to config array
    CONFIGS+=($NAME);
    elif [ "memcached_$2" == "$NAME" ];
    then
    # use only one memcached
    CONFIGS=($NAME);
    break;
    fi;
    done;

    if [ ${#CONFIGS[@]} == 0 ];
    then
    echo “Config not exist for: $2″ >&2;
    exit 1;
    fi;
    else
    CONFIGS=(memcached);
    fi;

    CONFIG_NUM=${#CONFIGS[@]};
    for ((i=0; i &2
    exit 1
    ;;
    esac

    exit 0

  12. Jon sagt:

    Here are the complete patched files for Ubuntu 8.04.
    http://gist.github.com/516746

  13. xSmurf sagt:

    Awesome tip, thank very much for the info!

  14. flo sagt:

    small Fix:
    use:
    FILES=(/etc/memcached*.conf);
    instead of:
    FILES=(/etc/memcached_*.conf);
    to also hit the standard-configfile

    and simply add the line:
    start-stop-daemon –stop –quiet –oknodo –pidfile $PIDFILE
    whenever a serverstop is invoked.

  15. flo sagt:

    forget the “start-stop-daemon –stop –quiet –oknodo –pidfile $PIDFILE” Line cause its already there ;)

  16. i have forked the gist and make some small improvements http://gist.github.com/612961.

    tested under:
    ubuntu and memcache 1.4.5
    debian lenny memcache 1.4.5

  17. Kaanon sagt:

    You guys are lifesavers, I didn’t want to have to write this myself!

    Works perfectly!!!!!!

  18. Aleka sagt:

    Thanks for your scripts, I have tested it in Debian lenny – memcached 1.4.5-1 and Works perfectly.

    But, It would be possible to run more than 2 instances of memcache?.
    If so, what should I change in the scripts?

  19. simple add another memcache config file. you are only limited on ram and ports ;) so i run 22 memcache instances on one server

  20. Aleka sagt:

    Thanks for your answer!

    In this regard. Can I do some questions?

    1. Do you know any tool that allows me to make monitoring multiple instances at once?

    2. Do you know any tool that allows me to make “Stress Testing” on a site configured with memcache, which only has access through a “logon”?

    Thanks in advance!!

  21. april14344 sagt:

    oh cool, this is great! just like what i needed! thanks so much!
    april14344´s last [type] ..Young Driver Insurance – The Best Strategy to Save You Money!

Leave a Reply

CommentLuv badge