How To Install And Monitor Memcache On Centos?Last Updated on
WHAT IS MEMCACHE?
Memcache is free, open source, high performance, distributed memory object caching system. It is intended for speeding up dynamic web-applications by reducing database load. It is in-memory data store that keeps data in the format of key-value pair. Data is strings/objects and are usually the results of database calls, API calls or page rendering.
Its APIs are available in popular languages. So, we find python memcache API integration, php memcache API orJava client for memcache.
HOW TO INSTALL MEMCACHE?
Memcache has a dependency on libevent. So we need to install that first.
First, install the dependency libevent:
cd /usr/local/src curl -O http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz tar xzvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable ./configure –prefix=/usr/local make make install
Now, install memcached. Best is to use famous YUM. But, before you go there, you would need to activate the RPMForge custom repository (formely known as Dag Wieers): http://dag.wieers.com/rpm/packages/rpmforge-release/
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3… rpm -i rpmforge-release-0.3.4-1.el4.rf.i386.rpm
yum install –enablerepo=rpmforge memcached
Now memcached is installed.
You can test it:
service memcached restart chkconfig memcached on // start memcache on boot
If you want to configure the memory or create multiple instances make change to: /etc/init.d/memcached start daemon.
Remember, we have just installed Memcache on the server. If you are using PHP, Python, Java or a CMS like Drupal, you would need to install the language based client API for memcache. For example for PHP, we would use PECL memcache.
INSTALL PECL EXTENSION FOR PHP
Assuming you have pecl installed on your CentOS, use the following command:
cd /usr/local/src/ wget http://pecl.php.net/get/memcache-2.1.2.tgz tar zxvf memcache-2.1.2.tgz phpize ./configure make & make install echo “extension=memcache.so” >> /usr/local/lib/php.ini service httpd restart
Alternatively, you could try, if pecl is installed on centos.
pecl install memcached
DRUPAL INTEGRATION WITH MEMCACHE
Install Drupal memcache module and configure your settings.php as follows:
$conf = array(
‘cache_inc’ => ‘./sites/all/modules/memcache/memcache.db.inc’,
And you are ready to go. Complex configurations with memcache can be set.
HOW TO MONITOR MEMCACHE HITS AND MISSES?
How lovely? My Drupal/PHP application is up and running. Don’t forget the steps after installing memcahe would be different for a different language client or API integration of the application.
As of now, I want to monitor my hits and misses. How do I do that? I use Brutis.
./brutis -x 127.0.0.1:11211 -v
It tells me my hits and misses. Check out 100% Hits.
And there you are with fast web application.
Tags: centos | Drupal | install memcache | linux | memcache