memcache on multiple servers

Yael Goldberg yael.goldberg at achieve3000.com
Wed May 7 16:00:01 UTC 2008


Thank you all for the advice.  I got it working now using the internal IPs.
I'm going to add some information to this email for other newbies like me
that are searching for information.  Please correct anything that is wrong.

-----

To implement memcache, you need to install the memcached deamon on each
server that you will use the memory for caching.  You also need to install
the memcache PHP extension on the web servers to allow PHP to access the
memcached daemon.  

Here is installation instructions:

#installing zlib
cd /usr/lib64/php4
mkdir zlib
cd zlib
wget http://www.zlib.net/zlib-1.2.3.tar.gz
tar -xzf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install
make test

#installing libevent
cd /usr/lib64/php4
mkdir libevent
cd libevent
wget http://www.monkey.org/~provos/libevent-1.4.3-stable.tar.gz
tar -xzf libevent-1.4.3-stable.tar.gz
cd libevent-1.4.3-stable
./configure
make
make install
make verify
cp /usr/local/lib/libevent* /usr/lib64

#installing memcached
cd /usr/lib64/php4
mkdir memcached
cd memcached
wget http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
tar -xzf memcached-1.2.5.tar.gz
cd memcached-1.2.5
./configure
make
make check
make install

#installing memcache PHP extension
cd /usr/lib64/php4/memcached
wget http://pecl.php.net/get/memcache-2.2.3.tgz
tar -xzf memcache-2.2.3.tgz
cd memcache-2.2.3
phpize
./configure --enable-memcache
make
make install

---

#create this file only on servers that will use memory for caching
touch  /etc/init.d/memcached
chmod 755 /etc/init.d/memcached

Put this into the file /etc/init.d/memcached:

vi /etc/init.d/memcached

#! /bin/sh
#
# chkconfig: - 55 45
# description:  The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached

# Source function library.
. /etc/rc.d/init.d/functions

IP=192.168.100.180
PORT=11211
USER=nobody
MAXCONN=1024
CACHESIZE=1024
OPTIONS=""

if [ -f /etc/sysconfig/memcached ];then
        . /etc/sysconfig/memcached
fi

# Check that networking is up.
if [ "$NETWORKING" = "no" ]
then
        exit 0
fi

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
RETVAL=0
prog="memcached"

start () {
        echo -n $"Starting $prog: "
        # insure that /var/run/memcached has proper permissions
        chown $USER /var/run/
        daemon memcached -d -l $IP -p $PORT -u $USER  -m $CACHESIZE -c
$MAXCONN -P /var/run/memcached.pid $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}
stop () {
        echo -n $"Stopping $prog: "
        killproc memcached
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
            rm -f /var/lock/subsys/memcached
            rm -f /var/run/memcached.pid
        fi
}

restart () {
        stop
        start
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status memcached
        ;;
  restart|reload)
        restart
        ;;
  condrestart)
        [ -f /var/lock/subsys/memcached ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}"
        exit 1
esac

exit $?

This is the end of the file.

Run after creating the file:

cd /etc/init.d
chkconfig memcached --add
chkconfig --list memcached
service memcached stop
service memcached start

To see that the memcached daemon is running
netstat -nptl | grep mem

Add to php.ini:

extension=memcache.so

If you are using memcache as the PHP session handler, add to php.ini: 

session.save_handler = memcache

;(For multiple servers)
session.save_path = "tcp://192.168.100.180:11211,
tcp://192.168.100.181:11211, tcp://192.168.100.182:11211,
tcp://192.168.100.183:11211, tcp://192.168.100.184:11211,
tcp://192.168.100.185:11211"

#Restart Apache
service httpd restart




-----Original Message-----
From: Dirk-Willem van Gulik [mailto:dirkx at webweaving.org] 
Sent: Wednesday, May 07, 2008 10:15 AM
To: Yael Goldberg
Cc: 'Just Marc'; 'Dustin Sallings'; memcached at lists.danga.com
Subject: Re: memcache on multiple servers


On May 7, 2008, at 3:48 PM, Yael Goldberg wrote:
> Is it OK for the daemon to listen on all IPs, instead of specifying  
> one IP
> address?  Is there any issues with that? Performance? Security?

It is generally a good habit to not expose ports or services to the  
outside world unless the outside world needs access. Memcache has  
virtually no security - so one generally binds it very specifically to  
an 'inside' interface which is not visible from the 'outside' - and it  
is common to use non-routable IP space (fc 1918) for these inside  
interfaces. See any of the diagam's about facebook, 37signals,  
twitter, flickr, et.al highscalability.com or
http://www.webweaving.org/tmp/3tier.png

Thanks,

Dw


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the memcached mailing list