Recently I had to install memcache on a number of servers, and I would always tend to end up with errors whilst memcache tries to locate libevent. I always seem to forgett LD_DEBUG, so I figured I would write up the process for installing memcache.
One of the dependencies of memcache is libevent, so firstly download the source files for Libevent.
tar -xvf libevent-1.3b.tar.gz
Download the latest Memcached source code from danga.com
tar -xvf memcached-1.2.1.tar
Often libevent.so cannot be found when executing memcache. A useful command LD_DEBUG, is very helpful to determine where libraries are being loaded from.
LD_DEBUG=help memcached -v
LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less
18990: find library=libevent-1.3b.so.1 ; searching
18990: trying file=/usr/lib/libevent-1.3b.so.1
memcached: error while loading shared libraries: libevent-1.3b.so.1: cannot open shared object file: No such file or directory
Simply place the library where memcached will find it and execute memcached.
ln -s /usr/local/lib/libevent-1.3b.so.1 /lib/libevent-1.3b.so.1
memcached -d -u nobody -m 512 127.0.0.1 -p 11211
The options for memcached are:
Listen on <ip_addr>; default to INDRR_ANY. This is an important option to consider as there is no other way to secure the installation. Binding to an internal or firewalled network interface is suggested.
Run memcached as a daemon.
Assume the identity of <username> (only when run as root).
Use <num> MB memory max to use for object storage; the default is 64 megabytes.
Instead of throwing items from the cache when max memory is reached, throw an error
Use <num> max simultaneous connections; the default is 1024.
Lock down all paged memory. This is a somewhat dangerous option with large caches, so consult the README and memcached homepage for configuration suggestions.
Listen on port <num>, the default is port 11211.
Maximize core file limit
Disable automatic removal of items from the cache when out of memory. Additions will not be possible until adequate space is freed up.
Raise the core file size limit to the maximum allowable.
Show the version of memcached and a summary of options.
Be verbose during the event loop; print out errors and warnings.
Be even more verbose; same as -v but also print client commands and responses.
Print memcached and libevent licenses.
Print pidfile to <filename>, only used under -d option.
To install the pecl package for PHP
gzip -df memcache-2.1.2.tgz
tar -xvf memcache-2.1.2.tar
Add memcache.so to the php.ini file
php -i | grep -i 'memcache'
memcache should be listed and then restart the web server.
For further information:
Distributed Caching with Memcached