Install Memcache and Memcached

Install memcached

See How to install Memcache on Debian Etch or How to install Memcache on OSX.

To install memcached on Gentoo:

root# emerge -pv net-misc/memcached
[ebuild  N    ] dev-libs/libevent-1.4.4  ...
[ebuild  N    ] net-misc/memcached-1.2.5  ...

root# emerge -v net-misc/memcached

This will install libevent.

To install memcached on Redhat:

Install prerequisite - libevent

  1. Download libevent from http://www.monkey.org/~provos/libevent/.
  2. Unpack the downloaded package.
  3. cd into the package directory, and follow README:

    ./configure && make
    make install

Install memcached

  1. Download memcached from http://www.danga.com/memcached/download.bml
  2. Unpack the downloaded package.
  3. cd into the package directory, and do:

    ./configure && make
    make install

  4. Follow this post http://www.ajohnstone.com/archives/installing-memcached/ to help memcached find the libevent.

Start memcached

Run "memcached -h" to see a list a options avaible to the memcached. Most likely when you are just starting to test out the deamon, you will do this:

root#  memcached -d -u nobody -m 512 127.0.0.1 -p 11211

This will start memcached, using 512MB on the localhost, and listening on the default port 11211.

Autostart memcached on Gentoo

First, configure the memcached by editing the file /etc/conf.d/memcached. Then do the following:

root# rc-update add memcached default

Autostart memcached on Redhat/Centos

There isn't memcached in /etc/init.d/ after you installed it. So you have to do it yourself.

  1. Referece http://www.dev411.com/wiki/Memcached_startup_files_for_Red_Hat_(RHEL) to get your own version of /etc/init.d/memcached. This document doesn't give clear instruction on how to construct the configuration file /etc/memcache. So, to be lazy, you might as well just skip the start-memcached bootstrap. Here is what you can do:
    1. Change the definition of $DAEMONBOOTSTRAP to

      DAEMONBOOTSTRAP="$DAEMON -d -u nobody -m 512 127.0.0.1 -p 11211"

    2. Then, comment out the line

      # [ -x $DAEMONBOOTSTRAP ] || exit 0

    3. Then, under "start()", change the line "daemon $DAEMONBOOTSTRAP $DAEMONCONF" to just a line that says

      $DAEMONBOOTSTRAP

  2. Run the following:

    root# chkconfig --level 35 memcached on

Install memcache clients

http://www.danga.com/memcached/apis.bml where you can find the client APIs for the clients.

Install Pecl-memcache

Please reference these docs:

Install pecl-memcache on Gentoo

On Gentoo, the package "dev-php5/pecl-memcache" is currently masked off. To get around this, check the post TIP Dealing with masked packages, and then do this:

root# echo "=dev-php5/pecl-memcache-3.0.1" >> /etc/portage/package.keywords
root# emerge -pv dev-php5/pecl-memcache

Install pecl-memcache on Redhat

On Redhat/Cento, first check and make sure pecl is available. Then just run

root# pecl install memcache

Configure the webserver for memcache

In php.ini, add the following line

memcache.hash_strategy="consistent"

Then restart your webserver.

 

Comments

Thank you for info. Anton,

Thank you for info.

Anton, my blog.

thx

nice tutorial
I install this on my dedicated serwer
and now my forum counter strike works much better :) thx for it!

greeting, mosh

gentoo linux

I tried do do it on my dedicated gentoo linux server, but it doesn't work..

i can't find a "memcache.ini" on my server, where is it?

It depends on what app you try to use memcache for

If you are going to use apache and php, then check /etc/php/apache2-php5/ext/, there should be a memcache.ini there.