Memcached – Clustered
Posted in Technical on December 16th, 2011 by iyoung – Be the first to commentI didn’t find a great deal of information about how to run memcached across multiple servers and have them treated as one pool. Most of the examples just seem to show the installation and running of a single server instance or multiple instances on the same server running on different ports.
Far more useful in my opinion is running memcached on a number of servers in a web cluster. Now the install is as simple as “yum install memcached”. The following will start the server as a daemon on each of the machines in the cluster: -
memcached -d -p 11211 -u nobody -c 1024 -m 1024
This starts the service on port 11211 and is set to use 1gb of RAM.
Now in your code, when you instantiate your memcached object, you can pass an array of servers, this is the pool. The following is an example in Perl.
use Cache::Memcached;
$memd = new Cache::Memcached {
'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212", "/var/sock/memcached",
"10.0.0.17:11211", [ "10.0.0.17:11211", 3 ] ],
'debug' => 0,
'compress_threshold' => 10_000,
};
$memd->set_servers($array_ref);
$memd->set_compress_threshold(10_000);
$memd->enable_compress(0);